--- ms-ole.c	Sat Jan 13 17:42:55 2001
+++ /home/dom/libole2/libole2/ms-ole.c	Sat Jan 13 17:24:36 2001
@@ -15,7 +15,7 @@
 #include <unistd.h>
 #endif
 
-/* #include <sys/types.h> */
+#include <sys/types.h>
 #include <sys/stat.h>	/* for struct stat */
 #include <fcntl.h>
 
@@ -24,31 +24,28 @@
 #include <glib.h>
 #include <string.h>
 
-#ifdef HAVE_CONFIG_H
+#include <libole2/ms-ole.h>
 #include "config.h"
-#endif
-
-#include "ms-ole.h"
 
 #ifdef HAVE_MMAP
 #include <sys/mman.h>
 #endif
 
-#ifdef HAVE_UNISTD_H 
+#ifdef HAVE_UNISTD_H
 #	include <unistd.h>
 #else
-
-#if 0
-#include <io.h> 
-#endif
-
-#define S_IRUSR 0000400 
-#define S_IWUSR 0000200 
-#define S_IRGRP 0000040 
-#define S_IWGRP 0000020 
-#define _S_ISREG(m) (((m)&0170000) == 0100000) 
-#define S_ISREG(m) _S_ISREG(m) 
-#define O_NONBLOCK 0x4000 
+#	include <io.h>
+#	include <sys/stat.h>
+#	include <sys/types.h>
+/*
+#	define S_IRUSR 0000400
+#	define S_IWUSR 0000200
+#	define S_IRGRP 0000040
+#	define S_IWGRP 0000020
+#	define _S_ISREG(m) (((m)&0170000) == 0100000)
+#	define S_ISREG(m) _S_ISREG(m)
+#	define O_NONBLOCK 0x4000
+*/
 #endif
 
 #ifndef PROT_READ
@@ -129,23 +126,13 @@
 static int
 open2_wrap (const char *pathname, int flags)
 {
-  /* small fix for OS/2 and Win32 not applicable for Unix */
-#ifdef O_BINARY
-	return open (pathname, flags | O_BINARY);
-#else
 	return open (pathname, flags);
-#endif
 }
 
 static int
 open3_wrap (const char *pathname, int flags, mode_t mode)
 {
-  /* small fix for OS/2 and Win32 not applicable for Unix */
-#ifdef O_BINARY
-	return open (pathname, flags | O_BINARY, mode);
-#else
 	return open (pathname, flags, mode);
-#endif
 }
 
 static ssize_t
@@ -163,7 +150,7 @@
 static ssize_t
 write_wrap (int fd, const void *buf, size_t count)
 {
-	return write (fd, (void*)buf, count);
+	return write (fd, buf, count);
 }
 
 static off_t
@@ -238,8 +225,7 @@
 		f->syswrap = wrappers;
 }
 
-
-/* 
+/*
  * A global variable to enable calles to check_stream,
  * applications should optionally enable due to the performance penalty.
  * of 30-50 % of load time.
@@ -334,10 +320,10 @@
 	offset = (attr->blk+1)*BB_BLOCK_SIZE;
 	if (f->syswrap->lseek (f->file_des, offset, SEEK_SET)==(off_t)-1 ||
 	    f->syswrap->write (f->file_des, attr->data, BB_BLOCK_SIZE) == -1)
-		g_error ("Fatal error writing block %d at %d\n", attr->blk, offset);
+		printf ("Fatal error writing block %d at %d\n", attr->blk, offset);
 #if OLE_DEBUG > 0
-	g_print ("Writing cache block %d to offset %d\n",
-		 attr->blk, offset);
+	printf ("Writing cache block %d to offset %d\n",
+		attr->blk, offset);
 #endif	
 	attr->dirty = FALSE;
 }
@@ -385,7 +371,7 @@
 	if (min) {
 		g_assert (min->data);
 #if OLE_DEBUG > 0
-		g_print ("Replacing cache block %d with %d\n", min->blk, b);
+		printf ("Replacing cache block %d with %d\n", min->blk, b);
 #endif
 		if (min->dirty)
 			write_cache_block (f, min);
@@ -443,7 +429,7 @@
 /* NB it is misleading to assume that Microsofts linked lists link correctly.
    It is not the case that pps_next(f, pps_prev(f, n)) = n ! For the final list
    item there are no valid links. Cretins. */
-#define PPS_GET_NAME_LEN(p)   (MS_OLE_GET_GUINT16 (p + 0x40))
+#define PPS_GET_NAME_LEN(p)   (MS_OLE_GET_GUINT16(p + 0x40))
 #define PPS_SET_NAME_LEN(p,i) (MS_OLE_SET_GUINT16 (p + 0x40, (i)))
 #define PPS_GET_PREV(p)   ((PPS_IDX) MS_OLE_GET_GUINT32 (p + 0x44))
 #define PPS_GET_NEXT(p)   ((PPS_IDX) MS_OLE_GET_GUINT32 (p + 0x48))
@@ -454,7 +440,7 @@
 /* These get other interesting stuff from the PPS record */
 #define PPS_GET_STARTBLOCK(p)      ( MS_OLE_GET_GUINT32 (p + 0x74))
 #define PPS_GET_SIZE(p)            ( MS_OLE_GET_GUINT32 (p + 0x78))
-#define PPS_GET_TYPE(p) ((MsOleType)( MS_OLE_GET_GUINT8 (p + 0x42)))
+#define PPS_GET_TYPE(p) ((MsOleType)( MS_OLE_GET_GUINT8(p + 0x42)))
 #define PPS_SET_STARTBLOCK(p,i)    ( MS_OLE_SET_GUINT32 (p + 0x74, i))
 #define PPS_SET_SIZE(p,i)          ( MS_OLE_SET_GUINT32 (p + 0x78, i))
 #define PPS_SET_TYPE(p,i)          ( MS_OLE_SET_GUINT8 (p + 0x42, i))
@@ -483,7 +469,7 @@
 	if (length <= 0 ||
 	    length > (PPS_BLOCK_SIZE/4)) {
 #if OLE_DEBUG > 0
-		g_print ("Nulled name of length %d\n", length);
+		printf ("Nulled name of length %d\n", length);
 #endif
 		return 0;
 	}
@@ -504,13 +490,13 @@
 static void
 dump_header (MsOle *f)
 {
-	g_print ("--------------------------MsOle HEADER-------------------------\n");
-	g_print ("Num BBD Blocks : %d Root %%d, SB blocks %d\n",
+	printf ("--------------------------MsOle HEADER-------------------------\n");
+	printf ("Num BBD Blocks : %d Root %%d, SB blocks %d\n",
 		f->bb?f->bb->len:-1,
 /*		f->pps?f->pps->len:-1, */
 /* FIXME tenix, here is not f->num_pps? */
 		f->sb?f->sb->len:-1);
-	g_print ("-------------------------------------------------------------\n");
+	printf ("-------------------------------------------------------------\n");
 }
 
 static void
@@ -571,12 +557,12 @@
 	while (list) {
 		p = list->data;
 		if (p) {
-			g_print ("%s '%s' - %d\n",
-				 indentstr, p->name, p->size);
+		       printf ("%s '%s' (size: %d)\n",
+				indentstr, p->name, p->size);
 			if (p->children)
 				dump_tree (p->children, indent+1);
 		} else
-			g_print ("%s NULL!\n", indentstr);
+			printf ("%s NULL!\n", indentstr);
 		list = g_list_next (list);
 	}
 }
@@ -589,21 +575,21 @@
 
 	for (lp=0;lp<f->bb->len;lp++) {
 		characterise_block (f, lp, &blktype);
-		g_print ("Block %d -> block %d ( '%s' )\n", lp,
-			 g_array_index (f->bb, BLP, lp),
-			 blktype);
+		printf ("Block %d -> block %d ( '%s' )\n", lp,
+			g_array_index (f->bb, BLP, lp),
+			blktype);
 	}
 	
 	if (f->pps) {
-		g_print ("Root blocks : %d\n", f->num_pps); 
+		printf ("Root blocks : %d\n", f->num_pps); 
 		dump_tree (f->pps, 0);
 	} else
-		g_print ("No root yet\n");
+		printf ("No root yet\n");
 /*	
 	printf ("sbd blocks : %d\n", h->sbd_list->len);
 	for (lp=0;lp<h->sbd_list->len;lp++)
 	printf ("sbd_list[%d] = %d\n", lp, (int)ms_array_index (h->sbd_list, SBPtr, lp));*/
