]> git.draconx.ca Git - upkg.git/commitdiff
libupkg: Add explicit conversions to stdio wrappers.
authorNick Bowler <nbowler@draconx.ca>
Sun, 31 Jan 2010 21:53:13 +0000 (16:53 -0500)
committerNick Bowler <nbowler@draconx.ca>
Sun, 31 Jan 2010 21:53:13 +0000 (16:53 -0500)
Some C libraries provide a macro version of feof which does not convert
the provided pointer to FILE * before dereferencing it.  Ordinarily,
this conversion would occur automatically since feof's prototype
specifies FILE *, but this is suppressed in the macro case.

It is not clear to me whether this behaviour is consistent with the
requirements of the C standard.  However, after encountering at least
two implementations which do this, explicit conversions seem simple
enough.

src/libupkg.c

index 2c0cf0724de05f358c5c1c86c09edcfc24b7accf..40b39136f4c3164f22732a73e33adba2b1fae65e 100644 (file)
@@ -61,27 +61,27 @@ struct upkg_private {
 /* Default I/O operations for ordinary files. */
 static size_t file_read(void *buf, size_t size, void *handle)
 {
-       return fread(buf, 1, size, handle);
+       return fread(buf, 1, size, (FILE *)handle);
 }
 
 static int file_seek(void *handle, long offset, int whence)
 {
-       return fseek(handle, offset, whence);
+       return fseek((FILE *)handle, offset, whence);
 }
 
 static long file_tell(void *handle)
 {
-       return ftell(handle);
+       return ftell((FILE *)handle);
 }
 
 static int file_eof(void *handle)
 {
-       return feof(handle);
+       return feof((FILE *)handle);
 }
 
 static int file_close(void *handle)
 {
-       return fclose(handle);
+       return fclose((FILE *)handle);
 }
 
 const struct upkg_file_ops upkg_default_fops = {