sysfile_read returning error -39
Hi All
I have some code in my external that reads from a file using sysfile_read. On WinXP everything works fine but on Mac OSX sysfile_read returns error -39. I looked in the SDK docs but could find no way to convert this error number into a human readable string. This is what i get in the max window :
• error: error -39 reading file Macintosh HD:/Users/bschiett/sandbox/c3max/trunk/pwm.bin (18956 bytes read)
fwBuffer = (char*) sysmem_newptrclear(sizeof(char) * LIMIT);
if (fwBuffer)
{
err = path_opensysfile(s->s_name, path_getdefault(), &handle, READ_PERM);
if (err)
error("error %d opening file %s", err, s->s_name);
else
{
post("reading from %s ...", s->s_name);
// read raw data from .bin file into buffer
count = ( long)(sizeof(char) * LIMIT);
err = sysfile_read(handle, &count, fwBuffer);
// make sure we read all data
if (err)
error("error %d reading file %s (%d bytes read)", err, s->s_name, count);
else
{
...
}
// close file
sysfile_close(handle);
}
// free memory
sysmem_freeptr(fwBuffer);
}
else
{
error("failed to allocate memory ", 0);
return;
}
On Feb 27, 2007, at 8:41 AM, bert wrote:
> I have some code in my external that reads from a file using
> sysfile_read. On WinXP everything works fine but on Mac OSX
> sysfile_read returns error -39. I looked in the SDK docs but could
> find no way to convert this error number into a human readable string.
From MacErrors.h, this means end of file reached.
-Joshua
hi,
error -39 is:
eofErr (End of file; no additional data in the format)
see this link
http://docs.info.apple.com/article.html?artnum=9805
I hope that helps
ciao
/Giuseppe
---------- Initial Header -----------
>From : dev-bounces@cycling74.com
Cc :
Date : Tue, 27 Feb 2007 09:09:48 -0800
Subject : Re: [dev] sysfile_read returning error -39
>
> On Feb 27, 2007, at 8:41 AM, bert wrote:
>
> > I have some code in my external that reads from a file using
> > sysfile_read. On WinXP everything works fine but on Mac OSX
> > sysfile_read returns error -39. I looked in the SDK docs but could
> > find no way to convert this error number into a human readable string.
>
> From MacErrors.h, this means end of file reached.
>
> -Joshua
>
------------------------------------------------------
Passa a Infostrada. ADSL e Telefono senza limiti e senza canone Telecom
http://click.libero.it/infostrada27eb07
Hi Giuseppe, Joshua,
Thanks a lot for the reply and for clearing this up. Is there a function that will take such an error number and return a readable string?
Now that I know that sysfile_read returns EOF, does this mean that the file was succesfully read from begin to end, or does it mean I first need to rewind the file before I can start reading?
Thanks,
Bert
ok guys, i found the problem. of course it was in my code ...
I was doing this :
count = ( long)(sizeof(char) * LIMIT);
err = sysfile_read(handle, &count, fwBuffer);
where LIMIT was a number like 128000. The actual file itself was only 18000 bytes.
on Windows XP, sysfile_read will just read the entire file and give no error. however, on mac osx, an error will be returned indicating end of file, like Joshua and Guiseppe pointed out.
so the lesson is : always manually check the file size and then determine how much data you want to read instead of relying on an API to work a certain way ...