-	g_print ("-------------------------------------------------------------\n");
+	printf ("-------------------------------------------------------------\n");
 }
 
 /*
@@ -619,7 +605,7 @@
 		if (fs->pps)
 			dump_tree (fs->pps, 0);
 		else
-			g_print ("There are no tree (no pps)\n");
+			printf ("There are no tree (no pps)\n");
 		break;
 	default:
 		dump_header (fs);
@@ -685,7 +671,7 @@
 	for (lp = 0; (lp < (f->length / BB_BLOCK_SIZE) - 1) &&
 		     (lp < MAX_SIZE_BBD_LIST * BB_BLOCK_SIZE / 4); lp++) {
 		gboolean err;
- 
+
 		tmp = get_next_block (f, lp, &err);
 		if (err)
 			return 0;
@@ -780,7 +766,6 @@
 	return 1;
 }
 
-
 static void
 remap_file (MsOle *f, guint blocks)
 {
@@ -799,13 +784,13 @@
 
 	/* Extend that file by blocks */
 	if (f->syswrap->getfilesize (file, &filesize)) {
-		g_error ("Serious error extending file\n");
+		printf ("Serious error extending file\n");
 		f->mem = 0;
 		return;
 	}
 
 	if (f->syswrap->lseek (file, 0, SEEK_END) == (off_t)-1) {
-		g_error ("Serious error extending file\n");
+		printf ("Serious error extending file\n");
 		f->mem = 0;
 		return;
 	}
@@ -814,13 +799,13 @@
 		if (f->syswrap->write (file, zeroblock, BB_BLOCK_SIZE -
 				       ((icount == blocks - 1) ? 1 : 0))
 		    == -1) {
-			g_error ("Serious error extending file\n");
+			printf ("Serious error extending file\n");
 			f->mem = 0;
 			return;
 		}
 	}
 	if (f->syswrap->write (file, &zero, 1) == -1) {
-		g_error ("Serious error extending file\n");
+		printf ("Serious error extending file\n");
 		f->mem = 0;
 		return;
 	}
@@ -895,6 +880,7 @@
 	g_array_append_val (f->bb, tblk);
 	g_assert ((g_array_index (f->bb, BLP, blk) == UNUSED_BLOCK));
 	g_assert (f->bb->len < f->length/BB_BLOCK_SIZE);
+
 	return blk;
 }
 
@@ -957,7 +943,7 @@
 	g_assert ((g_array_index (f->sb, BLP, blk) == UNUSED_BLOCK));
 	g_assert (blk < f->sb->len);
 
-	if ((f->sb->len + (BB_BLOCK_SIZE/SB_BLOCK_SIZE) - 1) / 
+	if ((f->sb->len + (BB_BLOCK_SIZE/SB_BLOCK_SIZE) - 1) /
 	    (BB_BLOCK_SIZE/SB_BLOCK_SIZE) >= f->sbf->len) {
 	/* Create an extra big block on the small block stream */
 		BLP new_sbf = next_free_bb(f);
@@ -968,7 +954,7 @@
 		g_array_index (f->bb, BLP, new_sbf) = END_OF_CHAIN;
 	}
 
-	g_assert ((f->sb->len + (BB_BLOCK_SIZE/SB_BLOCK_SIZE) - 1) / 
+	g_assert ((f->sb->len + (BB_BLOCK_SIZE/SB_BLOCK_SIZE) - 1) /
 		  (BB_BLOCK_SIZE/SB_BLOCK_SIZE) <= f->sbf->len);
 
 	return blk;
@@ -996,9 +982,8 @@
 	}
 
 #if OLE_DEBUG > 0
-	g_print ("get_pps_ptr: blk = %d\n", blk);
+	printf ("get_pps_ptr: blk = %d\n", blk);
 #endif
-
 	if (forwrite)
 		return BB_W_PTR(f, blk) + (i%(BB_BLOCK_SIZE/PPS_BLOCK_SIZE))*PPS_BLOCK_SIZE;
 	else
@@ -1029,12 +1014,12 @@
 	pps->sig      = PPS_SIG;
 	mem           = get_pps_ptr (f, p, FALSE);
 	if (!mem) {
-		g_error ("Serious directory error %d\n", p);
+		printf ("Serious directory error %d\n", p);
 		f->pps = NULL;
 		return;
 	}
 #if OLE_DEBUG > 0
-	g_print ("pps_decode_tree: mem (offset)= %#8.8x\n", mem - f->mem);
+	printf ("pps_decode_tree: mem (offset)= %#8.8x\n", mem - f->mem);
 #endif
 	pps->name     = pps_get_text  (mem, PPS_GET_NAME_LEN(mem));
 	pps->type     = PPS_GET_TYPE  (mem);
@@ -1043,7 +1028,7 @@
 	pps->parent   = parent;
 	pps->idx      = 0;
 	if (!pps->name) { /* Make safe */
-		g_print ("how odd: blank named file in directory\n");
+		printf ("how odd: blank named file in directory\n");
 		g_free (pps);
 		return;
 	}
@@ -1052,14 +1037,14 @@
 	
 	if (parent) {
 #if OLE_DEBUG > 0
-		g_print ("Inserting '%s' into '%s'\n", pps->name, parent->name);
+		printf ("Inserting '%s' into '%s'\n", pps->name, parent->name);
 #endif
 		parent->children = g_list_insert_sorted (parent->children, pps,
 							 (GCompareFunc)pps_compare_func);
 	}
 	else {
 #if OLE_DEBUG > 0
-		g_print ("Setting root to '%s'\n", pps->name);
+		printf ("Setting root to '%s'\n", pps->name);
 #endif
 		f->pps = g_list_append (0, pps);
 	}
@@ -1142,7 +1127,7 @@
 	(*p)++;
 
 #if OLE_DEBUG > 0
-	g_print ("encoding '%s' as %d\n", pps->name, pps->idx);
+	printf ("encoding '%s' as %d\n", pps->name, pps->idx);
 #endif
 
 	mem = get_pps_ptr (f, pps->idx, TRUE);
@@ -1159,10 +1144,10 @@
 		for (lp = 0; lp < max; lp++)
 			MS_OLE_SET_GUINT16 (mem + lp * 2, pps->name [lp]);
 	} else {
-	        g_print ("No name %d\n", *p);
+		printf ("No name %d\n", *p);
 		max = -1;
 	}
