[BUG] opening unix-written image files
Tim Rowledge
tim at sumeru.stanford.edu
Mon Jan 28 22:04:07 UTC 2002
Felix Franz <fefr at gmx.net> is claimed by the authorities to have written:
> > Since the w32 vm appears to use the same piece of code (IsImage()), I
> > suspect the same problem can occur.
>
>
> yes, the same problem occurs on Windows (latest VM) also.
I've fixed the problem for Acorn and I suspect that the attached new
version of IsImage() would work for w32.
tim
static int IsImage(char *name) {
/* check the named file to see if it is a decent candidate for a Squeak image file. Remember to check both the very beginning of the file and 512 bytes into it, just in case it was written from a unix machine - which adds a short extra header */
FILE *fp;
int magic;
int byteSwapped(int);
fp = fopen(name,"rb");
if(!fp) return 0; /* could not open file */
if(fread(&magic, 1, sizeof(magic), fp) != sizeof(magic)) {
/* could not read an int from file */
fclose(fp);
return 0;
}
if (magic > 0xFFFF) {
magic = byteSwapped(magic);
}
ImageVersionNumber = magic;
if (readableFormat(magic)) {
fclose(fp);
return true;
}
/* no luck at beginning of file, seek to 512 and try again */
if(fseek( fp, 512, SEEK_SET)) {
/* seek failed, which implies fileis too small */
fclose(fp);
return false;
}
if(fread(&magic, 1, sizeof(magic), fp) != sizeof(magic)) {
/* could not read an int from file */
fclose(fp);
return 0;
}
if (magic > 0xFFFF) {
magic = byteSwapped(magic);
}
ImageVersionNumber = magic;
if (readableFormat(magic)) {
fclose(fp);
return true;
}
return false;
}
--
Tim Rowledge, tim at sumeru.stanford.edu, http://sumeru.stanford.edu/tim
Useful random insult:- Uses his head to keep the rain out of his neck.
More information about the Squeak-dev
mailing list
|