| [AD] pack_ferror() - differences between platforms |
[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]
Hi I was about to post a bug report - pack_ferror() wasn't being set on Linux - but it seems to be more of a quirk than a bug. With DJGPP, pack_ferror() will return nonzero if the end of the file has been reached (incidentally I was using a compressed file). With Linux, pack_ferror() will not. While I was looking for a possible cause for the bug, it occurred to me that this was what pack_feof() was for. I tested with Allegro 4.0.0 on DJGPP and Allegro 4.1.x CVS on Linux. Just to make sure, I tried Allegro 4.0.0 on Linux, and it behaved the same as Allegro 4.1.x CVS on Linux. So this really does appear to be a platform issue, not a version issue. (By the way, I still have Allegro 4.0.0 on my laptop because I hardly ever use the laptop any more and it's not worth the trouble of upgrading :) Anyhow, I believe it should be documented in pack_ferror()'s description that EOF may not be considered an error - or the library should be fixed so that it either always is or always isn't considered an error. I've attached three patches - don't apply more than one of them. They are as follows: allegro._tx.diff Updates the docs to indicate that the return value of pack_ferror() is undefined after you try to read beyond the end of the file. file.inl.eofiserror.diff Modifies packfile_ferror() to return nonzero if either PACKFILE_FLAG_EOF or PACKFILE_FLAG_ERROR is set in the PACKFILE struct. file.inl.eofnoterror.hacky.diff Modifies packfile_ferror() to return nonzero only if PACKFILE_FLAG_ERROR is set _and_ PACKFILE_FLAG_EOF is clear. This is hacky, as a valid error condition may accidentally be missed... I've also attached an archive of these files, in case your e-mail clients mess them up :) Ben
Attachment:
diffs.tar.gz
Description: GNU Zip compressed data
--- include/allegro/inline/file.inl.old Sun Jan 19 13:35:50 2003
+++ include/allegro/inline/file.inl Sun Jan 19 13:40:25 2003
@@ -51,7 +51,7 @@
AL_INLINE(int, pack_ferror, (PACKFILE *f),
{
- return (f->flags & PACKFILE_FLAG_ERROR);
+ return ((f->flags & (PACKFILE_FLAG_ERROR | PACKFILE_FLAG_EOF)) == PACKFILE_FLAG_ERROR);
})
#ifdef __cplusplus
--- include/allegro/inline/file.inl.old Sun Jan 19 13:35:50 2003
+++ include/allegro/inline/file.inl Sun Jan 19 13:35:55 2003
@@ -51,7 +51,7 @@
AL_INLINE(int, pack_ferror, (PACKFILE *f),
{
- return (f->flags & PACKFILE_FLAG_ERROR);
+ return (f->flags & (PACKFILE_FLAG_ERROR | PACKFILE_FLAG_EOF));
})
#ifdef __cplusplus
--- docs/src/allegro._tx.old Sun Jan 19 13:26:35 2003
+++ docs/src/allegro._tx Sun Jan 19 13:33:31 2003
@@ -6321,6 +6321,10 @@
DOS/Windows. If you do not want either of these things to happen,
use pack_fwrite() and/or pack_putc() instead.
</ul>
+ Please note that the return value of pack_ferror() after you try to read
+ beyond the end of the file is undefined. If you wish to detect premature
+ end of file, you should check both pack_ferror() and pack_feof().
+
@@PACKFILE *@pack_fopen_chunk(PACKFILE *f, int pack);
@xref pack_fclose_chunk, pack_fopen
Opens a sub-chunk of a file. Chunks are primarily intended for use by the
| Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |