[BUG][VM][FIX]file truncate primitive broken on *nix

Julian Fitzell julian at beta4.com
Fri Jan 9 18:34:49 UTC 2004


I encountered a problem calling #primTruncate:to: - it gives a 
"primitive failed" on Linux.  Searching the archives, I found this post 
from John M from 2 years ago (!) with a suggested fix.

http://lists.squeakfoundation.org/pipermail/squeak-dev/2001-November/031323.html

I applied the fix to the CVS sources and the problem seems to be fixed. 
  (well actually, now that I think about it, I haven't really checked 
that the file gets truncated - but the primitive doesn't fail and 
omnibase seems to work).

I make no particular claims as to the validity of the fix, mostly I'm 
just reposting in the hopes that someone will verify it as correct and 
someone (Ned?) will merge it into CVS.

Julian
-------------- next part --------------
Index: platforms/Cross/plugins/FilePlugin/FilePlugin.h
===================================================================
RCS file: /cvsroot/squeak/squeak/platforms/Cross/plugins/FilePlugin/FilePlugin.h,v
retrieving revision 1.4
diff -u -r1.4 FilePlugin.h
--- platforms/Cross/plugins/FilePlugin/FilePlugin.h	29 Jan 2002 05:18:38 -0000	1.4
+++ platforms/Cross/plugins/FilePlugin/FilePlugin.h	9 Jan 2004 06:01:15 -0000
@@ -36,7 +36,7 @@
 int sqFileValid(SQFile *f);
 size_t sqFileWriteFromAt(SQFile *f, size_t count, int byteArrayIndex, size_t startIndex);
 int sqFileFlush(SQFile *f);
-int sqFileTruncate(SQFile *f,squeakFileOffsetType offset);
+int sqFileTruncate(SQFile *f,int offset);
 int sqFileThisSession(void);
 
 /* directories */
Index: platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c
===================================================================
RCS file: /cvsroot/squeak/squeak/platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c,v
retrieving revision 1.6
diff -u -r1.6 sqFilePluginBasicPrims.c
--- platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c	23 Apr 2002 22:37:31 -0000	1.6
+++ platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c	9 Jan 2004 06:01:15 -0000
@@ -27,6 +27,7 @@
                                                       
 #include "sq.h"
 #ifndef NO_STD_FILE_SUPPORT
+#include <unistd.h>
 #include "FilePlugin.h"
 
 /***
@@ -251,17 +252,16 @@
 	return 1;
 }
 
-int sqFileTruncate(SQFile *f,squeakFileOffsetType offset) {
+int sqFileTruncate(SQFile *f,int offset) {
 	/* Truncate the file*/
 
-	if (!sqFileValid(f)) return interpreterProxy->success(false);
- 	if (sqFTruncate(f->file,offset)) {
-            return interpreterProxy->success(false);
-        } 
+	if (!sqFileValid) return interpreterProxy->success(false);
+	if (ftruncate(fileno(f->file),offset)) {
+		return interpreterProxy->success(false);
+	}
 	f->fileSize = ftell(f->file);
 	return 1;
 }
-
 
 int sqFileValid(SQFile *f) {
 	return (


More information about the Squeak-dev mailing list