[BUG] file Truncate is it really busted?

John M McIntosh johnmci at smalltalkconsulting.com
Fri Nov 23 08:56:19 UTC 2001


MMm well I think I added truncate so I'm wondering if it's really 
busted on non-mac platforms.

You see

int sqFileTruncate(SQFile *f,int offset) {
	/* Truncate the file*/

	if (!sqFileValid(f)) return interpreterProxy->success(false);
	if (ftruncate(f->file,offset)) return interpreterProxy->success(false);
	f->fileSize = ftell(f->file);
	return 1;
}

But really on Unix f->file points to a FILE structure, but ftruncate 
needs a file descriptor (an integer).

#include <unistd.h>
int sqFileTruncate(SQFile *f,int offset) {
	/* Truncate the file*/

	if (!sqFileValid(f)) return interpreterProxy->success(false);
	if (ftruncate(fileno(f->file),offset)) return 
interpreterProxy->success(false);
	f->fileSize = ftell(f->file);
	return 1;
}

Ah, thoughts are welcome. Of course I'm going to make the change 
because the SUnits fail... Hint it works on the mac because ftruncate 
didn't exist in a workable form for CW 6 so I added one.

-- 
--
===========================================================================
John M. McIntosh <johnmci at smalltalkconsulting.com> 1-800-477-2659
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
===========================================================================




More information about the Squeak-dev mailing list