physfs_internal.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. * Internal function/structure declaration. Do NOT include in your
  3. * application.
  4. *
  5. * Please see the file LICENSE in the source's root directory.
  6. *
  7. * This file written by Ryan C. Gordon.
  8. */
  9. #ifndef _INCLUDE_PHYSFS_INTERNAL_H_
  10. #define _INCLUDE_PHYSFS_INTERNAL_H_
  11. #ifndef __PHYSICSFS_INTERNAL__
  12. #error Do not include this header from your applications.
  13. #endif
  14. struct __PHYSFS_DIRREADER__;
  15. struct __PHYSFS_FILEFUNCTIONS__;
  16. typedef struct __PHYSFS_FILEHANDLE__
  17. {
  18. /*
  19. * This is reserved for the driver to store information.
  20. */
  21. void *opaque;
  22. /*
  23. * This should be the DirHandle that created this FileHandle.
  24. */
  25. const struct __PHYSFS_DIRREADER__ *dirReader;
  26. /*
  27. * Pointer to the file i/o functions for this filehandle.
  28. */
  29. const struct __PHYSFS_FILEFUNCTIONS__ *funcs;
  30. } FileHandle;
  31. typedef struct __PHYSFS_FILEFUNCTIONS__
  32. {
  33. /*
  34. * Read more from the file.
  35. */
  36. int (*read)(FileHandle *handle, void *buffer,
  37. unsigned int objSize, unsigned int objCount);
  38. /*
  39. * Write more to the file. Archives don't have to implement this.
  40. * (Set it to NULL if not implemented).
  41. */
  42. int (*write)(FileHandle *handle, void *buffer,
  43. unsigned int objSize, unsigned int objCount);
  44. /*
  45. * Returns non-zero if at end of file.
  46. */
  47. int (*eof)(FileHandle *handle);
  48. /*
  49. * Returns byte offset from start of file.
  50. */
  51. int (*tell)(FileHandle *handle);
  52. /*
  53. * Move read/write pointer to byte offset from start of file.
  54. * Returns non-zero on success, zero on error.
  55. */
  56. int (*seek)(FileHandle *handle, int offset);
  57. /*
  58. * Close the file, and free the FileHandle structure (including "opaque").
  59. */
  60. int (*close)(FileHandle *handle);
  61. } FileFunctions;
  62. typedef struct __PHYSFS_DIRREADER__
  63. {
  64. /*
  65. * This is reserved for the driver to store information.
  66. */
  67. void *opaque;
  68. /*
  69. * Pointer to the directory i/o functions for this reader.
  70. */
  71. const struct __PHYSFS_DIRFUNCTIONS__ *funcs;
  72. } DirHandle;
  73. typedef struct __PHYSFS_LINKEDSTRINGLIST__
  74. {
  75. char *str;
  76. struct __PHYSFS_LINKEDSTRINGLIST__ *next;
  77. } LinkedStringList;
  78. /*
  79. * Symlinks should always be followed; PhysicsFS will use
  80. * DirFunctions->isSymLink() and make a judgement on whether to
  81. * continue to call other methods based on that.
  82. */
  83. typedef struct __PHYSFS_DIRFUNCTIONS__
  84. {
  85. /*
  86. * Returns non-zero if (filename) is a valid archive that this
  87. * driver can handle. This filename is in platform-dependent
  88. * notation.
  89. */
  90. int (*isArchive)(const char *filename);
  91. /*
  92. * Return a DirHandle for dir/archive (name).
  93. * This filename is in platform-dependent notation.
  94. * return (NULL) on error.
  95. */
  96. DirHandle *(*openArchive)(const char *name);
  97. /*
  98. * Returns a list of all files in dirname. Each element of this list
  99. * (and its "str" field) will be deallocated with the system's free()
  100. * function by the caller, so be sure to explicitly malloc() each
  101. * chunk.
  102. * If you have a memory failure, return as much as you can.
  103. * This dirname is in platform-independent notation.
  104. */
  105. LinkedStringList **(*enumerateFiles)(DirHandle *r, const char *dirname);
  106. /*
  107. * Returns non-zero if filename is really a directory.
  108. * This filename is in platform-independent notation.
  109. */
  110. int (*isDirectory)(DirHandle *r, const char *name);
  111. /*
  112. * Returns non-zero if filename is really a symlink.
  113. * This filename is in platform-independent notation.
  114. */
  115. int (*isSymLink)(DirHandle *r, const char *name);
  116. /*
  117. * Returns non-zero if filename can be opened for reading.
  118. * This filename is in platform-independent notation.
  119. */
  120. int (*isOpenable)(DirHandle *r, const char *name);
  121. /*
  122. * Open file for reading, and return a FileHandle.
  123. * This filename is in platform-independent notation.
  124. */
  125. FileHandle *(*openRead)(DirHandle *r, const char *filename);
  126. /*
  127. * Open file for writing, and return a FileHandle.
  128. * This filename is in platform-independent notation.
  129. * This method may be NULL.
  130. */
  131. FileHandle *(*openWrite)(DirHandle *r, const char *filename);
  132. /*
  133. * Open file for appending, and return a FileHandle.
  134. * This filename is in platform-independent notation.
  135. * This method may be NULL.
  136. */
  137. FileHandle *(*openAppend)(DirHandle *r, const char *filename);
  138. /*
  139. * Close directories/archives, and free the handle, including
  140. * the "opaque" entry. This should assume that it won't be called if
  141. * there are still files open from this DirHandle.
  142. */
  143. void (*close)(DirHandle *r);
  144. } DirFunctions;
  145. /* error messages... */
  146. #define ERR_IS_INITIALIZED "Already initialized"
  147. #define ERR_NOT_INITIALIZED "Not initialized"
  148. #define ERR_INVALID_ARGUMENT "Invalid argument"
  149. #define ERR_FILES_OPEN_READ "Files still open for reading"
  150. #define ERR_FILES_OPEN_WRITE "Files still open for writing"
  151. #define ERR_NO_DIR_CREATE "Failed to create directories"
  152. #define ERR_OUT_OF_MEMORY "Out of memory"
  153. #define ERR_NOT_IN_SEARCH_PATH "No such entry in search path"
  154. #define ERR_NOT_SUPPORTED "Operation not supported"
  155. #define ERR_UNSUPPORTED_ARCHIVE "Archive type unsupported"
  156. /*
  157. * Call this to set the message returned by PHYSFS_getLastError().
  158. * Please only use the ERR_* constants above, or add new constants to the
  159. * above group, but I want these all in one place.
  160. */
  161. void __PHYSFS_setError(const char *err);
  162. /* This gets used all over for lessening code clutter. */
  163. #define BAIL_IF_MACRO(c, e, r) if (c) { __PHYSFS_setError(e); return(r); }
  164. /*--------------------------------------------------------------------------*/
  165. /*--------------------------------------------------------------------------*/
  166. /*------------ ----------------*/
  167. /*------------ You MUST implement the following functions ----------------*/
  168. /*------------ if porting to a new platform. ----------------*/
  169. /*------------ (see unix.c for an example) ----------------*/
  170. /*------------ ----------------*/
  171. /*--------------------------------------------------------------------------*/
  172. /*--------------------------------------------------------------------------*/
  173. /*
  174. * The dir separator; "/" on unix, "\\" on win32, ":" on MacOS, etc...
  175. * Obviously, this isn't a function, but it IS a null-terminated string.
  176. */
  177. extern const char *__PHYSFS_PlatformDirSeparator;
  178. /*
  179. * Platform implementation of PHYSFS_getCdRomDirs()...
  180. * See physfs.h. The retval should be freeable via PHYSFS_freeList().
  181. */
  182. char **__PHYSFS_platformDetectAvailableCDs(void);
  183. /*
  184. * Calculate the base dir, if your platform needs special consideration.
  185. * Just return NULL if the standard routines will suffice. (see
  186. * calculateBaseDir() in physfs.c ...)
  187. * Caller will free() the retval if it's not NULL.
  188. */
  189. char *__PHYSFS_platformCalcBaseDir(char *argv0);
  190. /*
  191. * Get the platform-specific user name.
  192. * Caller will free() the retval if it's not NULL. If it's NULL, the username
  193. * will default to "default".
  194. */
  195. char *__PHYSFS_platformGetUserName(void);
  196. /*
  197. * Get the platform-specific user dir.
  198. * Caller will free() the retval if it's not NULL. If it's NULL, the userdir
  199. * will default to basedir/username.
  200. */
  201. char *__PHYSFS_platformGetUserDir(void);
  202. /*
  203. * Return a number that uniquely identifies the current thread.
  204. * On a platform without threading, (1) will suffice. These numbers are
  205. * arbitrary; the only requirement is that no two threads have the same
  206. * number.
  207. */
  208. int __PHYSFS_platformGetThreadID(void);
  209. /*
  210. * This is a pass-through to whatever stricmp() is called on your platform.
  211. */
  212. int __PHYSFS_platformStricmp(const char *str1, const char *str2);
  213. /*
  214. * Return non-zero if filename (in platform-dependent notation) is a symlink.
  215. */
  216. int __PHYSFS_platformIsSymlink(const char *fname);
  217. #ifdef __cplusplus
  218. extern "C" {
  219. #endif
  220. #endif
  221. /* end of physfs_internal.h ... */