-	PPS_SET_NAME_LEN (mem, (max + 1)*2);
+	PPS_SET_NAME_LEN(mem, (max + 1) * 2);
 	
 	/* Magic numbers */
 	if (pps->idx == PPS_ROOT_INDEX) { /* Only Root */
@@ -1232,10 +1217,10 @@
 		PPS_SET_DIR (mem_parent, ((PPS *)(lchildren->data))->idx);
 
 #if OLE_DEBUG > 1
-		g_print ("Final encode '%s' as \n",
+		printf ("Final encode '%s' as \n",
 			((PPS *)(parent))->name);
 		ms_ole_dump (mem_parent, PPS_BLOCK_SIZE);
-		g_print ("Final encode '%s' as \n",
+		printf ("Final encode '%s' as \n",
 			((PPS *)(lchildren->data))->name);
 		ms_ole_dump (get_pps_ptr (f, ((PPS *)(lchildren->data))->idx, FALSE),
 		      PPS_BLOCK_SIZE);
@@ -1283,7 +1268,7 @@
 		}
 
 #if OLE_DEBUG > 1
-			g_print ("Final encode '%s' as \n",
+			printf ("Final encode '%s' as \n",
 				((PPS *)(children))->name);
 			ms_ole_dump (mem, PPS_BLOCK_SIZE);
 #endif
@@ -1292,7 +1277,7 @@
 	}
 
 #if OLE_DEBUG > 1
-	g_print ("Final encode '%s' as \n", ((PPS *)(parent))->name);
+	printf ("Final encode '%s' as \n", ((PPS *)(parent))->name);
 	ms_ole_dump (mem_parent, PPS_BLOCK_SIZE);
 #endif
 }
@@ -1520,7 +1505,7 @@
 }
 
 static MsOle *
-msole_ole_new ()
+ms_ole_new ()
 {
 	MsOle *f = g_new0 (MsOle, 1);
 
@@ -1579,21 +1564,19 @@
  * Return value: a #MsOleErr code.
  **/
 MsOleErr
-ms_ole_open_vfs (MsOle **fs, const char *name, 
+ms_ole_open_vfs (MsOle **fs, const char *name,
 		 gboolean try_mmap,
 		 MsOleSysWrappers *wrappers)
 {
-#ifdef HAVE_MMAP   
-	int prot = PROT_READ | PROT_WRITE;
-#endif /* HAVE_MMAP */
 	MsOle *f;
+	int prot = PROT_READ | PROT_WRITE;
 	int file;
 
 	if (!fs)
 		return MS_OLE_ERR_BADARG;
 
 #if OLE_DEBUG > 0
-	g_print ("New OLE file '%s'\n", name);
+	printf ("New OLE file '%s'\n", name);
 #endif
 
 	f = *fs = ms_ole_new ();
@@ -1606,25 +1589,24 @@
 	if (file == -1) {
 		f->file_des = file = f->syswrap->open2 (name, O_RDONLY);
 		f->mode = 'r';
-#ifdef HAVE_MMAP
 		prot &= ~PROT_WRITE;
-#endif /* HAVE_MMAP */
 	}
 
 	if ((file == -1) || !(f->syswrap->isregfile (file))) {
-		/* FIXME tenix is not a memory leak not to close file? */
-		g_warning ("No such file '%s'\n", name);
-		g_free (f) ;
+		printf ("No such file '%s'\n", name);
+		g_free (f);
 		*fs = NULL;
 		return MS_OLE_ERR_EXIST;
 	}
-	if (f->syswrap->getfilesize( file, &(f->length) )) {
-		g_warning ("Couldn't get the size of file '%s'\n", name);
+
+	if (f->syswrap->getfilesize (file, &(f->length) )) {
+		printf ("Couldn't get the size of file '%s'\n", name);
 		f->syswrap->close (file) ;
-		g_free (f) ;
+		g_free (f);
 		*fs = NULL;
 		return MS_OLE_ERR_EXIST;
 	}
+
 	if (f->length <= 0x4c) { /* Bad show */
 #if OLE_DEBUG > 0
 		g_warning ("File '%s' too short\n", name);
@@ -1660,14 +1642,14 @@
 			f->ole_mmap = TRUE;
 		
 	} else /* !try_mmap */ {
-		g_warning ("I won't mmap that file, using a slower method\n");
+		g_warning ("I won't mmap that file, using a slower method");
 		f->ole_mmap = FALSE;
 		f->mem = g_new (guint8, BB_BLOCK_SIZE);
 
 		if (!f->mem
 		    || (f->syswrap->read (file, f->mem, BB_BLOCK_SIZE)
 			== -1)) {
-			g_error ("Error reading header\n");
+			printf ("Error reading header\n");
 			g_free (f);
 			*fs = NULL;
 			return MS_OLE_ERR_EXIST;
@@ -1677,26 +1659,26 @@
 	if (MS_OLE_GET_GUINT32 (f->mem    ) != 0xe011cfd0 ||
 	    MS_OLE_GET_GUINT32 (f->mem + 4) != 0xe11ab1a1) {
 #if OLE_DEBUG > 0
-		g_print ("Failed OLE2 magic number %x %x\n",
-			 MS_OLE_GET_GUINT32(f->mem), MS_OLE_GET_GUINT32(f->mem+4));
+		printf ("Failed OLE2 magic number %x %x\n",
+			MS_OLE_GET_GUINT32 (f->mem), MS_OLE_GET_GUINT32 (f->mem + 4));
 #endif
 		ms_ole_destroy (fs);
 		return MS_OLE_ERR_FORMAT;
 	}
 	if (f->length % BB_BLOCK_SIZE)
-		g_warning ("Warning file '%s':%d non-integer number of blocks\n",
-			   name, f->length);
+		printf ("Warning file '%s':%d non-integer number of blocks\n",
+			name, f->length);
 
 	if (!ms_ole_setup (f)) {
-		g_error ("'%s' : duff file !\n", name);
+		printf ("'%s' : duff file !\n", name);
 		ms_ole_destroy (fs);
 		return MS_OLE_ERR_FORMAT;
 	}
-
-	g_assert (f->bb->len < f->length/BB_BLOCK_SIZE);
-
+	
+	g_assert (f->bb->len < f->length / BB_BLOCK_SIZE);
+	
 #if OLE_DEBUG > 0
-	g_print ("New OLE file '%s'\n", name);
+	printf ("New OLE file '%s'\n", name);
 #endif
 	/* If writing then when destroy commit it */
 	return MS_OLE_ERR_OK;
@@ -1719,7 +1701,7 @@
 ms_ole_create_vfs (MsOle **fs, const char *name, gboolean try_mmap,
 		   MsOleSysWrappers *wrappers)
 {
-        MsOle *f;
+	MsOle *f;
 	int file, zero=0;
 	int init_blocks = 1, lp;
 
@@ -1729,10 +1711,10 @@
 	f = *fs = ms_ole_new ();
 	take_wrapper_functions (f, wrappers);
 	if ((file = f->syswrap->open3 (name,
-				       O_RDWR|O_CREAT|O_TRUNC|/*O_NONBLOCK*/,
-				       S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP))
+					  O_RDWR|O_CREAT|O_TRUNC|O_NONBLOCK,
+					  S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP))
 	    == -1) {
-		g_error ("Can't create file '%s'\n", name);
+		printf ("Can't create file '%s'\n", name);
 		g_free (f);
 		*fs = NULL;
 		return MS_OLE_ERR_PERM;
@@ -1741,8 +1723,8 @@
 	if ((f->syswrap->lseek (file, BB_BLOCK_SIZE * init_blocks - 1,
 		    SEEK_SET) == (off_t)-1) ||
 	    (f->syswrap->write (file, &zero, 1) == -1)) {
-		g_error ("Serious error extending file to %d bytes\n",
-			 BB_BLOCK_SIZE*init_blocks);
+		printf ("Serious error extending file to %d bytes\n",
+			BB_BLOCK_SIZE*init_blocks);
 		g_free (f);
 		*fs = NULL;
 		return MS_OLE_ERR_SPACE;
@@ -1751,15 +1733,17 @@
 	f->ref_count = 0;
 	f->file_des  = file;
 	f->mode      = 'w';
-	if (f->syswrap->getfilesize (file, &(f->length))) {
-		g_warning ("Warning couldn't get the size of the file '%s'\n",
-			   name);
+
+	if (f->syswrap->getfilesize (file, &f->length)) {
+		printf ("Warning couldn't get the size of the file '%s'\n",
+			name);
 	}
 	if (f->length % BB_BLOCK_SIZE)
-		g_warning ("Warning file %d non-integer number of blocks\n",
-			   f->length);
+		printf ("Warning file %d non-integer number of blocks\n",
+			f->length);
 
 	if (try_mmap) {
+
 		if (f->syswrap->mmap)
 			f->mem = f->syswrap->mmap (
 				0, f->length, PROT_READ | PROT_WRITE,
@@ -1782,7 +1766,7 @@
 
 	/* The header block */
 	for (lp = 0; lp < BB_BLOCK_SIZE / 4; lp++)
-		MS_OLE_SET_GUINT32((*f)->mem + lp * 4,
+		MS_OLE_SET_GUINT32 (f->mem + lp * 4,
 				   (lp < (0x52 / 4)) ? 0: UNUSED_BLOCK);
 
 	MS_OLE_SET_GUINT32 (f->mem,     0xe011cfd0); /* Magic number */
@@ -1806,7 +1790,8 @@
 		f->bb  = g_array_new (FALSE, FALSE, sizeof(BLP));
 		f->sb  = g_array_new (FALSE, FALSE, sizeof(BLP));
 		f->sbf = g_array_new (FALSE, FALSE, sizeof(BLP));
-		p           = g_new(PPS, 1);
+
+		p           = g_new (PPS, 1);
 		p->sig      = PPS_SIG;
 		p->name     = g_strdup ("Root Entry");
 		p->start    = END_OF_CHAIN;
@@ -1814,15 +1799,15 @@
 		p->size     = 0;
 		p->children = NULL;
 		p->parent   = NULL;
-		f->pps = g_list_append (0, p);
-		f->num_pps = 1;
+		f->pps      = g_list_append (0, p);
+		f->num_pps  = 1;
 
 		if (f->ole_mmap)
 			f->bbattr = NULL;
 		else
 			f->bbattr   = g_ptr_array_new ();
 	}
-	g_assert (f->bb->len < f->length/BB_BLOCK_SIZE);
+	g_assert (f->bb->len < f->length / BB_BLOCK_SIZE);
 
 	return MS_OLE_ERR_OK;
 }
@@ -1860,7 +1845,7 @@
 #endif
 	if (f) {
 		if (f->ref_count != 0)
-			g_warning ("Unclosed files exist on this OLE stream\n");
+			g_warning ("Unclosed files exist on this OLE stream");
 
 		if (f->dirty)
 			ms_ole_cleanup (f);
@@ -2212,6 +2197,7 @@
 	g_return_val_if_fail (s, 0);
 	g_return_val_if_fail (ptr, 0);
 
+	
 	if (!s->blocks) {
 		printf ("Reading from NULL file\n");
 		return 0;
@@ -2268,6 +2254,7 @@
 	g_return_val_if_fail (s, 0);
 	g_return_val_if_fail (ptr, 0);
 
+	
 	if (!s->blocks) {
 		printf ("Reading from NULL file\n");
 		return 0;
@@ -2290,7 +2277,7 @@
 		g_assert (blkidx < s->blocks->len);
 		block = ms_array_index (s->blocks, BLP, blkidx);
 		src = GET_SB_R_PTR(s->file, block) + offset;
-				
+		
 		memcpy (ptr, src, cpylen);
 		ptr += cpylen;
 		length -= cpylen;
