physfs_internal.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. /*
  74. * Symlinks should always be followed; PhysicsFS will use
  75. * DirFunctions->isSymLink() and make a judgement on whether to
  76. * continue to call other methods based on that.
  77. */
  78. typedef struct __PHYSFS_DIRFUNCTIONS__
  79. {
  80. /*
  81. * Returns non-zero if (filename) is a valid archive that this
  82. * driver can handle. This filename is in platform-dependent
  83. * notation.
  84. */
  85. int (*isArchive)(const char *filename);
  86. /*
  87. * Return a DirHandle for dir/archive (name).
  88. * This filename is in platform-dependent notation.
  89. * return (NULL) on error.
  90. */
  91. DirHandle *(*openArchive)(const char *name);
  92. /*
  93. * Returns a list (freeable via PHYSFS_freeList()) of
  94. * all files in dirname.
  95. * This dirname is in platform-independent notation.
  96. */
  97. char **(*enumerateFiles)(DirHandle *r, const char *dirname);
  98. /*
  99. * Returns non-zero if filename is really a directory.
  100. * This filename is in platform-independent notation.
  101. */
  102. int (*isDirectory)(DirHandle *r, const char *name);
  103. /*
  104. * Returns non-zero if filename is really a symlink.
  105. * This filename is in platform-independent notation.
  106. */
  107. int (*isSymLink)(DirHandle *r, const char *name);
  108. /*
  109. * Returns non-zero if filename can be opened for reading.
  110. * This filename is in platform-independent notation.
  111. */
  112. int (*isOpenable)(DirHandle *r, const char *name);
  113. /*
  114. * Open file for reading, and return a FileHandle.
  115. * This filename is in platform-independent notation.
  116. */
  117. FileHandle *(*openRead)(DirHandle *r, const char *filename);
  118. /*
  119. * Open file for writing, and return a FileHandle.
  120. * This filename is in platform-independent notation.
  121. * This method may be NULL.
  122. */
  123. FileHandle *(*openWrite)(DirHandle *r, const char *filename);
  124. /*
  125. * Open file for appending, and return a FileHandle.
  126. * This filename is in platform-independent notation.
  127. * This method may be NULL.
  128. */
  129. FileHandle *(*openAppend)(DirHandle *r, const char *filename);
  130. /*
  131. * Close directories/archives, and free the handle, including
  132. * the "opaque" entry. This should assume that it won't be called if
  133. * there are still files open from this DirHandle.
  134. */
  135. void (*close)(DirHandle *r);
  136. } DirFunctions;
  137. /* error messages... */
  138. #define ERR_IS_INITIALIZED "Already initialized"
  139. #define ERR_NOT_INITIALIZED "Not initialized"
  140. #define ERR_INVALID_ARGUMENT "Invalid argument"
  141. #define ERR_FILES_OPEN_READ "Files still open for reading"
  142. #define ERR_FILES_OPEN_WRITE "Files still open for writing"
  143. #define ERR_NO_DIR_CREATE "Failed to create directories"
  144. #define ERR_OUT_OF_MEMORY "Out of memory"
  145. #define ERR_NOT_IN_SEARCH_PATH "No such entry in search path"
  146. #define ERR_NOT_SUPPORTED "Operation not supported"
  147. #define ERR_UNSUPPORTED_ARCHIVE "Archive type unsupported"
  148. /*
  149. * Call this to set the message returned by PHYSFS_getLastError().
  150. * Please only use the ERR_* constants above, or add new constants to the
  151. * above group, but I want these all in one place.
  152. */
  153. void __PHYSFS_setError(const char *err);
  154. /* This gets used all over for lessening code clutter. */
  155. #define BAIL_IF_MACRO(c, e, r) if (c) { __PHYSFS_setError(e); return(r); }
  156. /*--------------------------------------------------------------------------*/
  157. /*--------------------------------------------------------------------------*/
  158. /*------------ ----------------*/
  159. /*------------ You MUST implement the following functions ----------------*/
  160. /*------------ if porting to a new platform. ----------------*/
  161. /*------------ (see unix.c for an example) ----------------*/
  162. /*------------ ----------------*/
  163. /*--------------------------------------------------------------------------*/
  164. /*--------------------------------------------------------------------------*/
  165. /*
  166. * The dir separator; "/" on unix, "\\" on win32, ":" on MacOS, etc...
  167. * Obviously, this isn't a function, but it IS a null-terminated string.
  168. */
  169. extern const char *__PHYSFS_PlatformDirSeparator;
  170. /*
  171. * Platform implementation of PHYSFS_getCdRomDirs()...
  172. * See physfs.h. The retval should be freeable via PHYSFS_freeList().
  173. */
  174. char **__PHYSFS_platformDetectAvailableCDs(void);
  175. /*
  176. * Calculate the base dir, if your platform needs special consideration.
  177. * Just return NULL if the standard routines will suffice. (see
  178. * calculateBaseDir() in physfs.c ...)
  179. * Caller will free() the retval if it's not NULL.
  180. */
  181. char *__PHYSFS_platformCalcBaseDir(char *argv0);
  182. /*
  183. * Get the platform-specific user name.
  184. * Caller will free() the retval if it's not NULL. If it's NULL, the username
  185. * will default to "default".
  186. */
  187. char *__PHYSFS_platformGetUserName(void);
  188. /*
  189. * Get the platform-specific user dir.
  190. * Caller will free() the retval if it's not NULL. If it's NULL, the userdir
  191. * will default to basedir/username.
  192. */
  193. char *__PHYSFS_platformGetUserDir(void);
  194. /*
  195. * Return a number that uniquely identifies the current thread.
  196. * On a platform without threading, (1) will suffice. These numbers are
  197. * arbitrary; the only requirement is that no two threads have the same
  198. * number.
  199. */
  200. int __PHYSFS_platformGetThreadID(void);
  201. /*
  202. * This is a pass-through to whatever stricmp() is called on your platform.
  203. */
  204. int __PHYSFS_platformStricmp(const char *str1, const char *str2);
  205. /*
  206. * Return non-zero if filename (in platform-dependent notation) is a symlink.
  207. */
  208. int __PHYSFS_platformIsSymlink(const char *fname);
  209. #ifdef __cplusplus
  210. extern "C" {
  211. #endif
  212. #endif
  213. /* end of physfs_internal.h ... */