physfs_internal.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. typedef struct __PHYSFS_FILEHANDLE__
  16. {
  17. /*
  18. * This is reserved for the driver to store information.
  19. */
  20. void *opaque;
  21. /*
  22. * This should be the DirReader that created this FileHandle.
  23. */
  24. struct __PHYSFS_DIRREADER__ *dirReader;
  25. /*
  26. * Read more from the file.
  27. */
  28. int (*read)(struct __PHYSFS_FILEHANDLE__ *handle, void *buffer,
  29. unsigned int objSize, unsigned int objCount);
  30. /*
  31. * Write more to the file. Archives don't have to implement this.
  32. * (Set it to NULL if not implemented).
  33. */
  34. int (*write)(struct __PHYSFS_FILEHANDLE__ *handle, void *buffer,
  35. unsigned int objSize, unsigned int objCount);
  36. /*
  37. * Returns non-zero if at end of file.
  38. */
  39. int (*eof)(struct __PHYSFS_FILEHANDLE__ *handle);
  40. /*
  41. * Returns byte offset from start of file.
  42. */
  43. int (*tell)(struct __PHYSFS_FILEHANDLE__ *handle);
  44. /*
  45. * Move read/write pointer to byte offset from start of file.
  46. * Returns non-zero on success, zero on error.
  47. */
  48. int (*seek)(struct __PHYSFS_FILEHANDLE__ *handle, int offset);
  49. /*
  50. * Close the file, and free this structure (including "opaque").
  51. */
  52. int (*close)(void);
  53. } FileHandle;
  54. typedef struct __PHYSFS_DIRREADER__
  55. {
  56. /*
  57. * This is reserved for the driver to store information.
  58. */
  59. void *opaque;
  60. /*
  61. * Returns a list (freeable via PHYSFS_freeList()) of
  62. * all files in dirname.
  63. * Symlinks should be followed.
  64. */
  65. char **(*enumerateFiles)(struct __PHYSFS_DIRREADER__ *r, const char *dirname);
  66. /*
  67. * Returns non-zero if filename is really a directory.
  68. * Symlinks should be followed.
  69. */
  70. int (*isDirectory)(struct __PHYSFS_DIRREADER__ *r, const char *name);
  71. /*
  72. * Returns non-zero if filename is really a symlink.
  73. */
  74. int (*isSymLink)(struct __PHYSFS_DIRREADER__ *r, const char *name);
  75. /*
  76. * Returns non-zero if filename can be opened for reading.
  77. * Symlinks should be followed.
  78. */
  79. int (*isOpenable)(struct __PHYSFS_DIRREADER__ *r, const char *name);
  80. /*
  81. * Open file for reading, and return a FileHandle.
  82. * Symlinks should be followed.
  83. */
  84. FileHandle *(*openRead)(struct __PHYSFS_DIRREADER__ *r, const char *filename);
  85. /*
  86. * Close directories/archives, and free this structure, including
  87. * the "opaque" entry. This should assume that it won't be called if
  88. * there are still files open from this DirReader.
  89. */
  90. void (*close)(struct __PHYSFS_DIRREADER__ *r);
  91. } DirReader;
  92. /* error messages... */
  93. #define ERR_IS_INITIALIZED "Already initialized"
  94. #define ERR_NOT_INITIALIZED "Not initialized"
  95. #define ERR_INVALID_ARGUMENT "Invalid argument"
  96. #define ERR_FILES_OPEN_WRITE "Files still open for writing"
  97. #define ERR_NO_DIR_CREATE "Failed to create directories"
  98. #define ERR_OUT_OF_MEMORY "Out of memory"
  99. #define ERR_NOT_IN_SEARCH_PATH "No such entry in search path"
  100. #define ERR_NOT_SUPPORTED "Operation not supported"
  101. /*
  102. * Call this to set the message returned by PHYSFS_getLastError().
  103. * Please only use the ERR_* constants above, or add new constants to the
  104. * above group, but I want these all in one place.
  105. */
  106. void __PHYSFS_setError(const char *err);
  107. /* This gets used all over for lessening code clutter. */
  108. #define BAIL_IF_MACRO(c, e, r) if (c) { __PHYSFS_setError(e); return(r); }
  109. /*--------------------------------------------------------------------------*/
  110. /*--------------------------------------------------------------------------*/
  111. /*------------ ----------------*/
  112. /*------------ You MUST implement the following functions ----------------*/
  113. /*------------ if porting to a new platform. ----------------*/
  114. /*------------ (see unix.c for an example) ----------------*/
  115. /*------------ ----------------*/
  116. /*--------------------------------------------------------------------------*/
  117. /*--------------------------------------------------------------------------*/
  118. /*
  119. * The dir separator; "/" on unix, "\\" on win32, ":" on MacOS, etc...
  120. * Obviously, this isn't a function, but it IS a null-terminated string.
  121. */
  122. extern const char *__PHYSFS_PlatformDirSeparator;
  123. /*
  124. * Platform implementation of PHYSFS_getCdRomDirs()...
  125. * See physfs.h. The retval should be freeable via PHYSFS_freeList().
  126. */
  127. char **__PHYSFS_platformDetectAvailableCDs(void);
  128. /*
  129. * Calculate the base dir, if your platform needs special consideration.
  130. * Just return NULL if the standard routines will suffice. (see
  131. * calculateBaseDir() in physfs.c ...)
  132. * Caller will free() the retval if it's not NULL.
  133. */
  134. char *__PHYSFS_platformCalcBaseDir(char *argv0);
  135. /*
  136. * Get the platform-specific user name.
  137. * Caller will free() the retval if it's not NULL. If it's NULL, the username
  138. * will default to "default".
  139. */
  140. char *__PHYSFS_platformGetUserName(void);
  141. /*
  142. * Get the platform-specific user dir.
  143. * Caller will free() the retval if it's not NULL. If it's NULL, the userdir
  144. * will default to basedir/username.
  145. */
  146. char *__PHYSFS_platformGetUserDir(void);
  147. /*
  148. * Return a number that uniquely identifies the current thread.
  149. * On a platform without threading, (1) will suffice. These numbers are
  150. * arbitrary; the only requirement is that no two threads have the same
  151. * number.
  152. */
  153. int __PHYSFS_platformGetThreadID(void);
  154. /*
  155. * This is a pass-through to whatever stricmp() is called on your platform.
  156. */
  157. int __PHYSFS_platformStricmp(const char *str1, const char *str2);
  158. #ifdef __cplusplus
  159. extern "C" {
  160. #endif
  161. #endif
  162. /* end of physfs_internal.h ... */