diff --git a/ChangeLog b/ChangeLog index 6c7cc5c6b..8522d6838 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-02-24 Chris Taylor + + * include/physfsx.h: use PHYSFSX_openReadBuffered and + PHYSFSX_openWriteBuffered, where appropriate + 2005-02-11 Bradley Bell * debian/control: build-dep on libphysfs-dev diff --git a/include/physfsx.h b/include/physfsx.h index 09f40065d..add6dc086 100644 --- a/include/physfsx.h +++ b/include/physfsx.h @@ -1,4 +1,4 @@ -/* $Id: physfsx.h,v 1.7 2004-12-05 10:56:32 btb Exp $ */ +/* $Id: physfsx.h,v 1.8 2005-02-25 02:02:22 chris Exp $ */ /* * @@ -146,4 +146,43 @@ static inline PHYSFS_sint64 PHYSFSX_getFreeDiskSpace() #endif } +//Open a file for reading, set up a buffer +static inline PHYSFS_file *PHYSFSX_openReadBuffered(char *filename) +{ + PHYSFS_file *fp; + PHYSFS_uint64 bufSize; + + if (filename[0] == '\x01') + { + //FIXME: don't look in dir, only in hogfile + filename++; + } + + fp = PHYSFS_openRead(filename); + if (!fp) + return NULL; + + bufSize = PHYSFS_fileLength(fp); + while (!PHYSFS_setBuffer(fp, bufSize) && bufSize) + bufSize /= 2; // even if the error isn't memory full, for a 20MB file it'll only do this 8 times + + return fp; +} + +//Open a file for writing, set up a buffer +static inline PHYSFS_file *PHYSFSX_openWriteBuffered(char *filename) +{ + PHYSFS_file *fp; + PHYSFS_uint64 bufSize = 1024*1024; // hmm, seems like an OK size. + + fp = PHYSFS_openWrite(filename); + if (!fp) + return NULL; + + while (!PHYSFS_setBuffer(fp, bufSize) && bufSize) + bufSize /= 2; + + return fp; +} + #endif /* PHYSFSX_H */