| 1 | /** |
| 2 | * \file physfs.h |
| 3 | * |
| 4 | * Main header file for PhysicsFS. |
| 5 | */ |
| 6 | |
| 7 | /** |
| 8 | * \mainpage PhysicsFS |
| 9 | * |
| 10 | * The latest version of PhysicsFS can be found at: |
| 11 | * https://icculus.org/physfs/ |
| 12 | * |
| 13 | * PhysicsFS; a portable, flexible file i/o abstraction. |
| 14 | * |
| 15 | * This API gives you access to a system file system in ways superior to the |
| 16 | * stdio or system i/o calls. The brief benefits: |
| 17 | * |
| 18 | * - It's portable. |
| 19 | * - It's safe. No file access is permitted outside the specified dirs. |
| 20 | * - It's flexible. Archives (.ZIP files) can be used transparently as |
| 21 | * directory structures. |
| 22 | * |
| 23 | * With PhysicsFS, you have a single writing directory and multiple |
| 24 | * directories (the "search path") for reading. You can think of this as a |
| 25 | * filesystem within a filesystem. If (on Windows) you were to set the |
| 26 | * writing directory to "C:\MyGame\MyWritingDirectory", then no PHYSFS calls |
| 27 | * could touch anything above this directory, including the "C:\MyGame" and |
| 28 | * "C:\" directories. This prevents an application's internal scripting |
| 29 | * language from piddling over c:\\config.sys, for example. If you'd rather |
| 30 | * give PHYSFS full access to the system's REAL file system, set the writing |
| 31 | * dir to "C:\", but that's generally A Bad Thing for several reasons. |
| 32 | * |
| 33 | * Drive letters are hidden in PhysicsFS once you set up your initial paths. |
| 34 | * The search path creates a single, hierarchical directory structure. |
| 35 | * Not only does this lend itself well to general abstraction with archives, |
| 36 | * it also gives better support to operating systems like MacOS and Unix. |
| 37 | * Generally speaking, you shouldn't ever hardcode a drive letter; not only |
| 38 | * does this hurt portability to non-Microsoft OSes, but it limits your win32 |
| 39 | * users to a single drive, too. Use the PhysicsFS abstraction functions and |
| 40 | * allow user-defined configuration options, too. When opening a file, you |
| 41 | * specify it like it was on a Unix filesystem: if you want to write to |
| 42 | * "C:\MyGame\MyConfigFiles\game.cfg", then you might set the write dir to |
| 43 | * "C:\MyGame" and then open "MyConfigFiles/game.cfg". This gives an |
| 44 | * abstraction across all platforms. Specifying a file in this way is termed |
| 45 | * "platform-independent notation" in this documentation. Specifying a |
| 46 | * a filename in a form such as "C:\mydir\myfile" or |
| 47 | * "MacOS hard drive:My Directory:My File" is termed "platform-dependent |
| 48 | * notation". The only time you use platform-dependent notation is when |
| 49 | * setting up your write directory and search path; after that, all file |
| 50 | * access into those directories are done with platform-independent notation. |
| 51 | * |
| 52 | * All files opened for writing are opened in relation to the write directory, |
| 53 | * which is the root of the writable filesystem. When opening a file for |
| 54 | * reading, PhysicsFS goes through the search path. This is NOT the |
| 55 | * same thing as the PATH environment variable. An application using |
| 56 | * PhysicsFS specifies directories to be searched which may be actual |
| 57 | * directories, or archive files that contain files and subdirectories of |
| 58 | * their own. See the end of these docs for currently supported archive |
| 59 | * formats. |
| 60 | * |
| 61 | * Once the search path is defined, you may open files for reading. If you've |
| 62 | * got the following search path defined (to use a win32 example again): |
| 63 | * |
| 64 | * - C:\\mygame |
| 65 | * - C:\\mygame\\myuserfiles |
| 66 | * - D:\\mygamescdromdatafiles |
| 67 | * - C:\\mygame\\installeddatafiles.zip |
| 68 | * |
| 69 | * Then a call to PHYSFS_openRead("textfiles/myfile.txt") (note the directory |
| 70 | * separator, lack of drive letter, and lack of dir separator at the start of |
| 71 | * the string; this is platform-independent notation) will check for |
| 72 | * C:\\mygame\\textfiles\\myfile.txt, then |
| 73 | * C:\\mygame\\myuserfiles\\textfiles\\myfile.txt, then |
| 74 | * D:\\mygamescdromdatafiles\\textfiles\\myfile.txt, then, finally, for |
| 75 | * textfiles\\myfile.txt inside of C:\\mygame\\installeddatafiles.zip. |
| 76 | * Remember that most archive types and platform filesystems store their |
| 77 | * filenames in a case-sensitive manner, so you should be careful to specify |
| 78 | * it correctly. |
| 79 | * |
| 80 | * Files opened through PhysicsFS may NOT contain "." or ".." or ":" as dir |
| 81 | * elements. Not only are these meaningless on MacOS Classic and/or Unix, |
| 82 | * they are a security hole. Also, symbolic links (which can be found in |
| 83 | * some archive types and directly in the filesystem on Unix platforms) are |
| 84 | * NOT followed until you call PHYSFS_permitSymbolicLinks(). That's left to |
| 85 | * your own discretion, as following a symlink can allow for access outside |
| 86 | * the write dir and search paths. For portability, there is no mechanism for |
| 87 | * creating new symlinks in PhysicsFS. |
| 88 | * |
| 89 | * The write dir is not included in the search path unless you specifically |
| 90 | * add it. While you CAN change the write dir as many times as you like, |
| 91 | * you should probably set it once and stick to it. Remember that your |
| 92 | * program will not have permission to write in every directory on Unix and |
| 93 | * NT systems. |
| 94 | * |
| 95 | * All files are opened in binary mode; there is no endline conversion for |
| 96 | * textfiles. Other than that, PhysicsFS has some convenience functions for |
| 97 | * platform-independence. There is a function to tell you the current |
| 98 | * platform's dir separator ("\\" on windows, "/" on Unix, ":" on MacOS), |
| 99 | * which is needed only to set up your search/write paths. There is a |
| 100 | * function to tell you what CD-ROM drives contain accessible discs, and a |
| 101 | * function to recommend a good search path, etc. |
| 102 | * |
| 103 | * A recommended order for the search path is the write dir, then the base dir, |
| 104 | * then the cdrom dir, then any archives discovered. Quake 3 does something |
| 105 | * like this, but moves the archives to the start of the search path. Build |
| 106 | * Engine games, like Duke Nukem 3D and Blood, place the archives last, and |
| 107 | * use the base dir for both searching and writing. There is a helper |
| 108 | * function (PHYSFS_setSaneConfig()) that puts together a basic configuration |
| 109 | * for you, based on a few parameters. Also see the comments on |
| 110 | * PHYSFS_getBaseDir(), and PHYSFS_getPrefDir() for info on what those |
| 111 | * are and how they can help you determine an optimal search path. |
| 112 | * |
| 113 | * PhysicsFS 2.0 adds the concept of "mounting" archives to arbitrary points |
| 114 | * in the search path. If a zipfile contains "maps/level.map" and you mount |
| 115 | * that archive at "mods/mymod", then you would have to open |
| 116 | * "mods/mymod/maps/level.map" to access the file, even though "mods/mymod" |
| 117 | * isn't actually specified in the .zip file. Unlike the Unix mentality of |
| 118 | * mounting a filesystem, "mods/mymod" doesn't actually have to exist when |
| 119 | * mounting the zipfile. It's a "virtual" directory. The mounting mechanism |
| 120 | * allows the developer to seperate archives in the tree and avoid trampling |
| 121 | * over files when added new archives, such as including mod support in a |
| 122 | * game...keeping external content on a tight leash in this manner can be of |
| 123 | * utmost importance to some applications. |
| 124 | * |
| 125 | * PhysicsFS is mostly thread safe. The errors returned by |
| 126 | * PHYSFS_getLastErrorCode() are unique by thread, and library-state-setting |
| 127 | * functions are mutex'd. For efficiency, individual file accesses are |
| 128 | * not locked, so you can not safely read/write/seek/close/etc the same |
| 129 | * file from two threads at the same time. Other race conditions are bugs |
| 130 | * that should be reported/patched. |
| 131 | * |
| 132 | * While you CAN use stdio/syscall file access in a program that has PHYSFS_* |
| 133 | * calls, doing so is not recommended, and you can not directly use system |
| 134 | * filehandles with PhysicsFS and vice versa (but as of PhysicsFS 2.1, you |
| 135 | * can wrap them in a PHYSFS_Io interface yourself if you wanted to). |
| 136 | * |
| 137 | * Note that archives need not be named as such: if you have a ZIP file and |
| 138 | * rename it with a .PKG extension, the file will still be recognized as a |
| 139 | * ZIP archive by PhysicsFS; the file's contents are used to determine its |
| 140 | * type where possible. |
| 141 | * |
| 142 | * Currently supported archive types: |
| 143 | * - .ZIP (pkZip/WinZip/Info-ZIP compatible) |
| 144 | * - .7Z (7zip archives) |
| 145 | * - .ISO (ISO9660 files, CD-ROM images) |
| 146 | * - .GRP (Build Engine groupfile archives) |
| 147 | * - .PAK (Quake I/II archive format) |
| 148 | * - .HOG (Descent I/II/III HOG file archives) |
| 149 | * - .MVL (Descent II movielib archives) |
| 150 | * - .WAD (DOOM engine archives) |
| 151 | * - .VDF (Gothic I/II engine archives) |
| 152 | * - .SLB (Independence War archives) |
| 153 | * |
| 154 | * String policy for PhysicsFS 2.0 and later: |
| 155 | * |
| 156 | * PhysicsFS 1.0 could only deal with null-terminated ASCII strings. All high |
| 157 | * ASCII chars resulted in undefined behaviour, and there was no Unicode |
| 158 | * support at all. PhysicsFS 2.0 supports Unicode without breaking binary |
| 159 | * compatibility with the 1.0 API by using UTF-8 encoding of all strings |
| 160 | * passed in and out of the library. |
| 161 | * |
| 162 | * All strings passed through PhysicsFS are in null-terminated UTF-8 format. |
| 163 | * This means that if all you care about is English (ASCII characters <= 127) |
| 164 | * then you just use regular C strings. If you care about Unicode (and you |
| 165 | * should!) then you need to figure out what your platform wants, needs, and |
| 166 | * offers. If you are on Windows before Win2000 and build with Unicode |
| 167 | * support, your TCHAR strings are two bytes per character (this is called |
| 168 | * "UCS-2 encoding"). Any modern Windows uses UTF-16, which is two bytes |
| 169 | * per character for most characters, but some characters are four. You |
| 170 | * should convert them to UTF-8 before handing them to PhysicsFS with |
| 171 | * PHYSFS_utf8FromUtf16(), which handles both UTF-16 and UCS-2. If you're |
| 172 | * using Unix or Mac OS X, your wchar_t strings are four bytes per character |
| 173 | * ("UCS-4 encoding", sometimes called "UTF-32"). Use PHYSFS_utf8FromUcs4(). |
| 174 | * Mac OS X can give you UTF-8 directly from a CFString or NSString, and many |
| 175 | * Unixes generally give you C strings in UTF-8 format everywhere. If you |
| 176 | * have a single-byte high ASCII charset, like so-many European "codepages" |
| 177 | * you may be out of luck. We'll convert from "Latin1" to UTF-8 only, and |
| 178 | * never back to Latin1. If you're above ASCII 127, all bets are off: move |
| 179 | * to Unicode or use your platform's facilities. Passing a C string with |
| 180 | * high-ASCII data that isn't UTF-8 encoded will NOT do what you expect! |
| 181 | * |
| 182 | * Naturally, there's also PHYSFS_utf8ToUcs2(), PHYSFS_utf8ToUtf16(), and |
| 183 | * PHYSFS_utf8ToUcs4() to get data back into a format you like. Behind the |
| 184 | * scenes, PhysicsFS will use Unicode where possible: the UTF-8 strings on |
| 185 | * Windows will be converted and used with the multibyte Windows APIs, for |
| 186 | * example. |
| 187 | * |
| 188 | * PhysicsFS offers basic encoding conversion support, but not a whole string |
| 189 | * library. Get your stuff into whatever format you can work with. |
| 190 | * |
| 191 | * Most platforms supported by PhysicsFS 2.1 and later fully support Unicode. |
| 192 | * Some older platforms have been dropped (Windows 95, Mac OS 9). Some, like |
| 193 | * OS/2, might be able to convert to a local codepage or will just fail to |
| 194 | * open/create the file. Modern OSes (macOS, Linux, Windows, etc) should all |
| 195 | * be fine. |
| 196 | * |
| 197 | * Many game-specific archivers are seriously unprepared for Unicode (the |
| 198 | * Descent HOG/MVL and Build Engine GRP archivers, for example, only offer a |
| 199 | * DOS 8.3 filename, for example). Nothing can be done for these, but they |
| 200 | * tend to be legacy formats for existing content that was all ASCII (and |
| 201 | * thus, valid UTF-8) anyhow. Other formats, like .ZIP, don't explicitly |
| 202 | * offer Unicode support, but unofficially expect filenames to be UTF-8 |
| 203 | * encoded, and thus Just Work. Most everything does the right thing without |
| 204 | * bothering you, but it's good to be aware of these nuances in case they |
| 205 | * don't. |
| 206 | * |
| 207 | * |
| 208 | * Other stuff: |
| 209 | * |
| 210 | * Please see the file LICENSE.txt in the source's root directory for |
| 211 | * licensing and redistribution rights. |
| 212 | * |
| 213 | * Please see the file CREDITS.txt in the source's "docs" directory for |
| 214 | * a more or less complete list of who's responsible for this. |
| 215 | * |
| 216 | * \author Ryan C. Gordon. |
| 217 | */ |
| 218 | |
| 219 | #ifndef _INCLUDE_PHYSFS_H_ |
| 220 | #define _INCLUDE_PHYSFS_H_ |
| 221 | |
| 222 | #ifdef __cplusplus |
| 223 | extern "C" { |
| 224 | #endif |
| 225 | |
| 226 | #if defined(PHYSFS_DECL) |
| 227 | /* do nothing. */ |
| 228 | #elif defined(PHYSFS_STATIC) |
| 229 | #define PHYSFS_DECL /**/ |
| 230 | #elif defined(_WIN32) || defined(__OS2__) |
| 231 | #define PHYSFS_DECL __declspec(dllexport) |
| 232 | #elif defined(__SUNPRO_C) |
| 233 | #define PHYSFS_DECL __global |
| 234 | #elif ((__GNUC__ >= 3) && (!defined(__EMX__)) && (!defined(sun))) |
| 235 | #define PHYSFS_DECL __attribute__((visibility("default"))) |
| 236 | #else |
| 237 | #define PHYSFS_DECL |
| 238 | #endif |
| 239 | |
| 240 | #if defined(PHYSFS_DEPRECATED) |
| 241 | /* do nothing. */ |
| 242 | #elif (__GNUC__ >= 4) /* technically, this arrived in gcc 3.1, but oh well. */ |
| 243 | #define PHYSFS_DEPRECATED __attribute__((deprecated)) |
| 244 | #else |
| 245 | #define PHYSFS_DEPRECATED |
| 246 | #endif |
| 247 | |
| 248 | #if 0 /* !!! FIXME: look into this later. */ |
| 249 | #if defined(PHYSFS_CALL) |
| 250 | /* do nothing. */ |
| 251 | #elif defined(__WIN32__) && !defined(__GNUC__) |
| 252 | #define PHYSFS_CALL __cdecl |
| 253 | #elif defined(__OS2__) || defined(OS2) /* should work across all compilers. */ |
| 254 | #define PHYSFS_CALL _System |
| 255 | #else |
| 256 | #define PHYSFS_CALL |
| 257 | #endif |
| 258 | #endif |
| 259 | |
| 260 | /** |
| 261 | * \typedef PHYSFS_uint8 |
| 262 | * \brief An unsigned, 8-bit integer type. |
| 263 | */ |
| 264 | typedef unsigned char PHYSFS_uint8; |
| 265 | |
| 266 | /** |
| 267 | * \typedef PHYSFS_sint8 |
| 268 | * \brief A signed, 8-bit integer type. |
| 269 | */ |
| 270 | typedef signed char PHYSFS_sint8; |
| 271 | |
| 272 | /** |
| 273 | * \typedef PHYSFS_uint16 |
| 274 | * \brief An unsigned, 16-bit integer type. |
| 275 | */ |
| 276 | typedef unsigned short PHYSFS_uint16; |
| 277 | |
| 278 | /** |
| 279 | * \typedef PHYSFS_sint16 |
| 280 | * \brief A signed, 16-bit integer type. |
| 281 | */ |
| 282 | typedef signed short PHYSFS_sint16; |
| 283 | |
| 284 | /** |
| 285 | * \typedef PHYSFS_uint32 |
| 286 | * \brief An unsigned, 32-bit integer type. |
| 287 | */ |
| 288 | typedef unsigned int PHYSFS_uint32; |
| 289 | |
| 290 | /** |
| 291 | * \typedef PHYSFS_sint32 |
| 292 | * \brief A signed, 32-bit integer type. |
| 293 | */ |
| 294 | typedef signed int PHYSFS_sint32; |
| 295 | |
| 296 | /** |
| 297 | * \typedef PHYSFS_uint64 |
| 298 | * \brief An unsigned, 64-bit integer type. |
| 299 | * \warning on platforms without any sort of 64-bit datatype, this is |
| 300 | * equivalent to PHYSFS_uint32! |
| 301 | */ |
| 302 | |
| 303 | /** |
| 304 | * \typedef PHYSFS_sint64 |
| 305 | * \brief A signed, 64-bit integer type. |
| 306 | * \warning on platforms without any sort of 64-bit datatype, this is |
| 307 | * equivalent to PHYSFS_sint32! |
| 308 | */ |
| 309 | |
| 310 | |
| 311 | #if (defined PHYSFS_NO_64BIT_SUPPORT) /* oh well. */ |
| 312 | typedef PHYSFS_uint32 PHYSFS_uint64; |
| 313 | typedef PHYSFS_sint32 PHYSFS_sint64; |
| 314 | #elif (defined _MSC_VER) |
| 315 | typedef signed __int64 PHYSFS_sint64; |
| 316 | typedef unsigned __int64 PHYSFS_uint64; |
| 317 | #else |
| 318 | typedef unsigned long long PHYSFS_uint64; |
| 319 | typedef signed long long PHYSFS_sint64; |
| 320 | #endif |
| 321 | |
| 322 | |
| 323 | #ifndef DOXYGEN_SHOULD_IGNORE_THIS |
| 324 | /* Make sure the types really have the right sizes */ |
| 325 | #define PHYSFS_COMPILE_TIME_ASSERT(name, x) \ |
| 326 | typedef int PHYSFS_compile_time_assert_##name[(x) * 2 - 1] |
| 327 | |
| 328 | PHYSFS_COMPILE_TIME_ASSERT(uint8IsOneByte, sizeof(PHYSFS_uint8) == 1); |
| 329 | PHYSFS_COMPILE_TIME_ASSERT(sint8IsOneByte, sizeof(PHYSFS_sint8) == 1); |
| 330 | PHYSFS_COMPILE_TIME_ASSERT(uint16IsTwoBytes, sizeof(PHYSFS_uint16) == 2); |
| 331 | PHYSFS_COMPILE_TIME_ASSERT(sint16IsTwoBytes, sizeof(PHYSFS_sint16) == 2); |
| 332 | PHYSFS_COMPILE_TIME_ASSERT(uint32IsFourBytes, sizeof(PHYSFS_uint32) == 4); |
| 333 | PHYSFS_COMPILE_TIME_ASSERT(sint32IsFourBytes, sizeof(PHYSFS_sint32) == 4); |
| 334 | |
| 335 | #ifndef PHYSFS_NO_64BIT_SUPPORT |
| 336 | PHYSFS_COMPILE_TIME_ASSERT(uint64IsEightBytes, sizeof(PHYSFS_uint64) == 8); |
| 337 | PHYSFS_COMPILE_TIME_ASSERT(sint64IsEightBytes, sizeof(PHYSFS_sint64) == 8); |
| 338 | #endif |
| 339 | |
| 340 | #undef PHYSFS_COMPILE_TIME_ASSERT |
| 341 | |
| 342 | #endif /* DOXYGEN_SHOULD_IGNORE_THIS */ |
| 343 | |
| 344 | |
| 345 | /** |
| 346 | * \struct PHYSFS_File |
| 347 | * \brief A PhysicsFS file handle. |
| 348 | * |
| 349 | * You get a pointer to one of these when you open a file for reading, |
| 350 | * writing, or appending via PhysicsFS. |
| 351 | * |
| 352 | * As you can see from the lack of meaningful fields, you should treat this |
| 353 | * as opaque data. Don't try to manipulate the file handle, just pass the |
| 354 | * pointer you got, unmolested, to various PhysicsFS APIs. |
| 355 | * |
| 356 | * \sa PHYSFS_openRead |
| 357 | * \sa PHYSFS_openWrite |
| 358 | * \sa PHYSFS_openAppend |
| 359 | * \sa PHYSFS_close |
| 360 | * \sa PHYSFS_read |
| 361 | * \sa PHYSFS_write |
| 362 | * \sa PHYSFS_seek |
| 363 | * \sa PHYSFS_tell |
| 364 | * \sa PHYSFS_eof |
| 365 | * \sa PHYSFS_setBuffer |
| 366 | * \sa PHYSFS_flush |
| 367 | */ |
| 368 | typedef struct PHYSFS_File |
| 369 | { |
| 370 | void *opaque; /**< That's all you get. Don't touch. */ |
| 371 | } PHYSFS_File; |
| 372 | |
| 373 | |
| 374 | /** |
| 375 | * \def PHYSFS_file |
| 376 | * \brief 1.0 API compatibility define. |
| 377 | * |
| 378 | * PHYSFS_file is identical to PHYSFS_File. This #define is here for backwards |
| 379 | * compatibility with the 1.0 API, which had an inconsistent capitalization |
| 380 | * convention in this case. New code should use PHYSFS_File, as this #define |
| 381 | * may go away someday. |
| 382 | * |
| 383 | * \sa PHYSFS_File |
| 384 | */ |
| 385 | #define PHYSFS_file PHYSFS_File |
| 386 | |
| 387 | |
| 388 | /** |
| 389 | * \struct PHYSFS_ArchiveInfo |
| 390 | * \brief Information on various PhysicsFS-supported archives. |
| 391 | * |
| 392 | * This structure gives you details on what sort of archives are supported |
| 393 | * by this implementation of PhysicsFS. Archives tend to be things like |
| 394 | * ZIP files and such. |
| 395 | * |
| 396 | * \warning Not all binaries are created equal! PhysicsFS can be built with |
| 397 | * or without support for various archives. You can check with |
| 398 | * PHYSFS_supportedArchiveTypes() to see if your archive type is |
| 399 | * supported. |
| 400 | * |
| 401 | * \sa PHYSFS_supportedArchiveTypes |
| 402 | * \sa PHYSFS_registerArchiver |
| 403 | * \sa PHYSFS_deregisterArchiver |
| 404 | */ |
| 405 | typedef struct PHYSFS_ArchiveInfo |
| 406 | { |
| 407 | const char *extension; /**< Archive file extension: "ZIP", for example. */ |
| 408 | const char *description; /**< Human-readable archive description. */ |
| 409 | const char *author; /**< Person who did support for this archive. */ |
| 410 | const char *url; /**< URL related to this archive */ |
| 411 | int supportsSymlinks; /**< non-zero if archive offers symbolic links. */ |
| 412 | } PHYSFS_ArchiveInfo; |
| 413 | |
| 414 | |
| 415 | /** |
| 416 | * \struct PHYSFS_Version |
| 417 | * \brief Information the version of PhysicsFS in use. |
| 418 | * |
| 419 | * Represents the library's version as three levels: major revision |
| 420 | * (increments with massive changes, additions, and enhancements), |
| 421 | * minor revision (increments with backwards-compatible changes to the |
| 422 | * major revision), and patchlevel (increments with fixes to the minor |
| 423 | * revision). |
| 424 | * |
| 425 | * \sa PHYSFS_VERSION |
| 426 | * \sa PHYSFS_getLinkedVersion |
| 427 | */ |
| 428 | typedef struct PHYSFS_Version |
| 429 | { |
| 430 | PHYSFS_uint8 major; /**< major revision */ |
| 431 | PHYSFS_uint8 minor; /**< minor revision */ |
| 432 | PHYSFS_uint8 patch; /**< patchlevel */ |
| 433 | } PHYSFS_Version; |
| 434 | |
| 435 | |
| 436 | #ifndef DOXYGEN_SHOULD_IGNORE_THIS |
| 437 | #define PHYSFS_VER_MAJOR 3 |
| 438 | #define PHYSFS_VER_MINOR 2 |
| 439 | #define PHYSFS_VER_PATCH 0 |
| 440 | #endif /* DOXYGEN_SHOULD_IGNORE_THIS */ |
| 441 | |
| 442 | |
| 443 | /* PhysicsFS state stuff ... */ |
| 444 | |
| 445 | /** |
| 446 | * \def PHYSFS_VERSION(x) |
| 447 | * \brief Macro to determine PhysicsFS version program was compiled against. |
| 448 | * |
| 449 | * This macro fills in a PHYSFS_Version structure with the version of the |
| 450 | * library you compiled against. This is determined by what header the |
| 451 | * compiler uses. Note that if you dynamically linked the library, you might |
| 452 | * have a slightly newer or older version at runtime. That version can be |
| 453 | * determined with PHYSFS_getLinkedVersion(), which, unlike PHYSFS_VERSION, |
| 454 | * is not a macro. |
| 455 | * |
| 456 | * \param x A pointer to a PHYSFS_Version struct to initialize. |
| 457 | * |
| 458 | * \sa PHYSFS_Version |
| 459 | * \sa PHYSFS_getLinkedVersion |
| 460 | */ |
| 461 | #define PHYSFS_VERSION(x) \ |
| 462 | { \ |
| 463 | (x)->major = PHYSFS_VER_MAJOR; \ |
| 464 | (x)->minor = PHYSFS_VER_MINOR; \ |
| 465 | (x)->patch = PHYSFS_VER_PATCH; \ |
| 466 | } |
| 467 | |
| 468 | |
| 469 | /** |
| 470 | * \fn void PHYSFS_getLinkedVersion(PHYSFS_Version *ver) |
| 471 | * \brief Get the version of PhysicsFS that is linked against your program. |
| 472 | * |
| 473 | * If you are using a shared library (DLL) version of PhysFS, then it is |
| 474 | * possible that it will be different than the version you compiled against. |
| 475 | * |
| 476 | * This is a real function; the macro PHYSFS_VERSION tells you what version |
| 477 | * of PhysFS you compiled against: |
| 478 | * |
| 479 | * \code |
| 480 | * PHYSFS_Version compiled; |
| 481 | * PHYSFS_Version linked; |
| 482 | * |
| 483 | * PHYSFS_VERSION(&compiled); |
| 484 | * PHYSFS_getLinkedVersion(&linked); |
| 485 | * printf("We compiled against PhysFS version %d.%d.%d ...\n", |
| 486 | * compiled.major, compiled.minor, compiled.patch); |
| 487 | * printf("But we linked against PhysFS version %d.%d.%d.\n", |
| 488 | * linked.major, linked.minor, linked.patch); |
| 489 | * \endcode |
| 490 | * |
| 491 | * This function may be called safely at any time, even before PHYSFS_init(). |
| 492 | * |
| 493 | * \sa PHYSFS_VERSION |
| 494 | */ |
| 495 | PHYSFS_DECL void PHYSFS_getLinkedVersion(PHYSFS_Version *ver); |
| 496 | |
| 497 | |
| 498 | #ifdef __ANDROID__ |
| 499 | typedef struct PHYSFS_AndroidInit |
| 500 | { |
| 501 | void *jnienv; |
| 502 | void *context; |
| 503 | } PHYSFS_AndroidInit; |
| 504 | #endif |
| 505 | |
| 506 | /** |
| 507 | * \fn int PHYSFS_init(const char *argv0) |
| 508 | * \brief Initialize the PhysicsFS library. |
| 509 | * |
| 510 | * This must be called before any other PhysicsFS function. |
| 511 | * |
| 512 | * This should be called prior to any attempts to change your process's |
| 513 | * current working directory. |
| 514 | * |
| 515 | * \warning On Android, argv0 should be a non-NULL pointer to a |
| 516 | * PHYSFS_AndroidInit struct. This struct must hold a valid JNIEnv * |
| 517 | * and a JNI jobject of a Context (either the application context or |
| 518 | * the current Activity is fine). Both are cast to a void * so we |
| 519 | * don't need jni.h included wherever physfs.h is. PhysicsFS |
| 520 | * uses these objects to query some system details. PhysicsFS does |
| 521 | * not hold a reference to the JNIEnv or Context past the call to |
| 522 | * PHYSFS_init(). If you pass a NULL here, PHYSFS_init can still |
| 523 | * succeed, but PHYSFS_getBaseDir() and PHYSFS_getPrefDir() will be |
| 524 | * incorrect. |
| 525 | * |
| 526 | * \param argv0 the argv[0] string passed to your program's mainline. |
| 527 | * This may be NULL on most platforms (such as ones without a |
| 528 | * standard main() function), but you should always try to pass |
| 529 | * something in here. Many Unix-like systems _need_ to pass argv[0] |
| 530 | * from main() in here. See warning about Android, too! |
| 531 | * \return nonzero on success, zero on error. Specifics of the error can be |
| 532 | * gleaned from PHYSFS_getLastError(). |
| 533 | * |
| 534 | * \sa PHYSFS_deinit |
| 535 | * \sa PHYSFS_isInit |
| 536 | */ |
| 537 | PHYSFS_DECL int PHYSFS_init(const char *argv0); |
| 538 | |
| 539 | |
| 540 | /** |
| 541 | * \fn int PHYSFS_deinit(void) |
| 542 | * \brief Deinitialize the PhysicsFS library. |
| 543 | * |
| 544 | * This closes any files opened via PhysicsFS, blanks the search/write paths, |
| 545 | * frees memory, and invalidates all of your file handles. |
| 546 | * |
| 547 | * Note that this call can FAIL if there's a file open for writing that |
| 548 | * refuses to close (for example, the underlying operating system was |
| 549 | * buffering writes to network filesystem, and the fileserver has crashed, |
| 550 | * or a hard drive has failed, etc). It is usually best to close all write |
| 551 | * handles yourself before calling this function, so that you can gracefully |
| 552 | * handle a specific failure. |
| 553 | * |
| 554 | * Once successfully deinitialized, PHYSFS_init() can be called again to |
| 555 | * restart the subsystem. All default API states are restored at this |
| 556 | * point, with the exception of any custom allocator you might have |
| 557 | * specified, which survives between initializations. |
| 558 | * |
| 559 | * \return nonzero on success, zero on error. Specifics of the error can be |
| 560 | * gleaned from PHYSFS_getLastError(). If failure, state of PhysFS is |
| 561 | * undefined, and probably badly screwed up. |
| 562 | * |
| 563 | * \sa PHYSFS_init |
| 564 | * \sa PHYSFS_isInit |
| 565 | */ |
| 566 | PHYSFS_DECL int PHYSFS_deinit(void); |
| 567 | |
| 568 | |
| 569 | /** |
| 570 | * \fn const PHYSFS_ArchiveInfo **PHYSFS_supportedArchiveTypes(void) |
| 571 | * \brief Get a list of supported archive types. |
| 572 | * |
| 573 | * Get a list of archive types supported by this implementation of PhysicFS. |
| 574 | * These are the file formats usable for search path entries. This is for |
| 575 | * informational purposes only. Note that the extension listed is merely |
| 576 | * convention: if we list "ZIP", you can open a PkZip-compatible archive |
| 577 | * with an extension of "XYZ", if you like. |
| 578 | * |
| 579 | * The returned value is an array of pointers to PHYSFS_ArchiveInfo structures, |
| 580 | * with a NULL entry to signify the end of the list: |
| 581 | * |
| 582 | * \code |
| 583 | * PHYSFS_ArchiveInfo **i; |
| 584 | * |
| 585 | * for (i = PHYSFS_supportedArchiveTypes(); *i != NULL; i++) |
| 586 | * { |
| 587 | * printf("Supported archive: [%s], which is [%s].\n", |
| 588 | * (*i)->extension, (*i)->description); |
| 589 | * } |
| 590 | * \endcode |
| 591 | * |
| 592 | * The return values are pointers to internal memory, and should |
| 593 | * be considered READ ONLY, and never freed. The returned values are |
| 594 | * valid until the next call to PHYSFS_deinit(), PHYSFS_registerArchiver(), |
| 595 | * or PHYSFS_deregisterArchiver(). |
| 596 | * |
| 597 | * \return READ ONLY Null-terminated array of READ ONLY structures. |
| 598 | * |
| 599 | * \sa PHYSFS_registerArchiver |
| 600 | * \sa PHYSFS_deregisterArchiver |
| 601 | */ |
| 602 | PHYSFS_DECL const PHYSFS_ArchiveInfo **PHYSFS_supportedArchiveTypes(void); |
| 603 | |
| 604 | |
| 605 | /** |
| 606 | * \fn void PHYSFS_freeList(void *listVar) |
| 607 | * \brief Deallocate resources of lists returned by PhysicsFS. |
| 608 | * |
| 609 | * Certain PhysicsFS functions return lists of information that are |
| 610 | * dynamically allocated. Use this function to free those resources. |
| 611 | * |
| 612 | * It is safe to pass a NULL here, but doing so will cause a crash in versions |
| 613 | * before PhysicsFS 2.1.0. |
| 614 | * |
| 615 | * \param listVar List of information specified as freeable by this function. |
| 616 | * Passing NULL is safe; it is a valid no-op. |
| 617 | * |
| 618 | * \sa PHYSFS_getCdRomDirs |
| 619 | * \sa PHYSFS_enumerateFiles |
| 620 | * \sa PHYSFS_getSearchPath |
| 621 | */ |
| 622 | PHYSFS_DECL void PHYSFS_freeList(void *listVar); |
| 623 | |
| 624 | |
| 625 | /** |
| 626 | * \fn const char *PHYSFS_getLastError(void) |
| 627 | * \brief Get human-readable error information. |
| 628 | * |
| 629 | * \deprecated Use PHYSFS_getLastErrorCode() and PHYSFS_getErrorByCode() instead. |
| 630 | * |
| 631 | * \warning As of PhysicsFS 2.1, this function has been nerfed. |
| 632 | * Before PhysicsFS 2.1, this function was the only way to get |
| 633 | * error details beyond a given function's basic return value. |
| 634 | * This was meant to be a human-readable string in one of several |
| 635 | * languages, and was not useful for application parsing. This was |
| 636 | * a problem, because the developer and not the user chose the |
| 637 | * language at compile time, and the PhysicsFS maintainers had |
| 638 | * to (poorly) maintain a significant amount of localization work. |
| 639 | * The app couldn't parse the strings, even if they counted on a |
| 640 | * specific language, since some were dynamically generated. |
| 641 | * In 2.1 and later, this always returns a static string in |
| 642 | * English; you may use it as a key string for your own |
| 643 | * localizations if you like, as we'll promise not to change |
| 644 | * existing error strings. Also, if your application wants to |
| 645 | * look at specific errors, we now offer a better option: |
| 646 | * use PHYSFS_getLastErrorCode() instead. |
| 647 | * |
| 648 | * Get the last PhysicsFS error message as a human-readable, null-terminated |
| 649 | * string. This will return NULL if there's been no error since the last call |
| 650 | * to this function. The pointer returned by this call points to an internal |
| 651 | * buffer. Each thread has a unique error state associated with it, but each |
| 652 | * time a new error message is set, it will overwrite the previous one |
| 653 | * associated with that thread. It is safe to call this function at anytime, |
| 654 | * even before PHYSFS_init(). |
| 655 | * |
| 656 | * PHYSFS_getLastError() and PHYSFS_getLastErrorCode() both reset the same |
| 657 | * thread-specific error state. Calling one will wipe out the other's |
| 658 | * data. If you need both, call PHYSFS_getLastErrorCode(), then pass that |
| 659 | * value to PHYSFS_getErrorByCode(). |
| 660 | * |
| 661 | * As of PhysicsFS 2.1, this function only presents text in the English |
| 662 | * language, but the strings are static, so you can use them as keys into |
| 663 | * your own localization dictionary. These strings are meant to be passed on |
| 664 | * directly to the user. |
| 665 | * |
| 666 | * Generally, applications should only concern themselves with whether a |
| 667 | * given function failed; however, if your code require more specifics, you |
| 668 | * should use PHYSFS_getLastErrorCode() instead of this function. |
| 669 | * |
| 670 | * \return READ ONLY string of last error message. |
| 671 | * |
| 672 | * \sa PHYSFS_getLastErrorCode |
| 673 | * \sa PHYSFS_getErrorByCode |
| 674 | */ |
| 675 | PHYSFS_DECL const char *PHYSFS_getLastError(void) PHYSFS_DEPRECATED; |
| 676 | |
| 677 | |
| 678 | /** |
| 679 | * \fn const char *PHYSFS_getDirSeparator(void) |
| 680 | * \brief Get platform-dependent dir separator string. |
| 681 | * |
| 682 | * This returns "\\" on win32, "/" on Unix, and ":" on MacOS. It may be more |
| 683 | * than one character, depending on the platform, and your code should take |
| 684 | * that into account. Note that this is only useful for setting up the |
| 685 | * search/write paths, since access into those dirs always use '/' |
| 686 | * (platform-independent notation) to separate directories. This is also |
| 687 | * handy for getting platform-independent access when using stdio calls. |
| 688 | * |
| 689 | * \return READ ONLY null-terminated string of platform's dir separator. |
| 690 | */ |
| 691 | PHYSFS_DECL const char *PHYSFS_getDirSeparator(void); |
| 692 | |
| 693 | |
| 694 | /** |
| 695 | * \fn void PHYSFS_permitSymbolicLinks(int allow) |
| 696 | * \brief Enable or disable following of symbolic links. |
| 697 | * |
| 698 | * Some physical filesystems and archives contain files that are just pointers |
| 699 | * to other files. On the physical filesystem, opening such a link will |
| 700 | * (transparently) open the file that is pointed to. |
| 701 | * |
| 702 | * By default, PhysicsFS will check if a file is really a symlink during open |
| 703 | * calls and fail if it is. Otherwise, the link could take you outside the |
| 704 | * write and search paths, and compromise security. |
| 705 | * |
| 706 | * If you want to take that risk, call this function with a non-zero parameter. |
| 707 | * Note that this is more for sandboxing a program's scripting language, in |
| 708 | * case untrusted scripts try to compromise the system. Generally speaking, |
| 709 | * a user could very well have a legitimate reason to set up a symlink, so |
| 710 | * unless you feel there's a specific danger in allowing them, you should |
| 711 | * permit them. |
| 712 | * |
| 713 | * Symlinks are only explicitly checked when dealing with filenames |
| 714 | * in platform-independent notation. That is, when setting up your |
| 715 | * search and write paths, etc, symlinks are never checked for. |
| 716 | * |
| 717 | * Please note that PHYSFS_stat() will always check the path specified; if |
| 718 | * that path is a symlink, it will not be followed in any case. If symlinks |
| 719 | * aren't permitted through this function, PHYSFS_stat() ignores them, and |
| 720 | * would treat the query as if the path didn't exist at all. |
| 721 | * |
| 722 | * Symbolic link permission can be enabled or disabled at any time after |
| 723 | * you've called PHYSFS_init(), and is disabled by default. |
| 724 | * |
| 725 | * \param allow nonzero to permit symlinks, zero to deny linking. |
| 726 | * |
| 727 | * \sa PHYSFS_symbolicLinksPermitted |
| 728 | */ |
| 729 | PHYSFS_DECL void PHYSFS_permitSymbolicLinks(int allow); |
| 730 | |
| 731 | |
| 732 | /** |
| 733 | * \fn char **PHYSFS_getCdRomDirs(void) |
| 734 | * \brief Get an array of paths to available CD-ROM drives. |
| 735 | * |
| 736 | * The dirs returned are platform-dependent ("D:\" on Win32, "/cdrom" or |
| 737 | * whatnot on Unix). Dirs are only returned if there is a disc ready and |
| 738 | * accessible in the drive. So if you've got two drives (D: and E:), and only |
| 739 | * E: has a disc in it, then that's all you get. If the user inserts a disc |
| 740 | * in D: and you call this function again, you get both drives. If, on a |
| 741 | * Unix box, the user unmounts a disc and remounts it elsewhere, the next |
| 742 | * call to this function will reflect that change. |
| 743 | * |
| 744 | * This function refers to "CD-ROM" media, but it really means "inserted disc |
| 745 | * media," such as DVD-ROM, HD-DVD, CDRW, and Blu-Ray discs. It looks for |
| 746 | * filesystems, and as such won't report an audio CD, unless there's a |
| 747 | * mounted filesystem track on it. |
| 748 | * |
| 749 | * The returned value is an array of strings, with a NULL entry to signify the |
| 750 | * end of the list: |
| 751 | * |
| 752 | * \code |
| 753 | * char **cds = PHYSFS_getCdRomDirs(); |
| 754 | * char **i; |
| 755 | * |
| 756 | * for (i = cds; *i != NULL; i++) |
| 757 | * printf("cdrom dir [%s] is available.\n", *i); |
| 758 | * |
| 759 | * PHYSFS_freeList(cds); |
| 760 | * \endcode |
| 761 | * |
| 762 | * This call may block while drives spin up. Be forewarned. |
| 763 | * |
| 764 | * When you are done with the returned information, you may dispose of the |
| 765 | * resources by calling PHYSFS_freeList() with the returned pointer. |
| 766 | * |
| 767 | * \return Null-terminated array of null-terminated strings. |
| 768 | * |
| 769 | * \sa PHYSFS_getCdRomDirsCallback |
| 770 | */ |
| 771 | PHYSFS_DECL char **PHYSFS_getCdRomDirs(void); |
| 772 | |
| 773 | |
| 774 | /** |
| 775 | * \fn const char *PHYSFS_getBaseDir(void) |
| 776 | * \brief Get the path where the application resides. |
| 777 | * |
| 778 | * Helper function. |
| 779 | * |
| 780 | * Get the "base dir". This is the directory where the application was run |
| 781 | * from, which is probably the installation directory, and may or may not |
| 782 | * be the process's current working directory. |
| 783 | * |
| 784 | * You should probably use the base dir in your search path. |
| 785 | * |
| 786 | * \warning On most platforms, this is a directory; on Android, this gives |
| 787 | * you the path to the app's package (APK) file. As APK files are |
| 788 | * just .zip files, you can mount them in PhysicsFS like regular |
| 789 | * directories. You'll probably want to call |
| 790 | * PHYSFS_setRoot(basedir, "/assets") after mounting to make your |
| 791 | * app's actual data available directly without all the Android |
| 792 | * metadata and directory offset. Note that if you passed a NULL to |
| 793 | * PHYSFS_init(), you will not get the APK file here. |
| 794 | * |
| 795 | * \return READ ONLY string of base dir in platform-dependent notation. |
| 796 | * |
| 797 | * \sa PHYSFS_getPrefDir |
| 798 | */ |
| 799 | PHYSFS_DECL const char *PHYSFS_getBaseDir(void); |
| 800 | |
| 801 | |
| 802 | /** |
| 803 | * \fn const char *PHYSFS_getUserDir(void) |
| 804 | * \brief Get the path where user's home directory resides. |
| 805 | * |
| 806 | * \deprecated As of PhysicsFS 2.1, you probably want PHYSFS_getPrefDir(). |
| 807 | * |
| 808 | * Helper function. |
| 809 | * |
| 810 | * Get the "user dir". This is meant to be a suggestion of where a specific |
| 811 | * user of the system can store files. On Unix, this is her home directory. |
| 812 | * On systems with no concept of multiple home directories (MacOS, win95), |
| 813 | * this will default to something like "C:\mybasedir\users\username" |
| 814 | * where "username" will either be the login name, or "default" if the |
| 815 | * platform doesn't support multiple users, either. |
| 816 | * |
| 817 | * \return READ ONLY string of user dir in platform-dependent notation. |
| 818 | * |
| 819 | * \sa PHYSFS_getBaseDir |
| 820 | * \sa PHYSFS_getPrefDir |
| 821 | */ |
| 822 | PHYSFS_DECL const char *PHYSFS_getUserDir(void) PHYSFS_DEPRECATED; |
| 823 | |
| 824 | |
| 825 | /** |
| 826 | * \fn const char *PHYSFS_getWriteDir(void) |
| 827 | * \brief Get path where PhysicsFS will allow file writing. |
| 828 | * |
| 829 | * Get the current write dir. The default write dir is NULL. |
| 830 | * |
| 831 | * \return READ ONLY string of write dir in platform-dependent notation, |
| 832 | * OR NULL IF NO WRITE PATH IS CURRENTLY SET. |
| 833 | * |
| 834 | * \sa PHYSFS_setWriteDir |
| 835 | */ |
| 836 | PHYSFS_DECL const char *PHYSFS_getWriteDir(void); |
| 837 | |
| 838 | |
| 839 | /** |
| 840 | * \fn int PHYSFS_setWriteDir(const char *newDir) |
| 841 | * \brief Tell PhysicsFS where it may write files. |
| 842 | * |
| 843 | * Set a new write dir. This will override the previous setting. |
| 844 | * |
| 845 | * This call will fail (and fail to change the write dir) if the current |
| 846 | * write dir still has files open in it. |
| 847 | * |
| 848 | * \param newDir The new directory to be the root of the write dir, |
| 849 | * specified in platform-dependent notation. Setting to NULL |
| 850 | * disables the write dir, so no files can be opened for |
| 851 | * writing via PhysicsFS. |
| 852 | * \return non-zero on success, zero on failure. All attempts to open a file |
| 853 | * for writing via PhysicsFS will fail until this call succeeds. |
| 854 | * Use PHYSFS_getLastErrorCode() to obtain the specific error. |
| 855 | * |
| 856 | * \sa PHYSFS_getWriteDir |
| 857 | */ |
| 858 | PHYSFS_DECL int PHYSFS_setWriteDir(const char *newDir); |
| 859 | |
| 860 | |
| 861 | /** |
| 862 | * \fn int PHYSFS_addToSearchPath(const char *newDir, int appendToPath) |
| 863 | * \brief Add an archive or directory to the search path. |
| 864 | * |
| 865 | * \deprecated As of PhysicsFS 2.0, use PHYSFS_mount() instead. This |
| 866 | * function just wraps it anyhow. |
| 867 | * |
| 868 | * This function is equivalent to: |
| 869 | * |
| 870 | * \code |
| 871 | * PHYSFS_mount(newDir, NULL, appendToPath); |
| 872 | * \endcode |
| 873 | * |
| 874 | * You must use this and not PHYSFS_mount if binary compatibility with |
| 875 | * PhysicsFS 1.0 is important (which it may not be for many people). |
| 876 | * |
| 877 | * \sa PHYSFS_mount |
| 878 | * \sa PHYSFS_removeFromSearchPath |
| 879 | * \sa PHYSFS_getSearchPath |
| 880 | */ |
| 881 | PHYSFS_DECL int PHYSFS_addToSearchPath(const char *newDir, int appendToPath) |
| 882 | PHYSFS_DEPRECATED; |
| 883 | |
| 884 | /** |
| 885 | * \fn int PHYSFS_removeFromSearchPath(const char *oldDir) |
| 886 | * \brief Remove a directory or archive from the search path. |
| 887 | * |
| 888 | * \deprecated As of PhysicsFS 2.1, use PHYSFS_unmount() instead. This |
| 889 | * function just wraps it anyhow. There's no functional difference |
| 890 | * except the vocabulary changed from "adding to the search path" |
| 891 | * to "mounting" when that functionality was extended, and thus |
| 892 | * the preferred way to accomplish this function's work is now |
| 893 | * called "unmounting." |
| 894 | * |
| 895 | * This function is equivalent to: |
| 896 | * |
| 897 | * \code |
| 898 | * PHYSFS_unmount(oldDir); |
| 899 | * \endcode |
| 900 | * |
| 901 | * You must use this and not PHYSFS_unmount if binary compatibility with |
| 902 | * PhysicsFS 1.0 is important (which it may not be for many people). |
| 903 | * |
| 904 | * \sa PHYSFS_addToSearchPath |
| 905 | * \sa PHYSFS_getSearchPath |
| 906 | * \sa PHYSFS_unmount |
| 907 | */ |
| 908 | PHYSFS_DECL int PHYSFS_removeFromSearchPath(const char *oldDir) |
| 909 | PHYSFS_DEPRECATED; |
| 910 | |
| 911 | |
| 912 | /** |
| 913 | * \fn char **PHYSFS_getSearchPath(void) |
| 914 | * \brief Get the current search path. |
| 915 | * |
| 916 | * The default search path is an empty list. |
| 917 | * |
| 918 | * The returned value is an array of strings, with a NULL entry to signify the |
| 919 | * end of the list: |
| 920 | * |
| 921 | * \code |
| 922 | * char **i; |
| 923 | * |
| 924 | * for (i = PHYSFS_getSearchPath(); *i != NULL; i++) |
| 925 | * printf("[%s] is in the search path.\n", *i); |
| 926 | * \endcode |
| 927 | * |
| 928 | * When you are done with the returned information, you may dispose of the |
| 929 | * resources by calling PHYSFS_freeList() with the returned pointer. |
| 930 | * |
| 931 | * \return Null-terminated array of null-terminated strings. NULL if there |
| 932 | * was a problem (read: OUT OF MEMORY). |
| 933 | * |
| 934 | * \sa PHYSFS_getSearchPathCallback |
| 935 | * \sa PHYSFS_addToSearchPath |
| 936 | * \sa PHYSFS_removeFromSearchPath |
| 937 | */ |
| 938 | PHYSFS_DECL char **PHYSFS_getSearchPath(void); |
| 939 | |
| 940 | |
| 941 | /** |
| 942 | * \fn int PHYSFS_setSaneConfig(const char *organization, const char *appName, const char *archiveExt, int includeCdRoms, int archivesFirst) |
| 943 | * \brief Set up sane, default paths. |
| 944 | * |
| 945 | * Helper function. |
| 946 | * |
| 947 | * The write dir will be set to the pref dir returned by |
| 948 | * \code PHYSFS_getPrefDir(organization, appName) \endcode, which is |
| 949 | * created if it doesn't exist. |
| 950 | * |
| 951 | * The above is sufficient to make sure your program's configuration directory |
| 952 | * is separated from other clutter, and platform-independent. |
| 953 | * |
| 954 | * The search path will be: |
| 955 | * |
| 956 | * - The Write Dir (created if it doesn't exist) |
| 957 | * - The Base Dir (PHYSFS_getBaseDir()) |
| 958 | * - All found CD-ROM dirs (optionally) |
| 959 | * |
| 960 | * These directories are then searched for files ending with the extension |
| 961 | * (archiveExt), which, if they are valid and supported archives, will also |
| 962 | * be added to the search path. If you specified "PKG" for (archiveExt), and |
| 963 | * there's a file named data.PKG in the base dir, it'll be checked. Archives |
| 964 | * can either be appended or prepended to the search path in alphabetical |
| 965 | * order, regardless of which directories they were found in. All archives |
| 966 | * are mounted in the root of the virtual file system ("/"). |
| 967 | * |
| 968 | * All of this can be accomplished from the application, but this just does it |
| 969 | * all for you. Feel free to add more to the search path manually, too. |
| 970 | * |
| 971 | * \param organization Name of your company/group/etc to be used as a |
| 972 | * dirname, so keep it small, and no-frills. |
| 973 | * |
| 974 | * \param appName Program-specific name of your program, to separate it |
| 975 | * from other programs using PhysicsFS. |
| 976 | * |
| 977 | * \param archiveExt File extension used by your program to specify an |
| 978 | * archive. For example, Quake 3 uses "pk3", even though |
| 979 | * they are just zipfiles. Specify NULL to not dig out |
| 980 | * archives automatically. Do not specify the '.' char; |
| 981 | * If you want to look for ZIP files, specify "ZIP" and |
| 982 | * not ".ZIP" ... the archive search is case-insensitive. |
| 983 | * |
| 984 | * \param includeCdRoms Non-zero to include CD-ROMs in the search path, and |
| 985 | * (if (archiveExt) != NULL) search them for archives. |
| 986 | * This may cause a significant amount of blocking |
| 987 | * while discs are accessed, and if there are no discs |
| 988 | * in the drive (or even not mounted on Unix systems), |
| 989 | * then they may not be made available anyhow. You may |
| 990 | * want to specify zero and handle the disc setup |
| 991 | * yourself. |
| 992 | * |
| 993 | * \param archivesFirst Non-zero to prepend the archives to the search path. |
| 994 | * Zero to append them. Ignored if !(archiveExt). |
| 995 | * |
| 996 | * \return nonzero on success, zero on error. Use PHYSFS_getLastErrorCode() |
| 997 | * to obtain the specific error. |
| 998 | */ |
| 999 | PHYSFS_DECL int PHYSFS_setSaneConfig(const char *organization, |
| 1000 | const char *appName, |
| 1001 | const char *archiveExt, |
| 1002 | int includeCdRoms, |
| 1003 | int archivesFirst); |
| 1004 | |
| 1005 | |
| 1006 | /* Directory management stuff ... */ |
| 1007 | |
| 1008 | /** |
| 1009 | * \fn int PHYSFS_mkdir(const char *dirName) |
| 1010 | * \brief Create a directory. |
| 1011 | * |
| 1012 | * This is specified in platform-independent notation in relation to the |
| 1013 | * write dir. All missing parent directories are also created if they |
| 1014 | * don't exist. |
| 1015 | * |
| 1016 | * So if you've got the write dir set to "C:\mygame\writedir" and call |
| 1017 | * PHYSFS_mkdir("downloads/maps") then the directories |
| 1018 | * "C:\mygame\writedir\downloads" and "C:\mygame\writedir\downloads\maps" |
| 1019 | * will be created if possible. If the creation of "maps" fails after we |
| 1020 | * have successfully created "downloads", then the function leaves the |
| 1021 | * created directory behind and reports failure. |
| 1022 | * |
| 1023 | * \param dirName New dir to create. |
| 1024 | * \return nonzero on success, zero on error. Use |
| 1025 | * PHYSFS_getLastErrorCode() to obtain the specific error. |
| 1026 | * |
| 1027 | * \sa PHYSFS_delete |
| 1028 | */ |
| 1029 | PHYSFS_DECL int PHYSFS_mkdir(const char *dirName); |
| 1030 | |
| 1031 | |
| 1032 | /** |
| 1033 | * \fn int PHYSFS_delete(const char *filename) |
| 1034 | * \brief Delete a file or directory. |
| 1035 | * |
| 1036 | * (filename) is specified in platform-independent notation in relation to the |
| 1037 | * write dir. |
| 1038 | * |
| 1039 | * A directory must be empty before this call can delete it. |
| 1040 | * |
| 1041 | * Deleting a symlink will remove the link, not what it points to, regardless |
| 1042 | * of whether you "permitSymLinks" or not. |
| 1043 | * |
| 1044 | * So if you've got the write dir set to "C:\mygame\writedir" and call |
| 1045 | * PHYSFS_delete("downloads/maps/level1.map") then the file |
| 1046 | * "C:\mygame\writedir\downloads\maps\level1.map" is removed from the |
| 1047 | * physical filesystem, if it exists and the operating system permits the |
| 1048 | * deletion. |
| 1049 | * |
| 1050 | * Note that on Unix systems, deleting a file may be successful, but the |
| 1051 | * actual file won't be removed until all processes that have an open |
| 1052 | * filehandle to it (including your program) close their handles. |
| 1053 | * |
| 1054 | * Chances are, the bits that make up the file still exist, they are just |
| 1055 | * made available to be written over at a later point. Don't consider this |
| 1056 | * a security method or anything. :) |
| 1057 | * |
| 1058 | * \param filename Filename to delete. |
| 1059 | * \return nonzero on success, zero on error. Use PHYSFS_getLastErrorCode() |
| 1060 | * to obtain the specific error. |
| 1061 | */ |
| 1062 | PHYSFS_DECL int PHYSFS_delete(const char *filename); |
| 1063 | |
| 1064 | |
| 1065 | /** |
| 1066 | * \fn const char *PHYSFS_getRealDir(const char *filename) |
| 1067 | * \brief Figure out where in the search path a file resides. |
| 1068 | * |
| 1069 | * The file is specified in platform-independent notation. The returned |
| 1070 | * filename will be the element of the search path where the file was found, |
| 1071 | * which may be a directory, or an archive. Even if there are multiple |
| 1072 | * matches in different parts of the search path, only the first one found |
| 1073 | * is used, just like when opening a file. |
| 1074 | * |
| 1075 | * So, if you look for "maps/level1.map", and C:\\mygame is in your search |
| 1076 | * path and C:\\mygame\\maps\\level1.map exists, then "C:\mygame" is returned. |
| 1077 | * |
| 1078 | * If a any part of a match is a symbolic link, and you've not explicitly |
| 1079 | * permitted symlinks, then it will be ignored, and the search for a match |
| 1080 | * will continue. |
| 1081 | * |
| 1082 | * If you specify a fake directory that only exists as a mount point, it'll |
| 1083 | * be associated with the first archive mounted there, even though that |
| 1084 | * directory isn't necessarily contained in a real archive. |
| 1085 | * |
| 1086 | * \warning This will return NULL if there is no real directory associated |
| 1087 | * with (filename). Specifically, PHYSFS_mountIo(), |
| 1088 | * PHYSFS_mountMemory(), and PHYSFS_mountHandle() will return NULL |
| 1089 | * even if the filename is found in the search path. Plan accordingly. |
| 1090 | * |
| 1091 | * \param filename file to look for. |
| 1092 | * \return READ ONLY string of element of search path containing the |
| 1093 | * the file in question. NULL if not found. |
| 1094 | */ |
| 1095 | PHYSFS_DECL const char *PHYSFS_getRealDir(const char *filename); |
| 1096 | |
| 1097 | |
| 1098 | /** |
| 1099 | * \fn char **PHYSFS_enumerateFiles(const char *dir) |
| 1100 | * \brief Get a file listing of a search path's directory. |
| 1101 | * |
| 1102 | * \warning In PhysicsFS versions prior to 2.1, this function would return |
| 1103 | * as many items as it could in the face of a failure condition |
| 1104 | * (out of memory, disk i/o error, etc). Since this meant apps |
| 1105 | * couldn't distinguish between complete success and partial failure, |
| 1106 | * and since the function could always return NULL to report |
| 1107 | * catastrophic failures anyway, in PhysicsFS 2.1 this function's |
| 1108 | * policy changed: it will either return a list of complete results |
| 1109 | * or it will return NULL for any failure of any kind, so we can |
| 1110 | * guarantee that the enumeration ran to completion and has no gaps |
| 1111 | * in its results. |
| 1112 | * |
| 1113 | * Matching directories are interpolated. That is, if "C:\mydir" is in the |
| 1114 | * search path and contains a directory "savegames" that contains "x.sav", |
| 1115 | * "y.sav", and "z.sav", and there is also a "C:\userdir" in the search path |
| 1116 | * that has a "savegames" subdirectory with "w.sav", then the following code: |
| 1117 | * |
| 1118 | * \code |
| 1119 | * char **rc = PHYSFS_enumerateFiles("savegames"); |
| 1120 | * char **i; |
| 1121 | * |
| 1122 | * for (i = rc; *i != NULL; i++) |
| 1123 | * printf(" * We've got [%s].\n", *i); |
| 1124 | * |
| 1125 | * PHYSFS_freeList(rc); |
| 1126 | * \endcode |
| 1127 | * |
| 1128 | * \...will print: |
| 1129 | * |
| 1130 | * \verbatim |
| 1131 | * We've got [x.sav]. |
| 1132 | * We've got [y.sav]. |
| 1133 | * We've got [z.sav]. |
| 1134 | * We've got [w.sav].\endverbatim |
| 1135 | * |
| 1136 | * Feel free to sort the list however you like. However, the returned data |
| 1137 | * will always contain no duplicates, and will be always sorted in alphabetic |
| 1138 | * (rather: case-sensitive Unicode) order for you. |
| 1139 | * |
| 1140 | * Don't forget to call PHYSFS_freeList() with the return value from this |
| 1141 | * function when you are done with it. |
| 1142 | * |
| 1143 | * \param dir directory in platform-independent notation to enumerate. |
| 1144 | * \return Null-terminated array of null-terminated strings, or NULL for |
| 1145 | * failure cases. |
| 1146 | * |
| 1147 | * \sa PHYSFS_enumerate |
| 1148 | */ |
| 1149 | PHYSFS_DECL char **PHYSFS_enumerateFiles(const char *dir); |
| 1150 | |
| 1151 | |
| 1152 | /** |
| 1153 | * \fn int PHYSFS_exists(const char *fname) |
| 1154 | * \brief Determine if a file exists in the search path. |
| 1155 | * |
| 1156 | * Reports true if there is an entry anywhere in the search path by the |
| 1157 | * name of (fname). |
| 1158 | * |
| 1159 | * Note that entries that are symlinks are ignored if |
| 1160 | * PHYSFS_permitSymbolicLinks(1) hasn't been called, so you |
| 1161 | * might end up further down in the search path than expected. |
| 1162 | * |
| 1163 | * \param fname filename in platform-independent notation. |
| 1164 | * \return non-zero if filename exists. zero otherwise. |
| 1165 | */ |
| 1166 | PHYSFS_DECL int PHYSFS_exists(const char *fname); |
| 1167 | |
| 1168 | |
| 1169 | /** |
| 1170 | * \fn int PHYSFS_isDirectory(const char *fname) |
| 1171 | * \brief Determine if a file in the search path is really a directory. |
| 1172 | * |
| 1173 | * \deprecated As of PhysicsFS 2.1, use PHYSFS_stat() instead. This |
| 1174 | * function just wraps it anyhow. |
| 1175 | * |
| 1176 | * Determine if the first occurence of (fname) in the search path is |
| 1177 | * really a directory entry. |
| 1178 | * |
| 1179 | * Note that entries that are symlinks are ignored if |
| 1180 | * PHYSFS_permitSymbolicLinks(1) hasn't been called, so you |
| 1181 | * might end up further down in the search path than expected. |
| 1182 | * |
| 1183 | * \param fname filename in platform-independent notation. |
| 1184 | * \return non-zero if filename exists and is a directory. zero otherwise. |
| 1185 | * |
| 1186 | * \sa PHYSFS_stat |
| 1187 | * \sa PHYSFS_exists |
| 1188 | */ |
| 1189 | PHYSFS_DECL int PHYSFS_isDirectory(const char *fname) PHYSFS_DEPRECATED; |
| 1190 | |
| 1191 | |
| 1192 | /** |
| 1193 | * \fn int PHYSFS_isSymbolicLink(const char *fname) |
| 1194 | * \brief Determine if a file in the search path is really a symbolic link. |
| 1195 | * |
| 1196 | * \deprecated As of PhysicsFS 2.1, use PHYSFS_stat() instead. This |
| 1197 | * function just wraps it anyhow. |
| 1198 | * |
| 1199 | * Determine if the first occurence of (fname) in the search path is |
| 1200 | * really a symbolic link. |
| 1201 | * |
| 1202 | * Note that entries that are symlinks are ignored if |
| 1203 | * PHYSFS_permitSymbolicLinks(1) hasn't been called, and as such, |
| 1204 | * this function will always return 0 in that case. |
| 1205 | * |
| 1206 | * \param fname filename in platform-independent notation. |
| 1207 | * \return non-zero if filename exists and is a symlink. zero otherwise. |
| 1208 | * |
| 1209 | * \sa PHYSFS_stat |
| 1210 | * \sa PHYSFS_exists |
| 1211 | */ |
| 1212 | PHYSFS_DECL int PHYSFS_isSymbolicLink(const char *fname) PHYSFS_DEPRECATED; |
| 1213 | |
| 1214 | |
| 1215 | /** |
| 1216 | * \fn PHYSFS_sint64 PHYSFS_getLastModTime(const char *filename) |
| 1217 | * \brief Get the last modification time of a file. |
| 1218 | * |
| 1219 | * \deprecated As of PhysicsFS 2.1, use PHYSFS_stat() instead. This |
| 1220 | * function just wraps it anyhow. |
| 1221 | * |
| 1222 | * The modtime is returned as a number of seconds since the Unix epoch |
| 1223 | * (midnight, Jan 1, 1970). The exact derivation and accuracy of this time |
| 1224 | * depends on the particular archiver. If there is no reasonable way to |
| 1225 | * obtain this information for a particular archiver, or there was some sort |
| 1226 | * of error, this function returns (-1). |
| 1227 | * |
| 1228 | * You must use this and not PHYSFS_stat() if binary compatibility with |
| 1229 | * PhysicsFS 2.0 is important (which it may not be for many people). |
| 1230 | * |
| 1231 | * \param filename filename to check, in platform-independent notation. |
| 1232 | * \return last modified time of the file. -1 if it can't be determined. |
| 1233 | * |
| 1234 | * \sa PHYSFS_stat |
| 1235 | */ |
| 1236 | PHYSFS_DECL PHYSFS_sint64 PHYSFS_getLastModTime(const char *filename) |
| 1237 | PHYSFS_DEPRECATED; |
| 1238 | |
| 1239 | |
| 1240 | /* i/o stuff... */ |
| 1241 | |
| 1242 | /** |
| 1243 | * \fn PHYSFS_File *PHYSFS_openWrite(const char *filename) |
| 1244 | * \brief Open a file for writing. |
| 1245 | * |
| 1246 | * Open a file for writing, in platform-independent notation and in relation |
| 1247 | * to the write dir as the root of the writable filesystem. The specified |
| 1248 | * file is created if it doesn't exist. If it does exist, it is truncated to |
| 1249 | * zero bytes, and the writing offset is set to the start. |
| 1250 | * |
| 1251 | * Note that entries that are symlinks are ignored if |
| 1252 | * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a |
| 1253 | * symlink with this function will fail in such a case. |
| 1254 | * |
| 1255 | * \param filename File to open. |
| 1256 | * \return A valid PhysicsFS filehandle on success, NULL on error. Use |
| 1257 | * PHYSFS_getLastErrorCode() to obtain the specific error. |
| 1258 | * |
| 1259 | * \sa PHYSFS_openRead |
| 1260 | * \sa PHYSFS_openAppend |
| 1261 | * \sa PHYSFS_write |
| 1262 | * \sa PHYSFS_close |
| 1263 | */ |
| 1264 | PHYSFS_DECL PHYSFS_File *PHYSFS_openWrite(const char *filename); |
| 1265 | |
| 1266 | |
| 1267 | /** |
| 1268 | * \fn PHYSFS_File *PHYSFS_openAppend(const char *filename) |
| 1269 | * \brief Open a file for appending. |
| 1270 | * |
| 1271 | * Open a file for writing, in platform-independent notation and in relation |
| 1272 | * to the write dir as the root of the writable filesystem. The specified |
| 1273 | * file is created if it doesn't exist. If it does exist, the writing offset |
| 1274 | * is set to the end of the file, so the first write will be the byte after |
| 1275 | * the end. |
| 1276 | * |
| 1277 | * Note that entries that are symlinks are ignored if |
| 1278 | * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a |
| 1279 | * symlink with this function will fail in such a case. |
| 1280 | * |
| 1281 | * \param filename File to open. |
| 1282 | * \return A valid PhysicsFS filehandle on success, NULL on error. Use |
| 1283 | * PHYSFS_getLastErrorCode() to obtain the specific error. |
| 1284 | * |
| 1285 | * \sa PHYSFS_openRead |
| 1286 | * \sa PHYSFS_openWrite |
| 1287 | * \sa PHYSFS_write |
| 1288 | * \sa PHYSFS_close |
| 1289 | */ |
| 1290 | PHYSFS_DECL PHYSFS_File *PHYSFS_openAppend(const char *filename); |
| 1291 | |
| 1292 | |
| 1293 | /** |
| 1294 | * \fn PHYSFS_File *PHYSFS_openRead(const char *filename) |
| 1295 | * \brief Open a file for reading. |
| 1296 | * |
| 1297 | * Open a file for reading, in platform-independent notation. The search path |
| 1298 | * is checked one at a time until a matching file is found, in which case an |
| 1299 | * abstract filehandle is associated with it, and reading may be done. |
| 1300 | * The reading offset is set to the first byte of the file. |
| 1301 | * |
| 1302 | * Note that entries that are symlinks are ignored if |
| 1303 | * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a |
| 1304 | * symlink with this function will fail in such a case. |
| 1305 | * |
| 1306 | * \param filename File to open. |
| 1307 | * \return A valid PhysicsFS filehandle on success, NULL on error. |
| 1308 | * Use PHYSFS_getLastErrorCode() to obtain the specific error. |
| 1309 | * |
| 1310 | * \sa PHYSFS_openWrite |
| 1311 | * \sa PHYSFS_openAppend |
| 1312 | * \sa PHYSFS_read |
| 1313 | * \sa PHYSFS_close |
| 1314 | */ |
| 1315 | PHYSFS_DECL PHYSFS_File *PHYSFS_openRead(const char *filename); |
| 1316 | |
| 1317 | |
| 1318 | /** |
| 1319 | * \fn int PHYSFS_close(PHYSFS_File *handle) |
| 1320 | * \brief Close a PhysicsFS filehandle. |
| 1321 | * |
| 1322 | * This call is capable of failing if the operating system was buffering |
| 1323 | * writes to the physical media, and, now forced to write those changes to |
| 1324 | * physical media, can not store the data for some reason. In such a case, |
| 1325 | * the filehandle stays open. A well-written program should ALWAYS check the |
| 1326 | * return value from the close call in addition to every writing call! |
| 1327 | * |
| 1328 | * \param handle handle returned from PHYSFS_open*(). |
| 1329 | * \return nonzero on success, zero on error. Use PHYSFS_getLastErrorCode() |
| 1330 | * to obtain the specific error. |
| 1331 | * |
| 1332 | * \sa PHYSFS_openRead |
| 1333 | * \sa PHYSFS_openWrite |
| 1334 | * \sa PHYSFS_openAppend |
| 1335 | */ |
| 1336 | PHYSFS_DECL int PHYSFS_close(PHYSFS_File *handle); |
| 1337 | |
| 1338 | |
| 1339 | /** |
| 1340 | * \fn PHYSFS_sint64 PHYSFS_read(PHYSFS_File *handle, void *buffer, PHYSFS_uint32 objSize, PHYSFS_uint32 objCount) |
| 1341 | * \brief Read data from a PhysicsFS filehandle |
| 1342 | * |
| 1343 | * The file must be opened for reading. |
| 1344 | * |
| 1345 | * \deprecated As of PhysicsFS 2.1, use PHYSFS_readBytes() instead. This |
| 1346 | * function just wraps it anyhow. This function never clarified |
| 1347 | * what would happen if you managed to read a partial object, so |
| 1348 | * working at the byte level makes this cleaner for everyone, |
| 1349 | * especially now that PHYSFS_Io interfaces can be supplied by the |
| 1350 | * application. |
| 1351 | * |
| 1352 | * \param handle handle returned from PHYSFS_openRead(). |
| 1353 | * \param buffer buffer to store read data into. |
| 1354 | * \param objSize size in bytes of objects being read from (handle). |
| 1355 | * \param objCount number of (objSize) objects to read from (handle). |
| 1356 | * \return number of objects read. PHYSFS_getLastErrorCode() can shed light |
| 1357 | * on the reason this might be < (objCount), as can PHYSFS_eof(). |
| 1358 | * -1 if complete failure. |
| 1359 | * |
| 1360 | * \sa PHYSFS_readBytes |
| 1361 | * \sa PHYSFS_eof |
| 1362 | */ |
| 1363 | PHYSFS_DECL PHYSFS_sint64 PHYSFS_read(PHYSFS_File *handle, |
| 1364 | void *buffer, |
| 1365 | PHYSFS_uint32 objSize, |
| 1366 | PHYSFS_uint32 objCount) |
| 1367 | PHYSFS_DEPRECATED; |
| 1368 | |
| 1369 | /** |
| 1370 | * \fn PHYSFS_sint64 PHYSFS_write(PHYSFS_File *handle, const void *buffer, PHYSFS_uint32 objSize, PHYSFS_uint32 objCount) |
| 1371 | * \brief Write data to a PhysicsFS filehandle |
| 1372 | * |
| 1373 | * The file must be opened for writing. |
| 1374 | * |
| 1375 | * \deprecated As of PhysicsFS 2.1, use PHYSFS_writeBytes() instead. This |
| 1376 | * function just wraps it anyhow. This function never clarified |
| 1377 | * what would happen if you managed to write a partial object, so |
| 1378 | * working at the byte level makes this cleaner for everyone, |
| 1379 | * especially now that PHYSFS_Io interfaces can be supplied by the |
| 1380 | * application. |
| 1381 | * |
| 1382 | * \param handle retval from PHYSFS_openWrite() or PHYSFS_openAppend(). |
| 1383 | * \param buffer buffer of bytes to write to (handle). |
| 1384 | * \param objSize size in bytes of objects being written to (handle). |
| 1385 | * \param objCount number of (objSize) objects to write to (handle). |
| 1386 | * \return number of objects written. PHYSFS_getLastErrorCode() can shed |
| 1387 | * light on the reason this might be < (objCount). -1 if complete |
| 1388 | * failure. |
| 1389 | * |
| 1390 | * \sa PHYSFS_writeBytes |
| 1391 | */ |
| 1392 | PHYSFS_DECL PHYSFS_sint64 PHYSFS_write(PHYSFS_File *handle, |
| 1393 | const void *buffer, |
| 1394 | PHYSFS_uint32 objSize, |
| 1395 | PHYSFS_uint32 objCount) |
| 1396 | PHYSFS_DEPRECATED; |
| 1397 | |
| 1398 | |
| 1399 | /* File position stuff... */ |
| 1400 | |
| 1401 | /** |
| 1402 | * \fn int PHYSFS_eof(PHYSFS_File *handle) |
| 1403 | * \brief Check for end-of-file state on a PhysicsFS filehandle. |
| 1404 | * |
| 1405 | * Determine if the end of file has been reached in a PhysicsFS filehandle. |
| 1406 | * |
| 1407 | * \param handle handle returned from PHYSFS_openRead(). |
| 1408 | * \return nonzero if EOF, zero if not. |
| 1409 | * |
| 1410 | * \sa PHYSFS_read |
| 1411 | * \sa PHYSFS_tell |
| 1412 | */ |
| 1413 | PHYSFS_DECL int PHYSFS_eof(PHYSFS_File *handle); |
| 1414 | |
| 1415 | |
| 1416 | /** |
| 1417 | * \fn PHYSFS_sint64 PHYSFS_tell(PHYSFS_File *handle) |
| 1418 | * \brief Determine current position within a PhysicsFS filehandle. |
| 1419 | * |
| 1420 | * \param handle handle returned from PHYSFS_open*(). |
| 1421 | * \return offset in bytes from start of file. -1 if error occurred. |
| 1422 | * Use PHYSFS_getLastErrorCode() to obtain the specific error. |
| 1423 | * |
| 1424 | * \sa PHYSFS_seek |
| 1425 | */ |
| 1426 | PHYSFS_DECL PHYSFS_sint64 PHYSFS_tell(PHYSFS_File *handle); |
| 1427 | |
| 1428 | |
| 1429 | /** |
| 1430 | * \fn int PHYSFS_seek(PHYSFS_File *handle, PHYSFS_uint64 pos) |
| 1431 | * \brief Seek to a new position within a PhysicsFS filehandle. |
| 1432 | * |
| 1433 | * The next read or write will occur at that place. Seeking past the |
| 1434 | * beginning or end of the file is not allowed, and causes an error. |
| 1435 | * |
| 1436 | * \param handle handle returned from PHYSFS_open*(). |
| 1437 | * \param pos number of bytes from start of file to seek to. |
| 1438 | * \return nonzero on success, zero on error. Use PHYSFS_getLastErrorCode() |
| 1439 | * to obtain the specific error. |
| 1440 | * |
| 1441 | * \sa PHYSFS_tell |
| 1442 | */ |
| 1443 | PHYSFS_DECL int PHYSFS_seek(PHYSFS_File *handle, PHYSFS_uint64 pos); |
| 1444 | |
| 1445 | |
| 1446 | /** |
| 1447 | * \fn PHYSFS_sint64 PHYSFS_fileLength(PHYSFS_File *handle) |
| 1448 | * \brief Get total length of a file in bytes. |
| 1449 | * |
| 1450 | * Note that if another process/thread is writing to this file at the same |
| 1451 | * time, then the information this function supplies could be incorrect |
| 1452 | * before you get it. Use with caution, or better yet, don't use at all. |
| 1453 | * |
| 1454 | * \param handle handle returned from PHYSFS_open*(). |
| 1455 | * \return size in bytes of the file. -1 if can't be determined. |
| 1456 | * |
| 1457 | * \sa PHYSFS_tell |
| 1458 | * \sa PHYSFS_seek |
| 1459 | */ |
| 1460 | PHYSFS_DECL PHYSFS_sint64 PHYSFS_fileLength(PHYSFS_File *handle); |
| 1461 | |
| 1462 | |
| 1463 | /* Buffering stuff... */ |
| 1464 | |
| 1465 | /** |
| 1466 | * \fn int PHYSFS_setBuffer(PHYSFS_File *handle, PHYSFS_uint64 bufsize) |
| 1467 | * \brief Set up buffering for a PhysicsFS file handle. |
| 1468 | * |
| 1469 | * Define an i/o buffer for a file handle. A memory block of (bufsize) bytes |
| 1470 | * will be allocated and associated with (handle). |
| 1471 | * |
| 1472 | * For files opened for reading, up to (bufsize) bytes are read from (handle) |
| 1473 | * and stored in the internal buffer. Calls to PHYSFS_read() will pull |
| 1474 | * from this buffer until it is empty, and then refill it for more reading. |
| 1475 | * Note that compressed files, like ZIP archives, will decompress while |
| 1476 | * buffering, so this can be handy for offsetting CPU-intensive operations. |
| 1477 | * The buffer isn't filled until you do your next read. |
| 1478 | * |
| 1479 | * For files opened for writing, data will be buffered to memory until the |
| 1480 | * buffer is full or the buffer is flushed. Closing a handle implicitly |
| 1481 | * causes a flush...check your return values! |
| 1482 | * |
| 1483 | * Seeking, etc transparently accounts for buffering. |
| 1484 | * |
| 1485 | * You can resize an existing buffer by calling this function more than once |
| 1486 | * on the same file. Setting the buffer size to zero will free an existing |
| 1487 | * buffer. |
| 1488 | * |
| 1489 | * PhysicsFS file handles are unbuffered by default. |
| 1490 | * |
| 1491 | * Please check the return value of this function! Failures can include |
| 1492 | * not being able to seek backwards in a read-only file when removing the |
| 1493 | * buffer, not being able to allocate the buffer, and not being able to |
| 1494 | * flush the buffer to disk, among other unexpected problems. |
| 1495 | * |
| 1496 | * \param handle handle returned from PHYSFS_open*(). |
| 1497 | * \param bufsize size, in bytes, of buffer to allocate. |
| 1498 | * \return nonzero if successful, zero on error. |
| 1499 | * |
| 1500 | * \sa PHYSFS_flush |
| 1501 | * \sa PHYSFS_read |
| 1502 | * \sa PHYSFS_write |
| 1503 | * \sa PHYSFS_close |
| 1504 | */ |
| 1505 | PHYSFS_DECL int PHYSFS_setBuffer(PHYSFS_File *handle, PHYSFS_uint64 bufsize); |
| 1506 | |
| 1507 | |
| 1508 | /** |
| 1509 | * \fn int PHYSFS_flush(PHYSFS_File *handle) |
| 1510 | * \brief Flush a buffered PhysicsFS file handle. |
| 1511 | * |
| 1512 | * For buffered files opened for writing, this will put the current contents |
| 1513 | * of the buffer to disk and flag the buffer as empty if possible. |
| 1514 | * |
| 1515 | * For buffered files opened for reading or unbuffered files, this is a safe |
| 1516 | * no-op, and will report success. |
| 1517 | * |
| 1518 | * \param handle handle returned from PHYSFS_open*(). |
| 1519 | * \return nonzero if successful, zero on error. |
| 1520 | * |
| 1521 | * \sa PHYSFS_setBuffer |
| 1522 | * \sa PHYSFS_close |
| 1523 | */ |
| 1524 | PHYSFS_DECL int PHYSFS_flush(PHYSFS_File *handle); |
| 1525 | |
| 1526 | |
| 1527 | /* Byteorder stuff... */ |
| 1528 | |
| 1529 | /** |
| 1530 | * \fn PHYSFS_sint16 PHYSFS_swapSLE16(PHYSFS_sint16 val) |
| 1531 | * \brief Swap littleendian signed 16 to platform's native byte order. |
| 1532 | * |
| 1533 | * Take a 16-bit signed value in littleendian format and convert it to |
| 1534 | * the platform's native byte order. |
| 1535 | * |
| 1536 | * \param val value to convert |
| 1537 | * \return converted value. |
| 1538 | */ |
| 1539 | PHYSFS_DECL PHYSFS_sint16 PHYSFS_swapSLE16(PHYSFS_sint16 val); |
| 1540 | |
| 1541 | |
| 1542 | /** |
| 1543 | * \fn PHYSFS_uint16 PHYSFS_swapULE16(PHYSFS_uint16 val) |
| 1544 | * \brief Swap littleendian unsigned 16 to platform's native byte order. |
| 1545 | * |
| 1546 | * Take a 16-bit unsigned value in littleendian format and convert it to |
| 1547 | * the platform's native byte order. |
| 1548 | * |
| 1549 | * \param val value to convert |
| 1550 | * \return converted value. |
| 1551 | */ |
| 1552 | PHYSFS_DECL PHYSFS_uint16 PHYSFS_swapULE16(PHYSFS_uint16 val); |
| 1553 | |
| 1554 | /** |
| 1555 | * \fn PHYSFS_sint32 PHYSFS_swapSLE32(PHYSFS_sint32 val) |
| 1556 | * \brief Swap littleendian signed 32 to platform's native byte order. |
| 1557 | * |
| 1558 | * Take a 32-bit signed value in littleendian format and convert it to |
| 1559 | * the platform's native byte order. |
| 1560 | * |
| 1561 | * \param val value to convert |
| 1562 | * \return converted value. |
| 1563 | */ |
| 1564 | PHYSFS_DECL PHYSFS_sint32 PHYSFS_swapSLE32(PHYSFS_sint32 val); |
| 1565 | |
| 1566 | |
| 1567 | /** |
| 1568 | * \fn PHYSFS_uint32 PHYSFS_swapULE32(PHYSFS_uint32 val) |
| 1569 | * \brief Swap littleendian unsigned 32 to platform's native byte order. |
| 1570 | * |
| 1571 | * Take a 32-bit unsigned value in littleendian format and convert it to |
| 1572 | * the platform's native byte order. |
| 1573 | * |
| 1574 | * \param val value to convert |
| 1575 | * \return converted value. |
| 1576 | */ |
| 1577 | PHYSFS_DECL PHYSFS_uint32 PHYSFS_swapULE32(PHYSFS_uint32 val); |
| 1578 | |
| 1579 | /** |
| 1580 | * \fn PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 val) |
| 1581 | * \brief Swap littleendian signed 64 to platform's native byte order. |
| 1582 | * |
| 1583 | * Take a 64-bit signed value in littleendian format and convert it to |
| 1584 | * the platform's native byte order. |
| 1585 | * |
| 1586 | * \param val value to convert |
| 1587 | * \return converted value. |
| 1588 | * |
| 1589 | * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without |
| 1590 | * any sort of 64-bit support. |
| 1591 | */ |
| 1592 | PHYSFS_DECL PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 val); |
| 1593 | |
| 1594 | |
| 1595 | /** |
| 1596 | * \fn PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 val) |
| 1597 | * \brief Swap littleendian unsigned 64 to platform's native byte order. |
| 1598 | * |
| 1599 | * Take a 64-bit unsigned value in littleendian format and convert it to |
| 1600 | * the platform's native byte order. |
| 1601 | * |
| 1602 | * \param val value to convert |
| 1603 | * \return converted value. |
| 1604 | * |
| 1605 | * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without |
| 1606 | * any sort of 64-bit support. |
| 1607 | */ |
| 1608 | PHYSFS_DECL PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 val); |
| 1609 | |
| 1610 | |
| 1611 | /** |
| 1612 | * \fn PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 val) |
| 1613 | * \brief Swap bigendian signed 16 to platform's native byte order. |
| 1614 | * |
| 1615 | * Take a 16-bit signed value in bigendian format and convert it to |
| 1616 | * the platform's native byte order. |
| 1617 | * |
| 1618 | * \param val value to convert |
| 1619 | * \return converted value. |
| 1620 | */ |
| 1621 | PHYSFS_DECL PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 val); |
| 1622 | |
| 1623 | |
| 1624 | /** |
| 1625 | * \fn PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 val) |
| 1626 | * \brief Swap bigendian unsigned 16 to platform's native byte order. |
| 1627 | * |
| 1628 | * Take a 16-bit unsigned value in bigendian format and convert it to |
| 1629 | * the platform's native byte order. |
| 1630 | * |
| 1631 | * \param val value to convert |
| 1632 | * \return converted value. |
| 1633 | */ |
| 1634 | PHYSFS_DECL PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 val); |
| 1635 | |
| 1636 | /** |
| 1637 | * \fn PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 val) |
| 1638 | * \brief Swap bigendian signed 32 to platform's native byte order. |
| 1639 | * |
| 1640 | * Take a 32-bit signed value in bigendian format and convert it to |
| 1641 | * the platform's native byte order. |
| 1642 | * |
| 1643 | * \param val value to convert |
| 1644 | * \return converted value. |
| 1645 | */ |
| 1646 | PHYSFS_DECL PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 val); |
| 1647 | |
| 1648 | |
| 1649 | /** |
| 1650 | * \fn PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 val) |
| 1651 | * \brief Swap bigendian unsigned 32 to platform's native byte order. |
| 1652 | * |
| 1653 | * Take a 32-bit unsigned value in bigendian format and convert it to |
| 1654 | * the platform's native byte order. |
| 1655 | * |
| 1656 | * \param val value to convert |
| 1657 | * \return converted value. |
| 1658 | */ |
| 1659 | PHYSFS_DECL PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 val); |
| 1660 | |
| 1661 | |
| 1662 | /** |
| 1663 | * \fn PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 val) |
| 1664 | * \brief Swap bigendian signed 64 to platform's native byte order. |
| 1665 | * |
| 1666 | * Take a 64-bit signed value in bigendian format and convert it to |
| 1667 | * the platform's native byte order. |
| 1668 | * |
| 1669 | * \param val value to convert |
| 1670 | * \return converted value. |
| 1671 | * |
| 1672 | * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without |
| 1673 | * any sort of 64-bit support. |
| 1674 | */ |
| 1675 | PHYSFS_DECL PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 val); |
| 1676 | |
| 1677 | |
| 1678 | /** |
| 1679 | * \fn PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 val) |
| 1680 | * \brief Swap bigendian unsigned 64 to platform's native byte order. |
| 1681 | * |
| 1682 | * Take a 64-bit unsigned value in bigendian format and convert it to |
| 1683 | * the platform's native byte order. |
| 1684 | * |
| 1685 | * \param val value to convert |
| 1686 | * \return converted value. |
| 1687 | * |
| 1688 | * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without |
| 1689 | * any sort of 64-bit support. |
| 1690 | */ |
| 1691 | PHYSFS_DECL PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 val); |
| 1692 | |
| 1693 | |
| 1694 | /** |
| 1695 | * \fn int PHYSFS_readSLE16(PHYSFS_File *file, PHYSFS_sint16 *val) |
| 1696 | * \brief Read and convert a signed 16-bit littleendian value. |
| 1697 | * |
| 1698 | * Convenience function. Read a signed 16-bit littleendian value from a |
| 1699 | * file and convert it to the platform's native byte order. |
| 1700 | * |
| 1701 | * \param file PhysicsFS file handle from which to read. |
| 1702 | * \param val pointer to where value should be stored. |
| 1703 | * \return zero on failure, non-zero on success. If successful, (*val) will |
| 1704 | * store the result. On failure, you can find out what went wrong |
| 1705 | * from PHYSFS_getLastErrorCode(). |
| 1706 | */ |
| 1707 | PHYSFS_DECL int PHYSFS_readSLE16(PHYSFS_File *file, PHYSFS_sint16 *val); |
| 1708 | |
| 1709 | |
| 1710 | /** |
| 1711 | * \fn int PHYSFS_readULE16(PHYSFS_File *file, PHYSFS_uint16 *val) |
| 1712 | * \brief Read and convert an unsigned 16-bit littleendian value. |
| 1713 | * |
| 1714 | * Convenience function. Read an unsigned 16-bit littleendian value from a |
| 1715 | * file and convert it to the platform's native byte order. |
| 1716 | * |
| 1717 | * \param file PhysicsFS file handle from which to read. |
| 1718 | * \param val pointer to where value should be stored. |
| 1719 | * \return zero on failure, non-zero on success. If successful, (*val) will |
| 1720 | * store the result. On failure, you can find out what went wrong |
| 1721 | * from PHYSFS_getLastErrorCode(). |
| 1722 | * |
| 1723 | */ |
| 1724 | PHYSFS_DECL int PHYSFS_readULE16(PHYSFS_File *file, PHYSFS_uint16 *val); |
| 1725 | |
| 1726 | |
| 1727 | /** |
| 1728 | * \fn int PHYSFS_readSBE16(PHYSFS_File *file, PHYSFS_sint16 *val) |
| 1729 | * \brief Read and convert a signed 16-bit bigendian value. |
| 1730 | * |
| 1731 | * Convenience function. Read a signed 16-bit bigendian value from a |
| 1732 | * file and convert it to the platform's native byte order. |
| 1733 | * |
| 1734 | * \param file PhysicsFS file handle from which to read. |
| 1735 | * \param val pointer to where value should be stored. |
| 1736 | * \return zero on failure, non-zero on success. If successful, (*val) will |
| 1737 | * store the result. On failure, you can find out what went wrong |
| 1738 | * from PHYSFS_getLastErrorCode(). |
| 1739 | */ |
| 1740 | PHYSFS_DECL int PHYSFS_readSBE16(PHYSFS_File *file, PHYSFS_sint16 *val); |
| 1741 | |
| 1742 | |
| 1743 | /** |
| 1744 | * \fn int PHYSFS_readUBE16(PHYSFS_File *file, PHYSFS_uint16 *val) |
| 1745 | * \brief Read and convert an unsigned 16-bit bigendian value. |
| 1746 | * |
| 1747 | * Convenience function. Read an unsigned 16-bit bigendian value from a |
| 1748 | * file and convert it to the platform's native byte order. |
| 1749 | * |
| 1750 | * \param file PhysicsFS file handle from which to read. |
| 1751 | * \param val pointer to where value should be stored. |
| 1752 | * \return zero on failure, non-zero on success. If successful, (*val) will |
| 1753 | * store the result. On failure, you can find out what went wrong |
| 1754 | * from PHYSFS_getLastErrorCode(). |
| 1755 | * |
| 1756 | */ |
| 1757 | PHYSFS_DECL int PHYSFS_readUBE16(PHYSFS_File *file, PHYSFS_uint16 *val); |
| 1758 | |
| 1759 | |
| 1760 | /** |
| 1761 | * \fn int PHYSFS_readSLE32(PHYSFS_File *file, PHYSFS_sint32 *val) |
| 1762 | * \brief Read and convert a signed 32-bit littleendian value. |
| 1763 | * |
| 1764 | * Convenience function. Read a signed 32-bit littleendian value from a |
| 1765 | * file and convert it to the platform's native byte order. |
| 1766 | * |
| 1767 | * \param file PhysicsFS file handle from which to read. |
| 1768 | * \param val pointer to where value should be stored. |
| 1769 | * \return zero on failure, non-zero on success. If successful, (*val) will |
| 1770 | * store the result. On failure, you can find out what went wrong |
| 1771 | * from PHYSFS_getLastErrorCode(). |
| 1772 | */ |
| 1773 | PHYSFS_DECL int PHYSFS_readSLE32(PHYSFS_File *file, PHYSFS_sint32 *val); |
| 1774 | |
| 1775 | |
| 1776 | /** |
| 1777 | * \fn int PHYSFS_readULE32(PHYSFS_File *file, PHYSFS_uint32 *val) |
| 1778 | * \brief Read and convert an unsigned 32-bit littleendian value. |
| 1779 | * |
| 1780 | * Convenience function. Read an unsigned 32-bit littleendian value from a |
| 1781 | * file and convert it to the platform's native byte order. |
| 1782 | * |
| 1783 | * \param file PhysicsFS file handle from which to read. |
| 1784 | * \param val pointer to where value should be stored. |
| 1785 | * \return zero on failure, non-zero on success. If successful, (*val) will |
| 1786 | * store the result. On failure, you can find out what went wrong |
| 1787 | * from PHYSFS_getLastErrorCode(). |
| 1788 | * |
| 1789 | */ |
| 1790 | PHYSFS_DECL int PHYSFS_readULE32(PHYSFS_File *file, PHYSFS_uint32 *val); |
| 1791 | |
| 1792 | |
| 1793 | /** |
| 1794 | * \fn int PHYSFS_readSBE32(PHYSFS_File *file, PHYSFS_sint32 *val) |
| 1795 | * \brief Read and convert a signed 32-bit bigendian value. |
| 1796 | * |
| 1797 | * Convenience function. Read a signed 32-bit bigendian value from a |
| 1798 | * file and convert it to the platform's native byte order. |
| 1799 | * |
| 1800 | * \param file PhysicsFS file handle from which to read. |
| 1801 | * \param val pointer to where value should be stored. |
| 1802 | * \return zero on failure, non-zero on success. If successful, (*val) will |
| 1803 | * store the result. On failure, you can find out what went wrong |
| 1804 | * from PHYSFS_getLastErrorCode(). |
| 1805 | */ |
| 1806 | PHYSFS_DECL int PHYSFS_readSBE32(PHYSFS_File *file, PHYSFS_sint32 *val); |
| 1807 | |
| 1808 | |
| 1809 | /** |
| 1810 | * \fn int PHYSFS_readUBE32(PHYSFS_File *file, PHYSFS_uint32 *val) |
| 1811 | * \brief Read and convert an unsigned 32-bit bigendian value. |
| 1812 | * |
| 1813 | * Convenience function. Read an unsigned 32-bit bigendian value from a |
| 1814 | * file and convert it to the platform's native byte order. |
| 1815 | * |
| 1816 | * \param file PhysicsFS file handle from which to read. |
| 1817 | * \param val pointer to where value should be stored. |
| 1818 | * \return zero on failure, non-zero on success. If successful, (*val) will |
| 1819 | * store the result. On failure, you can find out what went wrong |
| 1820 | * from PHYSFS_getLastErrorCode(). |
| 1821 | * |
| 1822 | */ |
| 1823 | PHYSFS_DECL int PHYSFS_readUBE32(PHYSFS_File *file, PHYSFS_uint32 *val); |
| 1824 | |
| 1825 | |
| 1826 | /** |
| 1827 | * \fn int PHYSFS_readSLE64(PHYSFS_File *file, PHYSFS_sint64 *val) |
| 1828 | * \brief Read and convert a signed 64-bit littleendian value. |
| 1829 | * |
| 1830 | * Convenience function. Read a signed 64-bit littleendian value from a |
| 1831 | * file and convert it to the platform's native byte order. |
| 1832 | * |
| 1833 | * \param file PhysicsFS file handle from which to read. |
| 1834 | * \param val pointer to where value should be stored. |
| 1835 | * \return zero on failure, non-zero on success. If successful, (*val) will |
| 1836 | * store the result. On failure, you can find out what went wrong |
| 1837 | * from PHYSFS_getLastErrorCode(). |
| 1838 | * |
| 1839 | * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without |
| 1840 | * any sort of 64-bit support. |
| 1841 | */ |
| 1842 | PHYSFS_DECL int PHYSFS_readSLE64(PHYSFS_File *file, PHYSFS_sint64 *val); |
| 1843 | |
| 1844 | |
| 1845 | /** |
| 1846 | * \fn int PHYSFS_readULE64(PHYSFS_File *file, PHYSFS_uint64 *val) |
| 1847 | * \brief Read and convert an unsigned 64-bit littleendian value. |
| 1848 | * |
| 1849 | * Convenience function. Read an unsigned 64-bit littleendian value from a |
| 1850 | * file and convert it to the platform's native byte order. |
| 1851 | * |
| 1852 | * \param file PhysicsFS file handle from which to read. |
| 1853 | * \param val pointer to where value should be stored. |
| 1854 | * \return zero on failure, non-zero on success. If successful, (*val) will |
| 1855 | * store the result. On failure, you can find out what went wrong |
| 1856 | * from PHYSFS_getLastErrorCode(). |
| 1857 | * |
| 1858 | * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without |
| 1859 | * any sort of 64-bit support. |
| 1860 | */ |
| 1861 | PHYSFS_DECL int PHYSFS_readULE64(PHYSFS_File *file, PHYSFS_uint64 *val); |
| 1862 | |
| 1863 | |
| 1864 | /** |
| 1865 | * \fn int PHYSFS_readSBE64(PHYSFS_File *file, PHYSFS_sint64 *val) |
| 1866 | * \brief Read and convert a signed 64-bit bigendian value. |
| 1867 | * |
| 1868 | * Convenience function. Read a signed 64-bit bigendian value from a |
| 1869 | * file and convert it to the platform's native byte order. |
| 1870 | * |
| 1871 | * \param file PhysicsFS file handle from which to read. |
| 1872 | * \param val pointer to where value should be stored. |
| 1873 | * \return zero on failure, non-zero on success. If successful, (*val) will |
| 1874 | * store the result. On failure, you can find out what went wrong |
| 1875 | * from PHYSFS_getLastErrorCode(). |
| 1876 | * |
| 1877 | * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without |
| 1878 | * any sort of 64-bit support. |
| 1879 | */ |
| 1880 | PHYSFS_DECL int PHYSFS_readSBE64(PHYSFS_File *file, PHYSFS_sint64 *val); |
| 1881 | |
| 1882 | |
| 1883 | /** |
| 1884 | * \fn int PHYSFS_readUBE64(PHYSFS_File *file, PHYSFS_uint64 *val) |
| 1885 | * \brief Read and convert an unsigned 64-bit bigendian value. |
| 1886 | * |
| 1887 | * Convenience function. Read an unsigned 64-bit bigendian value from a |
| 1888 | * file and convert it to the platform's native byte order. |
| 1889 | * |
| 1890 | * \param file PhysicsFS file handle from which to read. |
| 1891 | * \param val pointer to where value should be stored. |
| 1892 | * \return zero on failure, non-zero on success. If successful, (*val) will |
| 1893 | * store the result. On failure, you can find out what went wrong |
| 1894 | * from PHYSFS_getLastErrorCode(). |
| 1895 | * |
| 1896 | * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without |
| 1897 | * any sort of 64-bit support. |
| 1898 | */ |
| 1899 | PHYSFS_DECL int PHYSFS_readUBE64(PHYSFS_File *file, PHYSFS_uint64 *val); |
| 1900 | |
| 1901 | |
| 1902 | /** |
| 1903 | * \fn int PHYSFS_writeSLE16(PHYSFS_File *file, PHYSFS_sint16 val) |
| 1904 | * \brief Convert and write a signed 16-bit littleendian value. |
| 1905 | * |
| 1906 | * Convenience function. Convert a signed 16-bit value from the platform's |
| 1907 | * native byte order to littleendian and write it to a file. |
| 1908 | * |
| 1909 | * \param file PhysicsFS file handle to which to write. |
| 1910 | * \param val Value to convert and write. |
| 1911 | * \return zero on failure, non-zero on success. On failure, you can |
| 1912 | * find out what went wrong from PHYSFS_getLastErrorCode(). |
| 1913 | */ |
| 1914 | PHYSFS_DECL int PHYSFS_writeSLE16(PHYSFS_File *file, PHYSFS_sint16 val); |
| 1915 | |
| 1916 | |
| 1917 | /** |
| 1918 | * \fn int PHYSFS_writeULE16(PHYSFS_File *file, PHYSFS_uint16 val) |
| 1919 | * \brief Convert and write an unsigned 16-bit littleendian value. |
| 1920 | * |
| 1921 | * Convenience function. Convert an unsigned 16-bit value from the platform's |
| 1922 | * native byte order to littleendian and write it to a file. |
| 1923 | * |
| 1924 | * \param file PhysicsFS file handle to which to write. |
| 1925 | * \param val Value to convert and write. |
| 1926 | * \return zero on failure, non-zero on success. On failure, you can |
| 1927 | * find out what went wrong from PHYSFS_getLastErrorCode(). |
| 1928 | */ |
| 1929 | PHYSFS_DECL int PHYSFS_writeULE16(PHYSFS_File *file, PHYSFS_uint16 val); |
| 1930 | |
| 1931 | |
| 1932 | /** |
| 1933 | * \fn int PHYSFS_writeSBE16(PHYSFS_File *file, PHYSFS_sint16 val) |
| 1934 | * \brief Convert and write a signed 16-bit bigendian value. |
| 1935 | * |
| 1936 | * Convenience function. Convert a signed 16-bit value from the platform's |
| 1937 | * native byte order to bigendian and write it to a file. |
| 1938 | * |
| 1939 | * \param file PhysicsFS file handle to which to write. |
| 1940 | * \param val Value to convert and write. |
| 1941 | * \return zero on failure, non-zero on success. On failure, you can |
| 1942 | * find out what went wrong from PHYSFS_getLastErrorCode(). |
| 1943 | */ |
| 1944 | PHYSFS_DECL int PHYSFS_writeSBE16(PHYSFS_File *file, PHYSFS_sint16 val); |
| 1945 | |
| 1946 | |
| 1947 | /** |
| 1948 | * \fn int PHYSFS_writeUBE16(PHYSFS_File *file, PHYSFS_uint16 val) |
| 1949 | * \brief Convert and write an unsigned 16-bit bigendian value. |
| 1950 | * |
| 1951 | * Convenience function. Convert an unsigned 16-bit value from the platform's |
| 1952 | * native byte order to bigendian and write it to a file. |
| 1953 | * |
| 1954 | * \param file PhysicsFS file handle to which to write. |
| 1955 | * \param val Value to convert and write. |
| 1956 | * \return zero on failure, non-zero on success. On failure, you can |
| 1957 | * find out what went wrong from PHYSFS_getLastErrorCode(). |
| 1958 | */ |
| 1959 | PHYSFS_DECL int PHYSFS_writeUBE16(PHYSFS_File *file, PHYSFS_uint16 val); |
| 1960 | |
| 1961 | |
| 1962 | /** |
| 1963 | * \fn int PHYSFS_writeSLE32(PHYSFS_File *file, PHYSFS_sint32 val) |
| 1964 | * \brief Convert and write a signed 32-bit littleendian value. |
| 1965 | * |
| 1966 | * Convenience function. Convert a signed 32-bit value from the platform's |
| 1967 | * native byte order to littleendian and write it to a file. |
| 1968 | * |
| 1969 | * \param file PhysicsFS file handle to which to write. |
| 1970 | * \param val Value to convert and write. |
| 1971 | * \return zero on failure, non-zero on success. On failure, you can |
| 1972 | * find out what went wrong from PHYSFS_getLastErrorCode(). |
| 1973 | */ |
| 1974 | PHYSFS_DECL int PHYSFS_writeSLE32(PHYSFS_File *file, PHYSFS_sint32 val); |
| 1975 | |
| 1976 | |
| 1977 | /** |
| 1978 | * \fn int PHYSFS_writeULE32(PHYSFS_File *file, PHYSFS_uint32 val) |
| 1979 | * \brief Convert and write an unsigned 32-bit littleendian value. |
| 1980 | * |
| 1981 | * Convenience function. Convert an unsigned 32-bit value from the platform's |
| 1982 | * native byte order to littleendian and write it to a file. |
| 1983 | * |
| 1984 | * \param file PhysicsFS file handle to which to write. |
| 1985 | * \param val Value to convert and write. |
| 1986 | * \return zero on failure, non-zero on success. On failure, you can |
| 1987 | * find out what went wrong from PHYSFS_getLastErrorCode(). |
| 1988 | */ |
| 1989 | PHYSFS_DECL int PHYSFS_writeULE32(PHYSFS_File *file, PHYSFS_uint32 val); |
| 1990 | |
| 1991 | |
| 1992 | /** |
| 1993 | * \fn int PHYSFS_writeSBE32(PHYSFS_File *file, PHYSFS_sint32 val) |
| 1994 | * \brief Convert and write a signed 32-bit bigendian value. |
| 1995 | * |
| 1996 | * Convenience function. Convert a signed 32-bit value from the platform's |
| 1997 | * native byte order to bigendian and write it to a file. |
| 1998 | * |
| 1999 | * \param file PhysicsFS file handle to which to write. |
| 2000 | * \param val Value to convert and write. |
| 2001 | * \return zero on failure, non-zero on success. On failure, you can |
| 2002 | * find out what went wrong from PHYSFS_getLastErrorCode(). |
| 2003 | */ |
| 2004 | PHYSFS_DECL int PHYSFS_writeSBE32(PHYSFS_File *file, PHYSFS_sint32 val); |
| 2005 | |
| 2006 | |
| 2007 | /** |
| 2008 | * \fn int PHYSFS_writeUBE32(PHYSFS_File *file, PHYSFS_uint32 val) |
| 2009 | * \brief Convert and write an unsigned 32-bit bigendian value. |
| 2010 | * |
| 2011 | * Convenience function. Convert an unsigned 32-bit value from the platform's |
| 2012 | * native byte order to bigendian and write it to a file. |
| 2013 | * |
| 2014 | * \param file PhysicsFS file handle to which to write. |
| 2015 | * \param val Value to convert and write. |
| 2016 | * \return zero on failure, non-zero on success. On failure, you can |
| 2017 | * find out what went wrong from PHYSFS_getLastErrorCode(). |
| 2018 | */ |
| 2019 | PHYSFS_DECL int PHYSFS_writeUBE32(PHYSFS_File *file, PHYSFS_uint32 val); |
| 2020 | |
| 2021 | |
| 2022 | /** |
| 2023 | * \fn int PHYSFS_writeSLE64(PHYSFS_File *file, PHYSFS_sint64 val) |
| 2024 | * \brief Convert and write a signed 64-bit littleendian value. |
| 2025 | * |
| 2026 | * Convenience function. Convert a signed 64-bit value from the platform's |
| 2027 | * native byte order to littleendian and write it to a file. |
| 2028 | * |
| 2029 | * \param file PhysicsFS file handle to which to write. |
| 2030 | * \param val Value to convert and write. |
| 2031 | * \return zero on failure, non-zero on success. On failure, you can |
| 2032 | * find out what went wrong from PHYSFS_getLastErrorCode(). |
| 2033 | * |
| 2034 | * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without |
| 2035 | * any sort of 64-bit support. |
| 2036 | */ |
| 2037 | PHYSFS_DECL int PHYSFS_writeSLE64(PHYSFS_File *file, PHYSFS_sint64 val); |
| 2038 | |
| 2039 | |
| 2040 | /** |
| 2041 | * \fn int PHYSFS_writeULE64(PHYSFS_File *file, PHYSFS_uint64 val) |
| 2042 | * \brief Convert and write an unsigned 64-bit littleendian value. |
| 2043 | * |
| 2044 | * Convenience function. Convert an unsigned 64-bit value from the platform's |
| 2045 | * native byte order to littleendian and write it to a file. |
| 2046 | * |
| 2047 | * \param file PhysicsFS file handle to which to write. |
| 2048 | * \param val Value to convert and write. |
| 2049 | * \return zero on failure, non-zero on success. On failure, you can |
| 2050 | * find out what went wrong from PHYSFS_getLastErrorCode(). |
| 2051 | * |
| 2052 | * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without |
| 2053 | * any sort of 64-bit support. |
| 2054 | */ |
| 2055 | PHYSFS_DECL int PHYSFS_writeULE64(PHYSFS_File *file, PHYSFS_uint64 val); |
| 2056 | |
| 2057 | |
| 2058 | /** |
| 2059 | * \fn int PHYSFS_writeSBE64(PHYSFS_File *file, PHYSFS_sint64 val) |
| 2060 | * \brief Convert and write a signed 64-bit bigending value. |
| 2061 | * |
| 2062 | * Convenience function. Convert a signed 64-bit value from the platform's |
| 2063 | * native byte order to bigendian and write it to a file. |
| 2064 | * |
| 2065 | * \param file PhysicsFS file handle to which to write. |
| 2066 | * \param val Value to convert and write. |
| 2067 | * \return zero on failure, non-zero on success. On failure, you can |
| 2068 | * find out what went wrong from PHYSFS_getLastErrorCode(). |
| 2069 | * |
| 2070 | * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without |
| 2071 | * any sort of 64-bit support. |
| 2072 | */ |
| 2073 | PHYSFS_DECL int PHYSFS_writeSBE64(PHYSFS_File *file, PHYSFS_sint64 val); |
| 2074 | |
| 2075 | |
| 2076 | /** |
| 2077 | * \fn int PHYSFS_writeUBE64(PHYSFS_File *file, PHYSFS_uint64 val) |
| 2078 | * \brief Convert and write an unsigned 64-bit bigendian value. |
| 2079 | * |
| 2080 | * Convenience function. Convert an unsigned 64-bit value from the platform's |
| 2081 | * native byte order to bigendian and write it to a file. |
| 2082 | * |
| 2083 | * \param file PhysicsFS file handle to which to write. |
| 2084 | * \param val Value to convert and write. |
| 2085 | * \return zero on failure, non-zero on success. On failure, you can |
| 2086 | * find out what went wrong from PHYSFS_getLastErrorCode(). |
| 2087 | * |
| 2088 | * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without |
| 2089 | * any sort of 64-bit support. |
| 2090 | */ |
| 2091 | PHYSFS_DECL int PHYSFS_writeUBE64(PHYSFS_File *file, PHYSFS_uint64 val); |
| 2092 | |
| 2093 | |
| 2094 | /* Everything above this line is part of the PhysicsFS 1.0 API. */ |
| 2095 | |
| 2096 | /** |
| 2097 | * \fn int PHYSFS_isInit(void) |
| 2098 | * \brief Determine if the PhysicsFS library is initialized. |
| 2099 | * |
| 2100 | * Once PHYSFS_init() returns successfully, this will return non-zero. |
| 2101 | * Before a successful PHYSFS_init() and after PHYSFS_deinit() returns |
| 2102 | * successfully, this will return zero. This function is safe to call at |
| 2103 | * any time. |
| 2104 | * |
| 2105 | * \return non-zero if library is initialized, zero if library is not. |
| 2106 | * |
| 2107 | * \sa PHYSFS_init |
| 2108 | * \sa PHYSFS_deinit |
| 2109 | */ |
| 2110 | PHYSFS_DECL int PHYSFS_isInit(void); |
| 2111 | |
| 2112 | |
| 2113 | /** |
| 2114 | * \fn int PHYSFS_symbolicLinksPermitted(void) |
| 2115 | * \brief Determine if the symbolic links are permitted. |
| 2116 | * |
| 2117 | * This reports the setting from the last call to PHYSFS_permitSymbolicLinks(). |
| 2118 | * If PHYSFS_permitSymbolicLinks() hasn't been called since the library was |
| 2119 | * last initialized, symbolic links are implicitly disabled. |
| 2120 | * |
| 2121 | * \return non-zero if symlinks are permitted, zero if not. |
| 2122 | * |
| 2123 | * \sa PHYSFS_permitSymbolicLinks |
| 2124 | */ |
| 2125 | PHYSFS_DECL int PHYSFS_symbolicLinksPermitted(void); |
| 2126 | |
| 2127 | |
| 2128 | /** |
| 2129 | * \struct PHYSFS_Allocator |
| 2130 | * \brief PhysicsFS allocation function pointers. |
| 2131 | * |
| 2132 | * (This is for limited, hardcore use. If you don't immediately see a need |
| 2133 | * for it, you can probably ignore this forever.) |
| 2134 | * |
| 2135 | * You create one of these structures for use with PHYSFS_setAllocator. |
| 2136 | * Allocators are assumed to be reentrant by the caller; please mutex |
| 2137 | * accordingly. |
| 2138 | * |
| 2139 | * Allocations are always discussed in 64-bits, for future expansion...we're |
| 2140 | * on the cusp of a 64-bit transition, and we'll probably be allocating 6 |
| 2141 | * gigabytes like it's nothing sooner or later, and I don't want to change |
| 2142 | * this again at that point. If you're on a 32-bit platform and have to |
| 2143 | * downcast, it's okay to return NULL if the allocation is greater than |
| 2144 | * 4 gigabytes, since you'd have to do so anyhow. |
| 2145 | * |
| 2146 | * \sa PHYSFS_setAllocator |
| 2147 | */ |
| 2148 | typedef struct PHYSFS_Allocator |
| 2149 | { |
| 2150 | int (*Init)(void); /**< Initialize. Can be NULL. Zero on failure. */ |
| 2151 | void (*Deinit)(void); /**< Deinitialize your allocator. Can be NULL. */ |
| 2152 | void *(*Malloc)(PHYSFS_uint64); /**< Allocate like malloc(). */ |
| 2153 | void *(*Realloc)(void *, PHYSFS_uint64); /**< Reallocate like realloc(). */ |
| 2154 | void (*Free)(void *); /**< Free memory from Malloc or Realloc. */ |
| 2155 | } PHYSFS_Allocator; |
| 2156 | |
| 2157 | |
| 2158 | /** |
| 2159 | * \fn int PHYSFS_setAllocator(const PHYSFS_Allocator *allocator) |
| 2160 | * \brief Hook your own allocation routines into PhysicsFS. |
| 2161 | * |
| 2162 | * (This is for limited, hardcore use. If you don't immediately see a need |
| 2163 | * for it, you can probably ignore this forever.) |
| 2164 | * |
| 2165 | * By default, PhysicsFS will use whatever is reasonable for a platform |
| 2166 | * to manage dynamic memory (usually ANSI C malloc/realloc/free, but |
| 2167 | * some platforms might use something else), but in some uncommon cases, the |
| 2168 | * app might want more control over the library's memory management. This |
| 2169 | * lets you redirect PhysicsFS to use your own allocation routines instead. |
| 2170 | * You can only call this function before PHYSFS_init(); if the library is |
| 2171 | * initialized, it'll reject your efforts to change the allocator mid-stream. |
| 2172 | * You may call this function after PHYSFS_deinit() if you are willing to |
| 2173 | * shut down the library and restart it with a new allocator; this is a safe |
| 2174 | * and supported operation. The allocator remains intact between deinit/init |
| 2175 | * calls. If you want to return to the platform's default allocator, pass a |
| 2176 | * NULL in here. |
| 2177 | * |
| 2178 | * If you aren't immediately sure what to do with this function, you can |
| 2179 | * safely ignore it altogether. |
| 2180 | * |
| 2181 | * \param allocator Structure containing your allocator's entry points. |
| 2182 | * \return zero on failure, non-zero on success. This call only fails |
| 2183 | * when used between PHYSFS_init() and PHYSFS_deinit() calls. |
| 2184 | */ |
| 2185 | PHYSFS_DECL int PHYSFS_setAllocator(const PHYSFS_Allocator *allocator); |
| 2186 | |
| 2187 | |
| 2188 | /** |
| 2189 | * \fn int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath) |
| 2190 | * \brief Add an archive or directory to the search path. |
| 2191 | * |
| 2192 | * If this is a duplicate, the entry is not added again, even though the |
| 2193 | * function succeeds. You may not add the same archive to two different |
| 2194 | * mountpoints: duplicate checking is done against the archive and not the |
| 2195 | * mountpoint. |
| 2196 | * |
| 2197 | * When you mount an archive, it is added to a virtual file system...all files |
| 2198 | * in all of the archives are interpolated into a single hierachical file |
| 2199 | * tree. Two archives mounted at the same place (or an archive with files |
| 2200 | * overlapping another mountpoint) may have overlapping files: in such a case, |
| 2201 | * the file earliest in the search path is selected, and the other files are |
| 2202 | * inaccessible to the application. This allows archives to be used to |
| 2203 | * override previous revisions; you can use the mounting mechanism to place |
| 2204 | * archives at a specific point in the file tree and prevent overlap; this |
| 2205 | * is useful for downloadable mods that might trample over application data |
| 2206 | * or each other, for example. |
| 2207 | * |
| 2208 | * The mountpoint does not need to exist prior to mounting, which is different |
| 2209 | * than those familiar with the Unix concept of "mounting" may expect. |
| 2210 | * As well, more than one archive can be mounted to the same mountpoint, or |
| 2211 | * mountpoints and archive contents can overlap...the interpolation mechanism |
| 2212 | * still functions as usual. |
| 2213 | * |
| 2214 | * Specifying a symbolic link to an archive or directory is allowed here, |
| 2215 | * regardless of the state of PHYSFS_permitSymbolicLinks(). That function |
| 2216 | * only deals with symlinks inside the mounted directory or archive. |
| 2217 | * |
| 2218 | * \param newDir directory or archive to add to the path, in |
| 2219 | * platform-dependent notation. |
| 2220 | * \param mountPoint Location in the interpolated tree that this archive |
| 2221 | * will be "mounted", in platform-independent notation. |
| 2222 | * NULL or "" is equivalent to "/". |
| 2223 | * \param appendToPath nonzero to append to search path, zero to prepend. |
| 2224 | * \return nonzero if added to path, zero on failure (bogus archive, dir |
| 2225 | * missing, etc). Use PHYSFS_getLastErrorCode() to obtain |
| 2226 | * the specific error. |
| 2227 | * |
| 2228 | * \sa PHYSFS_removeFromSearchPath |
| 2229 | * \sa PHYSFS_getSearchPath |
| 2230 | * \sa PHYSFS_getMountPoint |
| 2231 | * \sa PHYSFS_mountIo |
| 2232 | */ |
| 2233 | PHYSFS_DECL int PHYSFS_mount(const char *newDir, |
| 2234 | const char *mountPoint, |
| 2235 | int appendToPath); |
| 2236 | |
| 2237 | /** |
| 2238 | * \fn int PHYSFS_getMountPoint(const char *dir) |
| 2239 | * \brief Determine a mounted archive's mountpoint. |
| 2240 | * |
| 2241 | * You give this function the name of an archive or dir you successfully |
| 2242 | * added to the search path, and it reports the location in the interpolated |
| 2243 | * tree where it is mounted. Files mounted with a NULL mountpoint or through |
| 2244 | * PHYSFS_addToSearchPath() will report "/". The return value is READ ONLY |
| 2245 | * and valid until the archive is removed from the search path. |
| 2246 | * |
| 2247 | * \param dir directory or archive previously added to the path, in |
| 2248 | * platform-dependent notation. This must match the string |
| 2249 | * used when adding, even if your string would also reference |
| 2250 | * the same file with a different string of characters. |
| 2251 | * \return READ-ONLY string of mount point if added to path, NULL on failure |
| 2252 | * (bogus archive, etc). Use PHYSFS_getLastErrorCode() to obtain the |
| 2253 | * specific error. |
| 2254 | * |
| 2255 | * \sa PHYSFS_removeFromSearchPath |
| 2256 | * \sa PHYSFS_getSearchPath |
| 2257 | * \sa PHYSFS_getMountPoint |
| 2258 | */ |
| 2259 | PHYSFS_DECL const char *PHYSFS_getMountPoint(const char *dir); |
| 2260 | |
| 2261 | |
| 2262 | /** |
| 2263 | * \typedef PHYSFS_StringCallback |
| 2264 | * \brief Function signature for callbacks that report strings. |
| 2265 | * |
| 2266 | * These are used to report a list of strings to an original caller, one |
| 2267 | * string per callback. All strings are UTF-8 encoded. Functions should not |
| 2268 | * try to modify or free the string's memory. |
| 2269 | * |
| 2270 | * These callbacks are used, starting in PhysicsFS 1.1, as an alternative to |
| 2271 | * functions that would return lists that need to be cleaned up with |
| 2272 | * PHYSFS_freeList(). The callback means that the library doesn't need to |
| 2273 | * allocate an entire list and all the strings up front. |
| 2274 | * |
| 2275 | * Be aware that promises data ordering in the list versions are not |
| 2276 | * necessarily so in the callback versions. Check the documentation on |
| 2277 | * specific APIs, but strings may not be sorted as you expect. |
| 2278 | * |
| 2279 | * \param data User-defined data pointer, passed through from the API |
| 2280 | * that eventually called the callback. |
| 2281 | * \param str The string data about which the callback is meant to inform. |
| 2282 | * |
| 2283 | * \sa PHYSFS_getCdRomDirsCallback |
| 2284 | * \sa PHYSFS_getSearchPathCallback |
| 2285 | */ |
| 2286 | typedef void (*PHYSFS_StringCallback)(void *data, const char *str); |
| 2287 | |
| 2288 | |
| 2289 | /** |
| 2290 | * \typedef PHYSFS_EnumFilesCallback |
| 2291 | * \brief Function signature for callbacks that enumerate files. |
| 2292 | * |
| 2293 | * \warning As of PhysicsFS 2.1, Use PHYSFS_EnumerateCallback with |
| 2294 | * PHYSFS_enumerate() instead; it gives you more control over the process. |
| 2295 | * |
| 2296 | * These are used to report a list of directory entries to an original caller, |
| 2297 | * one file/dir/symlink per callback. All strings are UTF-8 encoded. |
| 2298 | * Functions should not try to modify or free any string's memory. |
| 2299 | * |
| 2300 | * These callbacks are used, starting in PhysicsFS 1.1, as an alternative to |
| 2301 | * functions that would return lists that need to be cleaned up with |
| 2302 | * PHYSFS_freeList(). The callback means that the library doesn't need to |
| 2303 | * allocate an entire list and all the strings up front. |
| 2304 | * |
| 2305 | * Be aware that promised data ordering in the list versions are not |
| 2306 | * necessarily so in the callback versions. Check the documentation on |
| 2307 | * specific APIs, but strings may not be sorted as you expect and you might |
| 2308 | * get duplicate strings. |
| 2309 | * |
| 2310 | * \param data User-defined data pointer, passed through from the API |
| 2311 | * that eventually called the callback. |
| 2312 | * \param origdir A string containing the full path, in platform-independent |
| 2313 | * notation, of the directory containing this file. In most |
| 2314 | * cases, this is the directory on which you requested |
| 2315 | * enumeration, passed in the callback for your convenience. |
| 2316 | * \param fname The filename that is being enumerated. It may not be in |
| 2317 | * alphabetical order compared to other callbacks that have |
| 2318 | * fired, and it will not contain the full path. You can |
| 2319 | * recreate the fullpath with $origdir/$fname ... The file |
| 2320 | * can be a subdirectory, a file, a symlink, etc. |
| 2321 | * |
| 2322 | * \sa PHYSFS_enumerateFilesCallback |
| 2323 | */ |
| 2324 | typedef void (*PHYSFS_EnumFilesCallback)(void *data, const char *origdir, |
| 2325 | const char *fname); |
| 2326 | |
| 2327 | |
| 2328 | /** |
| 2329 | * \fn void PHYSFS_getCdRomDirsCallback(PHYSFS_StringCallback c, void *d) |
| 2330 | * \brief Enumerate CD-ROM directories, using an application-defined callback. |
| 2331 | * |
| 2332 | * Internally, PHYSFS_getCdRomDirs() just calls this function and then builds |
| 2333 | * a list before returning to the application, so functionality is identical |
| 2334 | * except for how the information is represented to the application. |
| 2335 | * |
| 2336 | * Unlike PHYSFS_getCdRomDirs(), this function does not return an array. |
| 2337 | * Rather, it calls a function specified by the application once per |
| 2338 | * detected disc: |
| 2339 | * |
| 2340 | * \code |
| 2341 | * |
| 2342 | * static void foundDisc(void *data, const char *cddir) |
| 2343 | * { |
| 2344 | * printf("cdrom dir [%s] is available.\n", cddir); |
| 2345 | * } |
| 2346 | * |
| 2347 | * // ... |
| 2348 | * PHYSFS_getCdRomDirsCallback(foundDisc, NULL); |
| 2349 | * \endcode |
| 2350 | * |
| 2351 | * This call may block while drives spin up. Be forewarned. |
| 2352 | * |
| 2353 | * \param c Callback function to notify about detected drives. |
| 2354 | * \param d Application-defined data passed to callback. Can be NULL. |
| 2355 | * |
| 2356 | * \sa PHYSFS_StringCallback |
| 2357 | * \sa PHYSFS_getCdRomDirs |
| 2358 | */ |
| 2359 | PHYSFS_DECL void PHYSFS_getCdRomDirsCallback(PHYSFS_StringCallback c, void *d); |
| 2360 | |
| 2361 | |
| 2362 | /** |
| 2363 | * \fn void PHYSFS_getSearchPathCallback(PHYSFS_StringCallback c, void *d) |
| 2364 | * \brief Enumerate the search path, using an application-defined callback. |
| 2365 | * |
| 2366 | * Internally, PHYSFS_getSearchPath() just calls this function and then builds |
| 2367 | * a list before returning to the application, so functionality is identical |
| 2368 | * except for how the information is represented to the application. |
| 2369 | * |
| 2370 | * Unlike PHYSFS_getSearchPath(), this function does not return an array. |
| 2371 | * Rather, it calls a function specified by the application once per |
| 2372 | * element of the search path: |
| 2373 | * |
| 2374 | * \code |
| 2375 | * |
| 2376 | * static void printSearchPath(void *data, const char *pathItem) |
| 2377 | * { |
| 2378 | * printf("[%s] is in the search path.\n", pathItem); |
| 2379 | * } |
| 2380 | * |
| 2381 | * // ... |
| 2382 | * PHYSFS_getSearchPathCallback(printSearchPath, NULL); |
| 2383 | * \endcode |
| 2384 | * |
| 2385 | * Elements of the search path are reported in order search priority, so the |
| 2386 | * first archive/dir that would be examined when looking for a file is the |
| 2387 | * first element passed through the callback. |
| 2388 | * |
| 2389 | * \param c Callback function to notify about search path elements. |
| 2390 | * \param d Application-defined data passed to callback. Can be NULL. |
| 2391 | * |
| 2392 | * \sa PHYSFS_StringCallback |
| 2393 | * \sa PHYSFS_getSearchPath |
| 2394 | */ |
| 2395 | PHYSFS_DECL void PHYSFS_getSearchPathCallback(PHYSFS_StringCallback c, void *d); |
| 2396 | |
| 2397 | |
| 2398 | /** |
| 2399 | * \fn void PHYSFS_enumerateFilesCallback(const char *dir, PHYSFS_EnumFilesCallback c, void *d) |
| 2400 | * \brief Get a file listing of a search path's directory, using an application-defined callback. |
| 2401 | * |
| 2402 | * \deprecated As of PhysicsFS 2.1, use PHYSFS_enumerate() instead. This |
| 2403 | * function has no way to report errors (or to have the callback signal an |
| 2404 | * error or request a stop), so if data will be lost, your callback has no |
| 2405 | * way to direct the process, and your calling app has no way to know. |
| 2406 | * |
| 2407 | * As of PhysicsFS 2.1, this function just wraps PHYSFS_enumerate() and |
| 2408 | * ignores errors. Consider using PHYSFS_enumerate() or |
| 2409 | * PHYSFS_enumerateFiles() instead. |
| 2410 | * |
| 2411 | * \sa PHYSFS_enumerate |
| 2412 | * \sa PHYSFS_enumerateFiles |
| 2413 | * \sa PHYSFS_EnumFilesCallback |
| 2414 | */ |
| 2415 | PHYSFS_DECL void PHYSFS_enumerateFilesCallback(const char *dir, |
| 2416 | PHYSFS_EnumFilesCallback c, |
| 2417 | void *d) PHYSFS_DEPRECATED; |
| 2418 | |
| 2419 | /** |
| 2420 | * \fn void PHYSFS_utf8FromUcs4(const PHYSFS_uint32 *src, char *dst, PHYSFS_uint64 len) |
| 2421 | * \brief Convert a UCS-4 string to a UTF-8 string. |
| 2422 | * |
| 2423 | * \warning This function will not report an error if there are invalid UCS-4 |
| 2424 | * values in the source string. It will replace them with a '?' |
| 2425 | * character and continue on. |
| 2426 | * |
| 2427 | * UCS-4 (aka UTF-32) strings are 32-bits per character: \c wchar_t on Unix. |
| 2428 | * |
| 2429 | * To ensure that the destination buffer is large enough for the conversion, |
| 2430 | * please allocate a buffer that is the same size as the source buffer. UTF-8 |
| 2431 | * never uses more than 32-bits per character, so while it may shrink a UCS-4 |
| 2432 | * string, it will never expand it. |
| 2433 | * |
| 2434 | * Strings that don't fit in the destination buffer will be truncated, but |
| 2435 | * will always be null-terminated and never have an incomplete UTF-8 |
| 2436 | * sequence at the end. If the buffer length is 0, this function does nothing. |
| 2437 | * |
| 2438 | * \param src Null-terminated source string in UCS-4 format. |
| 2439 | * \param dst Buffer to store converted UTF-8 string. |
| 2440 | * \param len Size, in bytes, of destination buffer. |
| 2441 | */ |
| 2442 | PHYSFS_DECL void PHYSFS_utf8FromUcs4(const PHYSFS_uint32 *src, char *dst, |
| 2443 | PHYSFS_uint64 len); |
| 2444 | |
| 2445 | /** |
| 2446 | * \fn void PHYSFS_utf8ToUcs4(const char *src, PHYSFS_uint32 *dst, PHYSFS_uint64 len) |
| 2447 | * \brief Convert a UTF-8 string to a UCS-4 string. |
| 2448 | * |
| 2449 | * \warning This function will not report an error if there are invalid UTF-8 |
| 2450 | * sequences in the source string. It will replace them with a '?' |
| 2451 | * character and continue on. |
| 2452 | * |
| 2453 | * UCS-4 (aka UTF-32) strings are 32-bits per character: \c wchar_t on Unix. |
| 2454 | * |
| 2455 | * To ensure that the destination buffer is large enough for the conversion, |
| 2456 | * please allocate a buffer that is four times the size of the source buffer. |
| 2457 | * UTF-8 uses from one to four bytes per character, but UCS-4 always uses |
| 2458 | * four, so an entirely low-ASCII string will quadruple in size! |
| 2459 | * |
| 2460 | * Strings that don't fit in the destination buffer will be truncated, but |
| 2461 | * will always be null-terminated and never have an incomplete UCS-4 |
| 2462 | * sequence at the end. If the buffer length is 0, this function does nothing. |
| 2463 | * |
| 2464 | * \param src Null-terminated source string in UTF-8 format. |
| 2465 | * \param dst Buffer to store converted UCS-4 string. |
| 2466 | * \param len Size, in bytes, of destination buffer. |
| 2467 | */ |
| 2468 | PHYSFS_DECL void PHYSFS_utf8ToUcs4(const char *src, PHYSFS_uint32 *dst, |
| 2469 | PHYSFS_uint64 len); |
| 2470 | |
| 2471 | /** |
| 2472 | * \fn void PHYSFS_utf8FromUcs2(const PHYSFS_uint16 *src, char *dst, PHYSFS_uint64 len) |
| 2473 | * \brief Convert a UCS-2 string to a UTF-8 string. |
| 2474 | * |
| 2475 | * \warning you almost certainly should use PHYSFS_utf8FromUtf16(), which |
| 2476 | * became available in PhysicsFS 2.1, unless you know what you're doing. |
| 2477 | * |
| 2478 | * \warning This function will not report an error if there are invalid UCS-2 |
| 2479 | * values in the source string. It will replace them with a '?' |
| 2480 | * character and continue on. |
| 2481 | * |
| 2482 | * UCS-2 strings are 16-bits per character: \c TCHAR on Windows, when building |
| 2483 | * with Unicode support. Please note that modern versions of Windows use |
| 2484 | * UTF-16, which is an extended form of UCS-2, and not UCS-2 itself. You |
| 2485 | * almost certainly want PHYSFS_utf8FromUtf16() instead. |
| 2486 | * |
| 2487 | * To ensure that the destination buffer is large enough for the conversion, |
| 2488 | * please allocate a buffer that is double the size of the source buffer. |
| 2489 | * UTF-8 never uses more than 32-bits per character, so while it may shrink |
| 2490 | * a UCS-2 string, it may also expand it. |
| 2491 | * |
| 2492 | * Strings that don't fit in the destination buffer will be truncated, but |
| 2493 | * will always be null-terminated and never have an incomplete UTF-8 |
| 2494 | * sequence at the end. If the buffer length is 0, this function does nothing. |
| 2495 | * |
| 2496 | * \param src Null-terminated source string in UCS-2 format. |
| 2497 | * \param dst Buffer to store converted UTF-8 string. |
| 2498 | * \param len Size, in bytes, of destination buffer. |
| 2499 | * |
| 2500 | * \sa PHYSFS_utf8FromUtf16 |
| 2501 | */ |
| 2502 | PHYSFS_DECL void PHYSFS_utf8FromUcs2(const PHYSFS_uint16 *src, char *dst, |
| 2503 | PHYSFS_uint64 len); |
| 2504 | |
| 2505 | /** |
| 2506 | * \fn PHYSFS_utf8ToUcs2(const char *src, PHYSFS_uint16 *dst, PHYSFS_uint64 len) |
| 2507 | * \brief Convert a UTF-8 string to a UCS-2 string. |
| 2508 | * |
| 2509 | * \warning you almost certainly should use PHYSFS_utf8ToUtf16(), which |
| 2510 | * became available in PhysicsFS 2.1, unless you know what you're doing. |
| 2511 | * |
| 2512 | * \warning This function will not report an error if there are invalid UTF-8 |
| 2513 | * sequences in the source string. It will replace them with a '?' |
| 2514 | * character and continue on. |
| 2515 | * |
| 2516 | * UCS-2 strings are 16-bits per character: \c TCHAR on Windows, when building |
| 2517 | * with Unicode support. Please note that modern versions of Windows use |
| 2518 | * UTF-16, which is an extended form of UCS-2, and not UCS-2 itself. You |
| 2519 | * almost certainly want PHYSFS_utf8ToUtf16() instead, but you need to |
| 2520 | * understand how that changes things, too. |
| 2521 | * |
| 2522 | * To ensure that the destination buffer is large enough for the conversion, |
| 2523 | * please allocate a buffer that is double the size of the source buffer. |
| 2524 | * UTF-8 uses from one to four bytes per character, but UCS-2 always uses |
| 2525 | * two, so an entirely low-ASCII string will double in size! |
| 2526 | * |
| 2527 | * Strings that don't fit in the destination buffer will be truncated, but |
| 2528 | * will always be null-terminated and never have an incomplete UCS-2 |
| 2529 | * sequence at the end. If the buffer length is 0, this function does nothing. |
| 2530 | * |
| 2531 | * \param src Null-terminated source string in UTF-8 format. |
| 2532 | * \param dst Buffer to store converted UCS-2 string. |
| 2533 | * \param len Size, in bytes, of destination buffer. |
| 2534 | * |
| 2535 | * \sa PHYSFS_utf8ToUtf16 |
| 2536 | */ |
| 2537 | PHYSFS_DECL void PHYSFS_utf8ToUcs2(const char *src, PHYSFS_uint16 *dst, |
| 2538 | PHYSFS_uint64 len); |
| 2539 | |
| 2540 | /** |
| 2541 | * \fn void PHYSFS_utf8FromLatin1(const char *src, char *dst, PHYSFS_uint64 len) |
| 2542 | * \brief Convert a UTF-8 string to a Latin1 string. |
| 2543 | * |
| 2544 | * Latin1 strings are 8-bits per character: a popular "high ASCII" encoding. |
| 2545 | * |
| 2546 | * To ensure that the destination buffer is large enough for the conversion, |
| 2547 | * please allocate a buffer that is double the size of the source buffer. |
| 2548 | * UTF-8 expands latin1 codepoints over 127 from 1 to 2 bytes, so the string |
| 2549 | * may grow in some cases. |
| 2550 | * |
| 2551 | * Strings that don't fit in the destination buffer will be truncated, but |
| 2552 | * will always be null-terminated and never have an incomplete UTF-8 |
| 2553 | * sequence at the end. If the buffer length is 0, this function does nothing. |
| 2554 | * |
| 2555 | * Please note that we do not supply a UTF-8 to Latin1 converter, since Latin1 |
| 2556 | * can't express most Unicode codepoints. It's a legacy encoding; you should |
| 2557 | * be converting away from it at all times. |
| 2558 | * |
| 2559 | * \param src Null-terminated source string in Latin1 format. |
| 2560 | * \param dst Buffer to store converted UTF-8 string. |
| 2561 | * \param len Size, in bytes, of destination buffer. |
| 2562 | */ |
| 2563 | PHYSFS_DECL void PHYSFS_utf8FromLatin1(const char *src, char *dst, |
| 2564 | PHYSFS_uint64 len); |
| 2565 | |
| 2566 | /* Everything above this line is part of the PhysicsFS 2.0 API. */ |
| 2567 | |
| 2568 | /** |
| 2569 | * \fn int PHYSFS_caseFold(const PHYSFS_uint32 from, PHYSFS_uint32 *to) |
| 2570 | * \brief "Fold" a Unicode codepoint to a lowercase equivalent. |
| 2571 | * |
| 2572 | * (This is for limited, hardcore use. If you don't immediately see a need |
| 2573 | * for it, you can probably ignore this forever.) |
| 2574 | * |
| 2575 | * This will convert a Unicode codepoint into its lowercase equivalent. |
| 2576 | * Bogus codepoints and codepoints without a lowercase equivalent will |
| 2577 | * be returned unconverted. |
| 2578 | * |
| 2579 | * Note that you might get multiple codepoints in return! The German Eszett, |
| 2580 | * for example, will fold down to two lowercase latin 's' codepoints. The |
| 2581 | * theory is that if you fold two strings, one with an Eszett and one with |
| 2582 | * "SS" down, they will match. |
| 2583 | * |
| 2584 | * \warning Anyone that is a student of Unicode knows about the "Turkish I" |
| 2585 | * problem. This API does not handle it. Assume this one letter |
| 2586 | * in all of Unicode will definitely fold sort of incorrectly. If |
| 2587 | * you don't know what this is about, you can probably ignore this |
| 2588 | * problem for most of the planet, but perfection is impossible. |
| 2589 | * |
| 2590 | * \param from The codepoint to fold. |
| 2591 | * \param to Buffer to store the folded codepoint values into. This should |
| 2592 | * point to space for at least 3 PHYSFS_uint32 slots. |
| 2593 | * \return The number of codepoints the folding produced. Between 1 and 3. |
| 2594 | */ |
| 2595 | PHYSFS_DECL int PHYSFS_caseFold(const PHYSFS_uint32 from, PHYSFS_uint32 *to); |
| 2596 | |
| 2597 | |
| 2598 | /** |
| 2599 | * \fn int PHYSFS_utf8stricmp(const char *str1, const char *str2) |
| 2600 | * \brief Case-insensitive compare of two UTF-8 strings. |
| 2601 | * |
| 2602 | * This is a strcasecmp/stricmp replacement that expects both strings |
| 2603 | * to be in UTF-8 encoding. It will do "case folding" to decide if the |
| 2604 | * Unicode codepoints in the strings match. |
| 2605 | * |
| 2606 | * If both strings are exclusively low-ASCII characters, this will do the |
| 2607 | * right thing, as that is also valid UTF-8. If there are any high-ASCII |
| 2608 | * chars, this will not do what you expect! |
| 2609 | * |
| 2610 | * It will report which string is "greater than" the other, but be aware that |
| 2611 | * this doesn't necessarily mean anything: 'a' may be "less than" 'b', but |
| 2612 | * a Japanese kuten has no meaningful alphabetically relationship to |
| 2613 | * a Greek lambda, but being able to assign a reliable "value" makes sorting |
| 2614 | * algorithms possible, if not entirely sane. Most cases should treat the |
| 2615 | * return value as "equal" or "not equal". |
| 2616 | * |
| 2617 | * Like stricmp, this expects both strings to be NULL-terminated. |
| 2618 | * |
| 2619 | * \param str1 First string to compare. |
| 2620 | * \param str2 Second string to compare. |
| 2621 | * \return -1 if str1 is "less than" str2, 1 if "greater than", 0 if equal. |
| 2622 | */ |
| 2623 | PHYSFS_DECL int PHYSFS_utf8stricmp(const char *str1, const char *str2); |
| 2624 | |
| 2625 | /** |
| 2626 | * \fn int PHYSFS_utf16stricmp(const PHYSFS_uint16 *str1, const PHYSFS_uint16 *str2) |
| 2627 | * \brief Case-insensitive compare of two UTF-16 strings. |
| 2628 | * |
| 2629 | * This is a strcasecmp/stricmp replacement that expects both strings |
| 2630 | * to be in UTF-16 encoding. It will do "case folding" to decide if the |
| 2631 | * Unicode codepoints in the strings match. |
| 2632 | * |
| 2633 | * It will report which string is "greater than" the other, but be aware that |
| 2634 | * this doesn't necessarily mean anything: 'a' may be "less than" 'b', but |
| 2635 | * a Japanese kuten has no meaningful alphabetically relationship to |
| 2636 | * a Greek lambda, but being able to assign a reliable "value" makes sorting |
| 2637 | * algorithms possible, if not entirely sane. Most cases should treat the |
| 2638 | * return value as "equal" or "not equal". |
| 2639 | * |
| 2640 | * Like stricmp, this expects both strings to be NULL-terminated. |
| 2641 | * |
| 2642 | * \param str1 First string to compare. |
| 2643 | * \param str2 Second string to compare. |
| 2644 | * \return -1 if str1 is "less than" str2, 1 if "greater than", 0 if equal. |
| 2645 | */ |
| 2646 | PHYSFS_DECL int PHYSFS_utf16stricmp(const PHYSFS_uint16 *str1, |
| 2647 | const PHYSFS_uint16 *str2); |
| 2648 | |
| 2649 | /** |
| 2650 | * \fn int PHYSFS_ucs4stricmp(const PHYSFS_uint32 *str1, const PHYSFS_uint32 *str2) |
| 2651 | * \brief Case-insensitive compare of two UCS-4 strings. |
| 2652 | * |
| 2653 | * This is a strcasecmp/stricmp replacement that expects both strings |
| 2654 | * to be in UCS-4 (aka UTF-32) encoding. It will do "case folding" to decide |
| 2655 | * if the Unicode codepoints in the strings match. |
| 2656 | * |
| 2657 | * It will report which string is "greater than" the other, but be aware that |
| 2658 | * this doesn't necessarily mean anything: 'a' may be "less than" 'b', but |
| 2659 | * a Japanese kuten has no meaningful alphabetically relationship to |
| 2660 | * a Greek lambda, but being able to assign a reliable "value" makes sorting |
| 2661 | * algorithms possible, if not entirely sane. Most cases should treat the |
| 2662 | * return value as "equal" or "not equal". |
| 2663 | * |
| 2664 | * Like stricmp, this expects both strings to be NULL-terminated. |
| 2665 | * |
| 2666 | * \param str1 First string to compare. |
| 2667 | * \param str2 Second string to compare. |
| 2668 | * \return -1 if str1 is "less than" str2, 1 if "greater than", 0 if equal. |
| 2669 | */ |
| 2670 | PHYSFS_DECL int PHYSFS_ucs4stricmp(const PHYSFS_uint32 *str1, |
| 2671 | const PHYSFS_uint32 *str2); |
| 2672 | |
| 2673 | |
| 2674 | /** |
| 2675 | * \typedef PHYSFS_EnumerateCallback |
| 2676 | * \brief Possible return values from PHYSFS_EnumerateCallback. |
| 2677 | * |
| 2678 | * These values dictate if an enumeration callback should continue to fire, |
| 2679 | * or stop (and why it is stopping). |
| 2680 | * |
| 2681 | * \sa PHYSFS_EnumerateCallback |
| 2682 | * \sa PHYSFS_enumerate |
| 2683 | */ |
| 2684 | typedef enum PHYSFS_EnumerateCallbackResult |
| 2685 | { |
| 2686 | PHYSFS_ENUM_ERROR = -1, /**< Stop enumerating, report error to app. */ |
| 2687 | PHYSFS_ENUM_STOP = 0, /**< Stop enumerating, report success to app. */ |
| 2688 | PHYSFS_ENUM_OK = 1 /**< Keep enumerating, no problems */ |
| 2689 | } PHYSFS_EnumerateCallbackResult; |
| 2690 | |
| 2691 | /** |
| 2692 | * \typedef PHYSFS_EnumerateCallback |
| 2693 | * \brief Function signature for callbacks that enumerate and return results. |
| 2694 | * |
| 2695 | * This is the same thing as PHYSFS_EnumFilesCallback from PhysicsFS 2.0, |
| 2696 | * except it can return a result from the callback: namely: if you're looking |
| 2697 | * for something specific, once you find it, you can tell PhysicsFS to stop |
| 2698 | * enumerating further. This is used with PHYSFS_enumerate(), which we |
| 2699 | * hopefully got right this time. :) |
| 2700 | * |
| 2701 | * \param data User-defined data pointer, passed through from the API |
| 2702 | * that eventually called the callback. |
| 2703 | * \param origdir A string containing the full path, in platform-independent |
| 2704 | * notation, of the directory containing this file. In most |
| 2705 | * cases, this is the directory on which you requested |
| 2706 | * enumeration, passed in the callback for your convenience. |
| 2707 | * \param fname The filename that is being enumerated. It may not be in |
| 2708 | * alphabetical order compared to other callbacks that have |
| 2709 | * fired, and it will not contain the full path. You can |
| 2710 | * recreate the fullpath with $origdir/$fname ... The file |
| 2711 | * can be a subdirectory, a file, a symlink, etc. |
| 2712 | * \return A value from PHYSFS_EnumerateCallbackResult. |
| 2713 | * All other values are (currently) undefined; don't use them. |
| 2714 | * |
| 2715 | * \sa PHYSFS_enumerate |
| 2716 | * \sa PHYSFS_EnumerateCallbackResult |
| 2717 | */ |
| 2718 | typedef PHYSFS_EnumerateCallbackResult (*PHYSFS_EnumerateCallback)(void *data, |
| 2719 | const char *origdir, const char *fname); |
| 2720 | |
| 2721 | /** |
| 2722 | * \fn int PHYSFS_enumerate(const char *dir, PHYSFS_EnumerateCallback c, void *d) |
| 2723 | * \brief Get a file listing of a search path's directory, using an application-defined callback, with errors reported. |
| 2724 | * |
| 2725 | * Internally, PHYSFS_enumerateFiles() just calls this function and then builds |
| 2726 | * a list before returning to the application, so functionality is identical |
| 2727 | * except for how the information is represented to the application. |
| 2728 | * |
| 2729 | * Unlike PHYSFS_enumerateFiles(), this function does not return an array. |
| 2730 | * Rather, it calls a function specified by the application once per |
| 2731 | * element of the search path: |
| 2732 | * |
| 2733 | * \code |
| 2734 | * |
| 2735 | * static PHYSFS_EnumerateCallbackResult printDir(void *data, const char *origdir, const char *fname) |
| 2736 | * { |
| 2737 | * printf(" * We've got [%s] in [%s].\n", fname, origdir); |
| 2738 | * return PHYSFS_ENUM_OK; // give me more data, please. |
| 2739 | * } |
| 2740 | * |
| 2741 | * // ... |
| 2742 | * PHYSFS_enumerate("/some/path", printDir, NULL); |
| 2743 | * \endcode |
| 2744 | * |
| 2745 | * Items sent to the callback are not guaranteed to be in any order whatsoever. |
| 2746 | * There is no sorting done at this level, and if you need that, you should |
| 2747 | * probably use PHYSFS_enumerateFiles() instead, which guarantees |
| 2748 | * alphabetical sorting. This form reports whatever is discovered in each |
| 2749 | * archive before moving on to the next. Even within one archive, we can't |
| 2750 | * guarantee what order it will discover data. <em>Any sorting you find in |
| 2751 | * these callbacks is just pure luck. Do not rely on it.</em> As this walks |
| 2752 | * the entire list of archives, you may receive duplicate filenames. |
| 2753 | * |
| 2754 | * This API and the callbacks themselves are capable of reporting errors. |
| 2755 | * Prior to this API, callbacks had to accept every enumerated item, even if |
| 2756 | * they were only looking for a specific thing and wanted to stop after that, |
| 2757 | * or had a serious error and couldn't alert anyone. Furthermore, if |
| 2758 | * PhysicsFS itself had a problem (disk error or whatnot), it couldn't report |
| 2759 | * it to the calling app, it would just have to skip items or stop |
| 2760 | * enumerating outright, and the caller wouldn't know it had lost some data |
| 2761 | * along the way. |
| 2762 | * |
| 2763 | * Now the caller can be sure it got a complete data set, and its callback has |
| 2764 | * control if it wants enumeration to stop early. See the documentation for |
| 2765 | * PHYSFS_EnumerateCallback for details on how your callback should behave. |
| 2766 | * |
| 2767 | * \param dir Directory, in platform-independent notation, to enumerate. |
| 2768 | * \param c Callback function to notify about search path elements. |
| 2769 | * \param d Application-defined data passed to callback. Can be NULL. |
| 2770 | * \return non-zero on success, zero on failure. Use |
| 2771 | * PHYSFS_getLastErrorCode() to obtain the specific error. If the |
| 2772 | * callback returns PHYSFS_ENUM_STOP to stop early, this will be |
| 2773 | * considered success. Callbacks returning PHYSFS_ENUM_ERROR will |
| 2774 | * make this function return zero and set the error code to |
| 2775 | * PHYSFS_ERR_APP_CALLBACK. |
| 2776 | * |
| 2777 | * \sa PHYSFS_EnumerateCallback |
| 2778 | * \sa PHYSFS_enumerateFiles |
| 2779 | */ |
| 2780 | PHYSFS_DECL int PHYSFS_enumerate(const char *dir, PHYSFS_EnumerateCallback c, |
| 2781 | void *d); |
| 2782 | |
| 2783 | |
| 2784 | /** |
| 2785 | * \fn int PHYSFS_unmount(const char *oldDir) |
| 2786 | * \brief Remove a directory or archive from the search path. |
| 2787 | * |
| 2788 | * This is functionally equivalent to PHYSFS_removeFromSearchPath(), but that |
| 2789 | * function is deprecated to keep the vocabulary paired with PHYSFS_mount(). |
| 2790 | * |
| 2791 | * This must be a (case-sensitive) match to a dir or archive already in the |
| 2792 | * search path, specified in platform-dependent notation. |
| 2793 | * |
| 2794 | * This call will fail (and fail to remove from the path) if the element still |
| 2795 | * has files open in it. |
| 2796 | * |
| 2797 | * \warning This function wants the path to the archive or directory that was |
| 2798 | * mounted (the same string used for the "newDir" argument of |
| 2799 | * PHYSFS_addToSearchPath or any of the mount functions), not the |
| 2800 | * path where it is mounted in the tree (the "mountPoint" argument |
| 2801 | * to any of the mount functions). |
| 2802 | * |
| 2803 | * \param oldDir dir/archive to remove. |
| 2804 | * \return nonzero on success, zero on failure. Use |
| 2805 | * PHYSFS_getLastErrorCode() to obtain the specific error. |
| 2806 | * |
| 2807 | * \sa PHYSFS_getSearchPath |
| 2808 | * \sa PHYSFS_mount |
| 2809 | */ |
| 2810 | PHYSFS_DECL int PHYSFS_unmount(const char *oldDir); |
| 2811 | |
| 2812 | |
| 2813 | /** |
| 2814 | * \fn const PHYSFS_Allocator *PHYSFS_getAllocator(void) |
| 2815 | * \brief Discover the current allocator. |
| 2816 | * |
| 2817 | * (This is for limited, hardcore use. If you don't immediately see a need |
| 2818 | * for it, you can probably ignore this forever.) |
| 2819 | * |
| 2820 | * This function exposes the function pointers that make up the currently used |
| 2821 | * allocator. This can be useful for apps that want to access PhysicsFS's |
| 2822 | * internal, default allocation routines, as well as for external code that |
| 2823 | * wants to share the same allocator, even if the application specified their |
| 2824 | * own. |
| 2825 | * |
| 2826 | * This call is only valid between PHYSFS_init() and PHYSFS_deinit() calls; |
| 2827 | * it will return NULL if the library isn't initialized. As we can't |
| 2828 | * guarantee the state of the internal allocators unless the library is |
| 2829 | * initialized, you shouldn't use any allocator returned here after a call |
| 2830 | * to PHYSFS_deinit(). |
| 2831 | * |
| 2832 | * Do not call the returned allocator's Init() or Deinit() methods under any |
| 2833 | * circumstances. |
| 2834 | * |
| 2835 | * If you aren't immediately sure what to do with this function, you can |
| 2836 | * safely ignore it altogether. |
| 2837 | * |
| 2838 | * \return Current allocator, as set by PHYSFS_setAllocator(), or PhysicsFS's |
| 2839 | * internal, default allocator if no application defined allocator |
| 2840 | * is currently set. Will return NULL if the library is not |
| 2841 | * initialized. |
| 2842 | * |
| 2843 | * \sa PHYSFS_Allocator |
| 2844 | * \sa PHYSFS_setAllocator |
| 2845 | */ |
| 2846 | PHYSFS_DECL const PHYSFS_Allocator *PHYSFS_getAllocator(void); |
| 2847 | |
| 2848 | |
| 2849 | /** |
| 2850 | * \enum PHYSFS_FileType |
| 2851 | * \brief Type of a File |
| 2852 | * |
| 2853 | * Possible types of a file. |
| 2854 | * |
| 2855 | * \sa PHYSFS_stat |
| 2856 | */ |
| 2857 | typedef enum PHYSFS_FileType |
| 2858 | { |
| 2859 | PHYSFS_FILETYPE_REGULAR, /**< a normal file */ |
| 2860 | PHYSFS_FILETYPE_DIRECTORY, /**< a directory */ |
| 2861 | PHYSFS_FILETYPE_SYMLINK, /**< a symlink */ |
| 2862 | PHYSFS_FILETYPE_OTHER /**< something completely different like a device */ |
| 2863 | } PHYSFS_FileType; |
| 2864 | |
| 2865 | /** |
| 2866 | * \struct PHYSFS_Stat |
| 2867 | * \brief Meta data for a file or directory |
| 2868 | * |
| 2869 | * Container for various meta data about a file in the virtual file system. |
| 2870 | * PHYSFS_stat() uses this structure for returning the information. The time |
| 2871 | * data will be either the number of seconds since the Unix epoch (midnight, |
| 2872 | * Jan 1, 1970), or -1 if the information isn't available or applicable. |
| 2873 | * The (filesize) field is measured in bytes. |
| 2874 | * The (readonly) field tells you whether the archive thinks a file is |
| 2875 | * not writable, but tends to be only an estimate (for example, your write |
| 2876 | * dir might overlap with a .zip file, meaning you _can_ successfully open |
| 2877 | * that path for writing, as it gets created elsewhere. |
| 2878 | * |
| 2879 | * \sa PHYSFS_stat |
| 2880 | * \sa PHYSFS_FileType |
| 2881 | */ |
| 2882 | typedef struct PHYSFS_Stat |
| 2883 | { |
| 2884 | PHYSFS_sint64 filesize; /**< size in bytes, -1 for non-files and unknown */ |
| 2885 | PHYSFS_sint64 modtime; /**< last modification time */ |
| 2886 | PHYSFS_sint64 createtime; /**< like modtime, but for file creation time */ |
| 2887 | PHYSFS_sint64 accesstime; /**< like modtime, but for file access time */ |
| 2888 | PHYSFS_FileType filetype; /**< File? Directory? Symlink? */ |
| 2889 | int readonly; /**< non-zero if read only, zero if writable. */ |
| 2890 | } PHYSFS_Stat; |
| 2891 | |
| 2892 | /** |
| 2893 | * \fn int PHYSFS_stat(const char *fname, PHYSFS_Stat *stat) |
| 2894 | * \brief Get various information about a directory or a file. |
| 2895 | * |
| 2896 | * Obtain various information about a file or directory from the meta data. |
| 2897 | * |
| 2898 | * This function will never follow symbolic links. If you haven't enabled |
| 2899 | * symlinks with PHYSFS_permitSymbolicLinks(), stat'ing a symlink will be |
| 2900 | * treated like stat'ing a non-existant file. If symlinks are enabled, |
| 2901 | * stat'ing a symlink will give you information on the link itself and not |
| 2902 | * what it points to. |
| 2903 | * |
| 2904 | * \param fname filename to check, in platform-indepedent notation. |
| 2905 | * \param stat pointer to structure to fill in with data about (fname). |
| 2906 | * \return non-zero on success, zero on failure. On failure, (stat)'s |
| 2907 | * contents are undefined. |
| 2908 | * |
| 2909 | * \sa PHYSFS_Stat |
| 2910 | */ |
| 2911 | PHYSFS_DECL int PHYSFS_stat(const char *fname, PHYSFS_Stat *stat); |
| 2912 | |
| 2913 | |
| 2914 | /** |
| 2915 | * \fn void PHYSFS_utf8FromUtf16(const PHYSFS_uint16 *src, char *dst, PHYSFS_uint64 len) |
| 2916 | * \brief Convert a UTF-16 string to a UTF-8 string. |
| 2917 | * |
| 2918 | * \warning This function will not report an error if there are invalid UTF-16 |
| 2919 | * sequences in the source string. It will replace them with a '?' |
| 2920 | * character and continue on. |
| 2921 | * |
| 2922 | * UTF-16 strings are 16-bits per character (except some chars, which are |
| 2923 | * 32-bits): \c TCHAR on Windows, when building with Unicode support. Modern |
| 2924 | * Windows releases use UTF-16. Windows releases before 2000 used TCHAR, but |
| 2925 | * only handled UCS-2. UTF-16 _is_ UCS-2, except for the characters that |
| 2926 | * are 4 bytes, which aren't representable in UCS-2 at all anyhow. If you |
| 2927 | * aren't sure, you should be using UTF-16 at this point on Windows. |
| 2928 | * |
| 2929 | * To ensure that the destination buffer is large enough for the conversion, |
| 2930 | * please allocate a buffer that is double the size of the source buffer. |
| 2931 | * UTF-8 never uses more than 32-bits per character, so while it may shrink |
| 2932 | * a UTF-16 string, it may also expand it. |
| 2933 | * |
| 2934 | * Strings that don't fit in the destination buffer will be truncated, but |
| 2935 | * will always be null-terminated and never have an incomplete UTF-8 |
| 2936 | * sequence at the end. If the buffer length is 0, this function does nothing. |
| 2937 | * |
| 2938 | * \param src Null-terminated source string in UTF-16 format. |
| 2939 | * \param dst Buffer to store converted UTF-8 string. |
| 2940 | * \param len Size, in bytes, of destination buffer. |
| 2941 | */ |
| 2942 | PHYSFS_DECL void PHYSFS_utf8FromUtf16(const PHYSFS_uint16 *src, char *dst, |
| 2943 | PHYSFS_uint64 len); |
| 2944 | |
| 2945 | /** |
| 2946 | * \fn PHYSFS_utf8ToUtf16(const char *src, PHYSFS_uint16 *dst, PHYSFS_uint64 len) |
| 2947 | * \brief Convert a UTF-8 string to a UTF-16 string. |
| 2948 | * |
| 2949 | * \warning This function will not report an error if there are invalid UTF-8 |
| 2950 | * sequences in the source string. It will replace them with a '?' |
| 2951 | * character and continue on. |
| 2952 | * |
| 2953 | * UTF-16 strings are 16-bits per character (except some chars, which are |
| 2954 | * 32-bits): \c TCHAR on Windows, when building with Unicode support. Modern |
| 2955 | * Windows releases use UTF-16. Windows releases before 2000 used TCHAR, but |
| 2956 | * only handled UCS-2. UTF-16 _is_ UCS-2, except for the characters that |
| 2957 | * are 4 bytes, which aren't representable in UCS-2 at all anyhow. If you |
| 2958 | * aren't sure, you should be using UTF-16 at this point on Windows. |
| 2959 | * |
| 2960 | * To ensure that the destination buffer is large enough for the conversion, |
| 2961 | * please allocate a buffer that is double the size of the source buffer. |
| 2962 | * UTF-8 uses from one to four bytes per character, but UTF-16 always uses |
| 2963 | * two to four, so an entirely low-ASCII string will double in size! The |
| 2964 | * UTF-16 characters that would take four bytes also take four bytes in UTF-8, |
| 2965 | * so you don't need to allocate 4x the space just in case: double will do. |
| 2966 | * |
| 2967 | * Strings that don't fit in the destination buffer will be truncated, but |
| 2968 | * will always be null-terminated and never have an incomplete UTF-16 |
| 2969 | * surrogate pair at the end. If the buffer length is 0, this function does |
| 2970 | * nothing. |
| 2971 | * |
| 2972 | * \param src Null-terminated source string in UTF-8 format. |
| 2973 | * \param dst Buffer to store converted UTF-16 string. |
| 2974 | * \param len Size, in bytes, of destination buffer. |
| 2975 | * |
| 2976 | * \sa PHYSFS_utf8ToUtf16 |
| 2977 | */ |
| 2978 | PHYSFS_DECL void PHYSFS_utf8ToUtf16(const char *src, PHYSFS_uint16 *dst, |
| 2979 | PHYSFS_uint64 len); |
| 2980 | |
| 2981 | |
| 2982 | /** |
| 2983 | * \fn PHYSFS_sint64 PHYSFS_readBytes(PHYSFS_File *handle, void *buffer, PHYSFS_uint64 len) |
| 2984 | * \brief Read bytes from a PhysicsFS filehandle |
| 2985 | * |
| 2986 | * The file must be opened for reading. |
| 2987 | * |
| 2988 | * \param handle handle returned from PHYSFS_openRead(). |
| 2989 | * \param buffer buffer of at least (len) bytes to store read data into. |
| 2990 | * \param len number of bytes being read from (handle). |
| 2991 | * \return number of bytes read. This may be less than (len); this does not |
| 2992 | * signify an error, necessarily (a short read may mean EOF). |
| 2993 | * PHYSFS_getLastErrorCode() can shed light on the reason this might |
| 2994 | * be < (len), as can PHYSFS_eof(). -1 if complete failure. |
| 2995 | * |
| 2996 | * \sa PHYSFS_eof |
| 2997 | */ |
| 2998 | PHYSFS_DECL PHYSFS_sint64 PHYSFS_readBytes(PHYSFS_File *handle, void *buffer, |
| 2999 | PHYSFS_uint64 len); |
| 3000 | |
| 3001 | /** |
| 3002 | * \fn PHYSFS_sint64 PHYSFS_writeBytes(PHYSFS_File *handle, const void *buffer, PHYSFS_uint64 len) |
| 3003 | * \brief Write data to a PhysicsFS filehandle |
| 3004 | * |
| 3005 | * The file must be opened for writing. |
| 3006 | * |
| 3007 | * Please note that while (len) is an unsigned 64-bit integer, you are limited |
| 3008 | * to 63 bits (9223372036854775807 bytes), so we can return a negative value |
| 3009 | * on error. If length is greater than 0x7FFFFFFFFFFFFFFF, this function will |
| 3010 | * immediately fail. For systems without a 64-bit datatype, you are limited |
| 3011 | * to 31 bits (0x7FFFFFFF, or 2147483647 bytes). We trust most things won't |
| 3012 | * need to do multiple gigabytes of i/o in one call anyhow, but why limit |
| 3013 | * things? |
| 3014 | * |
| 3015 | * \param handle retval from PHYSFS_openWrite() or PHYSFS_openAppend(). |
| 3016 | * \param buffer buffer of (len) bytes to write to (handle). |
| 3017 | * \param len number of bytes being written to (handle). |
| 3018 | * \return number of bytes written. This may be less than (len); in the case |
| 3019 | * of an error, the system may try to write as many bytes as possible, |
| 3020 | * so an incomplete write might occur. PHYSFS_getLastErrorCode() can |
| 3021 | * shed light on the reason this might be < (len). -1 if complete |
| 3022 | * failure. |
| 3023 | */ |
| 3024 | PHYSFS_DECL PHYSFS_sint64 PHYSFS_writeBytes(PHYSFS_File *handle, |
| 3025 | const void *buffer, |
| 3026 | PHYSFS_uint64 len); |
| 3027 | |
| 3028 | |
| 3029 | /** |
| 3030 | * \struct PHYSFS_Io |
| 3031 | * \brief An abstract i/o interface. |
| 3032 | * |
| 3033 | * \warning This is advanced, hardcore stuff. You don't need this unless you |
| 3034 | * really know what you're doing. Most apps will not need this. |
| 3035 | * |
| 3036 | * Historically, PhysicsFS provided access to the physical filesystem and |
| 3037 | * archives within that filesystem. However, sometimes you need more power |
| 3038 | * than this. Perhaps you need to provide an archive that is entirely |
| 3039 | * contained in RAM, or you need to bridge some other file i/o API to |
| 3040 | * PhysicsFS, or you need to translate the bits (perhaps you have a |
| 3041 | * a standard .zip file that's encrypted, and you need to decrypt on the fly |
| 3042 | * for the unsuspecting zip archiver). |
| 3043 | * |
| 3044 | * A PHYSFS_Io is the interface that Archivers use to get archive data. |
| 3045 | * Historically, this has mapped to file i/o to the physical filesystem, but |
| 3046 | * as of PhysicsFS 2.1, applications can provide their own i/o implementations |
| 3047 | * at runtime. |
| 3048 | * |
| 3049 | * This interface isn't necessarily a good universal fit for i/o. There are a |
| 3050 | * few requirements of note: |
| 3051 | * |
| 3052 | * - They only do blocking i/o (at least, for now). |
| 3053 | * - They need to be able to duplicate. If you have a file handle from |
| 3054 | * fopen(), you need to be able to create a unique clone of it (so we |
| 3055 | * have two handles to the same file that can both seek/read/etc without |
| 3056 | * stepping on each other). |
| 3057 | * - They need to know the size of their entire data set. |
| 3058 | * - They need to be able to seek and rewind on demand. |
| 3059 | * |
| 3060 | * ...in short, you're probably not going to write an HTTP implementation. |
| 3061 | * |
| 3062 | * Thread safety: PHYSFS_Io implementations are not guaranteed to be thread |
| 3063 | * safe in themselves. Under the hood where PhysicsFS uses them, the library |
| 3064 | * provides its own locks. If you plan to use them directly from separate |
| 3065 | * threads, you should either use mutexes to protect them, or don't use the |
| 3066 | * same PHYSFS_Io from two threads at the same time. |
| 3067 | * |
| 3068 | * \sa PHYSFS_mountIo |
| 3069 | */ |
| 3070 | typedef struct PHYSFS_Io |
| 3071 | { |
| 3072 | /** |
| 3073 | * \brief Binary compatibility information. |
| 3074 | * |
| 3075 | * This must be set to zero at this time. Future versions of this |
| 3076 | * struct will increment this field, so we know what a given |
| 3077 | * implementation supports. We'll presumably keep supporting older |
| 3078 | * versions as we offer new features, though. |
| 3079 | */ |
| 3080 | PHYSFS_uint32 version; |
| 3081 | |
| 3082 | /** |
| 3083 | * \brief Instance data for this struct. |
| 3084 | * |
| 3085 | * Each instance has a pointer associated with it that can be used to |
| 3086 | * store anything it likes. This pointer is per-instance of the stream, |
| 3087 | * so presumably it will change when calling duplicate(). This can be |
| 3088 | * deallocated during the destroy() method. |
| 3089 | */ |
| 3090 | void *opaque; |
| 3091 | |
| 3092 | /** |
| 3093 | * \brief Read more data. |
| 3094 | * |
| 3095 | * Read (len) bytes from the interface, at the current i/o position, and |
| 3096 | * store them in (buffer). The current i/o position should move ahead |
| 3097 | * by the number of bytes successfully read. |
| 3098 | * |
| 3099 | * You don't have to implement this; set it to NULL if not implemented. |
| 3100 | * This will only be used if the file is opened for reading. If set to |
| 3101 | * NULL, a default implementation that immediately reports failure will |
| 3102 | * be used. |
| 3103 | * |
| 3104 | * \param io The i/o instance to read from. |
| 3105 | * \param buf The buffer to store data into. It must be at least |
| 3106 | * (len) bytes long and can't be NULL. |
| 3107 | * \param len The number of bytes to read from the interface. |
| 3108 | * \return number of bytes read from file, 0 on EOF, -1 if complete |
| 3109 | * failure. |
| 3110 | */ |
| 3111 | PHYSFS_sint64 (*read)(struct PHYSFS_Io *io, void *buf, PHYSFS_uint64 len); |
| 3112 | |
| 3113 | /** |
| 3114 | * \brief Write more data. |
| 3115 | * |
| 3116 | * Write (len) bytes from (buffer) to the interface at the current i/o |
| 3117 | * position. The current i/o position should move ahead by the number of |
| 3118 | * bytes successfully written. |
| 3119 | * |
| 3120 | * You don't have to implement this; set it to NULL if not implemented. |
| 3121 | * This will only be used if the file is opened for writing. If set to |
| 3122 | * NULL, a default implementation that immediately reports failure will |
| 3123 | * be used. |
| 3124 | * |
| 3125 | * You are allowed to buffer; a write can succeed here and then later |
| 3126 | * fail when flushing. Note that PHYSFS_setBuffer() may be operating a |
| 3127 | * level above your i/o, so you should usually not implement your |
| 3128 | * own buffering routines. |
| 3129 | * |
| 3130 | * \param io The i/o instance to write to. |
| 3131 | * \param buffer The buffer to read data from. It must be at least |
| 3132 | * (len) bytes long and can't be NULL. |
| 3133 | * \param len The number of bytes to read from (buffer). |
| 3134 | * \return number of bytes written to file, -1 if complete failure. |
| 3135 | */ |
| 3136 | PHYSFS_sint64 (*write)(struct PHYSFS_Io *io, const void *buffer, |
| 3137 | PHYSFS_uint64 len); |
| 3138 | |
| 3139 | /** |
| 3140 | * \brief Move i/o position to a given byte offset from start. |
| 3141 | * |
| 3142 | * This method moves the i/o position, so the next read/write will |
| 3143 | * be of the byte at (offset) offset. Seeks past the end of file should |
| 3144 | * be treated as an error condition. |
| 3145 | * |
| 3146 | * \param io The i/o instance to seek. |
| 3147 | * \param offset The new byte offset for the i/o position. |
| 3148 | * \return non-zero on success, zero on error. |
| 3149 | */ |
| 3150 | int (*seek)(struct PHYSFS_Io *io, PHYSFS_uint64 offset); |
| 3151 | |
| 3152 | /** |
| 3153 | * \brief Report current i/o position. |
| 3154 | * |
| 3155 | * Return bytes offset, or -1 if you aren't able to determine. A failure |
| 3156 | * will almost certainly be fatal to further use of this stream, so you |
| 3157 | * may not leave this unimplemented. |
| 3158 | * |
| 3159 | * \param io The i/o instance to query. |
| 3160 | * \return The current byte offset for the i/o position, -1 if unknown. |
| 3161 | */ |
| 3162 | PHYSFS_sint64 (*tell)(struct PHYSFS_Io *io); |
| 3163 | |
| 3164 | /** |
| 3165 | * \brief Determine size of the i/o instance's dataset. |
| 3166 | * |
| 3167 | * Return number of bytes available in the file, or -1 if you |
| 3168 | * aren't able to determine. A failure will almost certainly be fatal |
| 3169 | * to further use of this stream, so you may not leave this unimplemented. |
| 3170 | * |
| 3171 | * \param io The i/o instance to query. |
| 3172 | * \return Total size, in bytes, of the dataset. |
| 3173 | */ |
| 3174 | PHYSFS_sint64 (*length)(struct PHYSFS_Io *io); |
| 3175 | |
| 3176 | /** |
| 3177 | * \brief Duplicate this i/o instance. |
| 3178 | * |
| 3179 | * This needs to result in a full copy of this PHYSFS_Io, that can live |
| 3180 | * completely independently. The copy needs to be able to perform all |
| 3181 | * its operations without altering the original, including either object |
| 3182 | * being destroyed separately (so, for example: they can't share a file |
| 3183 | * handle; they each need their own). |
| 3184 | * |
| 3185 | * If you can't duplicate a handle, it's legal to return NULL, but you |
| 3186 | * almost certainly need this functionality if you want to use this to |
| 3187 | * PHYSFS_Io to back an archive. |
| 3188 | * |
| 3189 | * \param io The i/o instance to duplicate. |
| 3190 | * \return A new value for a stream's (opaque) field, or NULL on error. |
| 3191 | */ |
| 3192 | struct PHYSFS_Io *(*duplicate)(struct PHYSFS_Io *io); |
| 3193 | |
| 3194 | /** |
| 3195 | * \brief Flush resources to media, or wherever. |
| 3196 | * |
| 3197 | * This is the chance to report failure for writes that had claimed |
| 3198 | * success earlier, but still had a chance to actually fail. This method |
| 3199 | * can be NULL if flushing isn't necessary. |
| 3200 | * |
| 3201 | * This function may be called before destroy(), as it can report failure |
| 3202 | * and destroy() can not. It may be called at other times, too. |
| 3203 | * |
| 3204 | * \param io The i/o instance to flush. |
| 3205 | * \return Zero on error, non-zero on success. |
| 3206 | */ |
| 3207 | int (*flush)(struct PHYSFS_Io *io); |
| 3208 | |
| 3209 | /** |
| 3210 | * \brief Cleanup and deallocate i/o instance. |
| 3211 | * |
| 3212 | * Free associated resources, including (opaque) if applicable. |
| 3213 | * |
| 3214 | * This function must always succeed: as such, it returns void. The |
| 3215 | * system may call your flush() method before this. You may report |
| 3216 | * failure there if necessary. This method may still be called if |
| 3217 | * flush() fails, in which case you'll have to abandon unflushed data |
| 3218 | * and other failing conditions and clean up. |
| 3219 | * |
| 3220 | * Once this method is called for a given instance, the system will assume |
| 3221 | * it is unsafe to touch that instance again and will discard any |
| 3222 | * references to it. |
| 3223 | * |
| 3224 | * \param s The i/o instance to destroy. |
| 3225 | */ |
| 3226 | void (*destroy)(struct PHYSFS_Io *io); |
| 3227 | } PHYSFS_Io; |
| 3228 | |
| 3229 | |
| 3230 | /** |
| 3231 | * \fn int PHYSFS_mountIo(PHYSFS_Io *io, const char *newDir, const char *mountPoint, int appendToPath) |
| 3232 | * \brief Add an archive, built on a PHYSFS_Io, to the search path. |
| 3233 | * |
| 3234 | * \warning Unless you have some special, low-level need, you should be using |
| 3235 | * PHYSFS_mount() instead of this. |
| 3236 | * |
| 3237 | * This function operates just like PHYSFS_mount(), but takes a PHYSFS_Io |
| 3238 | * instead of a pathname. Behind the scenes, PHYSFS_mount() calls this |
| 3239 | * function with a physical-filesystem-based PHYSFS_Io. |
| 3240 | * |
| 3241 | * (newDir) must be a unique string to identify this archive. It is used |
| 3242 | * to optimize archiver selection (if you name it XXXXX.zip, we might try |
| 3243 | * the ZIP archiver first, for example, or directly choose an archiver that |
| 3244 | * can only trust the data is valid by filename extension). It doesn't |
| 3245 | * need to refer to a real file at all. If the filename extension isn't |
| 3246 | * helpful, the system will try every archiver until one works or none |
| 3247 | * of them do. This filename must be unique, as the system won't allow you |
| 3248 | * to have two archives with the same name. |
| 3249 | * |
| 3250 | * (io) must remain until the archive is unmounted. When the archive is |
| 3251 | * unmounted, the system will call (io)->destroy(io), which will give you |
| 3252 | * a chance to free your resources. |
| 3253 | * |
| 3254 | * If this function fails, (io)->destroy(io) is not called. |
| 3255 | * |
| 3256 | * \param io i/o instance for archive to add to the path. |
| 3257 | * \param newDir Filename that can represent this stream. |
| 3258 | * \param mountPoint Location in the interpolated tree that this archive |
| 3259 | * will be "mounted", in platform-independent notation. |
| 3260 | * NULL or "" is equivalent to "/". |
| 3261 | * \param appendToPath nonzero to append to search path, zero to prepend. |
| 3262 | * \return nonzero if added to path, zero on failure (bogus archive, stream |
| 3263 | * i/o issue, etc). Use PHYSFS_getLastErrorCode() to obtain |
| 3264 | * the specific error. |
| 3265 | * |
| 3266 | * \sa PHYSFS_unmount |
| 3267 | * \sa PHYSFS_getSearchPath |
| 3268 | * \sa PHYSFS_getMountPoint |
| 3269 | */ |
| 3270 | PHYSFS_DECL int PHYSFS_mountIo(PHYSFS_Io *io, const char *newDir, |
| 3271 | const char *mountPoint, int appendToPath); |
| 3272 | |
| 3273 | |
| 3274 | /** |
| 3275 | * \fn int PHYSFS_mountMemory(const void *buf, PHYSFS_uint64 len, void (*del)(void *), const char *newDir, const char *mountPoint, int appendToPath) |
| 3276 | * \brief Add an archive, contained in a memory buffer, to the search path. |
| 3277 | * |
| 3278 | * \warning Unless you have some special, low-level need, you should be using |
| 3279 | * PHYSFS_mount() instead of this. |
| 3280 | * |
| 3281 | * This function operates just like PHYSFS_mount(), but takes a memory buffer |
| 3282 | * instead of a pathname. This buffer contains all the data of the archive, |
| 3283 | * and is used instead of a real file in the physical filesystem. |
| 3284 | * |
| 3285 | * (newDir) must be a unique string to identify this archive. It is used |
| 3286 | * to optimize archiver selection (if you name it XXXXX.zip, we might try |
| 3287 | * the ZIP archiver first, for example, or directly choose an archiver that |
| 3288 | * can only trust the data is valid by filename extension). It doesn't |
| 3289 | * need to refer to a real file at all. If the filename extension isn't |
| 3290 | * helpful, the system will try every archiver until one works or none |
| 3291 | * of them do. This filename must be unique, as the system won't allow you |
| 3292 | * to have two archives with the same name. |
| 3293 | * |
| 3294 | * (ptr) must remain until the archive is unmounted. When the archive is |
| 3295 | * unmounted, the system will call (del)(ptr), which will notify you that |
| 3296 | * the system is done with the buffer, and give you a chance to free your |
| 3297 | * resources. (del) can be NULL, in which case the system will make no |
| 3298 | * attempt to free the buffer. |
| 3299 | * |
| 3300 | * If this function fails, (del) is not called. |
| 3301 | * |
| 3302 | * \param buf Address of the memory buffer containing the archive data. |
| 3303 | * \param len Size of memory buffer, in bytes. |
| 3304 | * \param del A callback that triggers upon unmount. Can be NULL. |
| 3305 | * \param newDir Filename that can represent this stream. |
| 3306 | * \param mountPoint Location in the interpolated tree that this archive |
| 3307 | * will be "mounted", in platform-independent notation. |
| 3308 | * NULL or "" is equivalent to "/". |
| 3309 | * \param appendToPath nonzero to append to search path, zero to prepend. |
| 3310 | * \return nonzero if added to path, zero on failure (bogus archive, etc). |
| 3311 | * Use PHYSFS_getLastErrorCode() to obtain the specific error. |
| 3312 | * |
| 3313 | * \sa PHYSFS_unmount |
| 3314 | * \sa PHYSFS_getSearchPath |
| 3315 | * \sa PHYSFS_getMountPoint |
| 3316 | */ |
| 3317 | PHYSFS_DECL int PHYSFS_mountMemory(const void *buf, PHYSFS_uint64 len, |
| 3318 | void (*del)(void *), const char *newDir, |
| 3319 | const char *mountPoint, int appendToPath); |
| 3320 | |
| 3321 | |
| 3322 | /** |
| 3323 | * \fn int PHYSFS_mountHandle(PHYSFS_File *file, const char *newDir, const char *mountPoint, int appendToPath) |
| 3324 | * \brief Add an archive, contained in a PHYSFS_File handle, to the search path. |
| 3325 | * |
| 3326 | * \warning Unless you have some special, low-level need, you should be using |
| 3327 | * PHYSFS_mount() instead of this. |
| 3328 | * |
| 3329 | * \warning Archives-in-archives may be very slow! While a PHYSFS_File can |
| 3330 | * seek even when the data is compressed, it may do so by rewinding |
| 3331 | * to the start and decompressing everything before the seek point. |
| 3332 | * Normal archive usage may do a lot of seeking behind the scenes. |
| 3333 | * As such, you might find normal archive usage extremely painful |
| 3334 | * if mounted this way. Plan accordingly: if you, say, have a |
| 3335 | * self-extracting .zip file, and want to mount something in it, |
| 3336 | * compress the contents of the inner archive and make sure the outer |
| 3337 | * .zip file doesn't compress the inner archive too. |
| 3338 | * |
| 3339 | * This function operates just like PHYSFS_mount(), but takes a PHYSFS_File |
| 3340 | * handle instead of a pathname. This handle contains all the data of the |
| 3341 | * archive, and is used instead of a real file in the physical filesystem. |
| 3342 | * The PHYSFS_File may be backed by a real file in the physical filesystem, |
| 3343 | * but isn't necessarily. The most popular use for this is likely to mount |
| 3344 | * archives stored inside other archives. |
| 3345 | * |
| 3346 | * (newDir) must be a unique string to identify this archive. It is used |
| 3347 | * to optimize archiver selection (if you name it XXXXX.zip, we might try |
| 3348 | * the ZIP archiver first, for example, or directly choose an archiver that |
| 3349 | * can only trust the data is valid by filename extension). It doesn't |
| 3350 | * need to refer to a real file at all. If the filename extension isn't |
| 3351 | * helpful, the system will try every archiver until one works or none |
| 3352 | * of them do. This filename must be unique, as the system won't allow you |
| 3353 | * to have two archives with the same name. |
| 3354 | * |
| 3355 | * (file) must remain until the archive is unmounted. When the archive is |
| 3356 | * unmounted, the system will call PHYSFS_close(file). If you need this |
| 3357 | * handle to survive, you will have to wrap this in a PHYSFS_Io and use |
| 3358 | * PHYSFS_mountIo() instead. |
| 3359 | * |
| 3360 | * If this function fails, PHYSFS_close(file) is not called. |
| 3361 | * |
| 3362 | * \param file The PHYSFS_File handle containing archive data. |
| 3363 | * \param newDir Filename that can represent this stream. |
| 3364 | * \param mountPoint Location in the interpolated tree that this archive |
| 3365 | * will be "mounted", in platform-independent notation. |
| 3366 | * NULL or "" is equivalent to "/". |
| 3367 | * \param appendToPath nonzero to append to search path, zero to prepend. |
| 3368 | * \return nonzero if added to path, zero on failure (bogus archive, etc). |
| 3369 | * Use PHYSFS_getLastErrorCode() to obtain the specific error. |
| 3370 | * |
| 3371 | * \sa PHYSFS_unmount |
| 3372 | * \sa PHYSFS_getSearchPath |
| 3373 | * \sa PHYSFS_getMountPoint |
| 3374 | */ |
| 3375 | PHYSFS_DECL int PHYSFS_mountHandle(PHYSFS_File *file, const char *newDir, |
| 3376 | const char *mountPoint, int appendToPath); |
| 3377 | |
| 3378 | |
| 3379 | /** |
| 3380 | * \enum PHYSFS_ErrorCode |
| 3381 | * \brief Values that represent specific causes of failure. |
| 3382 | * |
| 3383 | * Most of the time, you should only concern yourself with whether a given |
| 3384 | * operation failed or not, but there may be occasions where you plan to |
| 3385 | * handle a specific failure case gracefully, so we provide specific error |
| 3386 | * codes. |
| 3387 | * |
| 3388 | * Most of these errors are a little vague, and most aren't things you can |
| 3389 | * fix...if there's a permission error, for example, all you can really do |
| 3390 | * is pass that information on to the user and let them figure out how to |
| 3391 | * handle it. In most these cases, your program should only care that it |
| 3392 | * failed to accomplish its goals, and not care specifically why. |
| 3393 | * |
| 3394 | * \sa PHYSFS_getLastErrorCode |
| 3395 | * \sa PHYSFS_getErrorByCode |
| 3396 | */ |
| 3397 | typedef enum PHYSFS_ErrorCode |
| 3398 | { |
| 3399 | PHYSFS_ERR_OK, /**< Success; no error. */ |
| 3400 | PHYSFS_ERR_OTHER_ERROR, /**< Error not otherwise covered here. */ |
| 3401 | PHYSFS_ERR_OUT_OF_MEMORY, /**< Memory allocation failed. */ |
| 3402 | PHYSFS_ERR_NOT_INITIALIZED, /**< PhysicsFS is not initialized. */ |
| 3403 | PHYSFS_ERR_IS_INITIALIZED, /**< PhysicsFS is already initialized. */ |
| 3404 | PHYSFS_ERR_ARGV0_IS_NULL, /**< Needed argv[0], but it is NULL. */ |
| 3405 | PHYSFS_ERR_UNSUPPORTED, /**< Operation or feature unsupported. */ |
| 3406 | PHYSFS_ERR_PAST_EOF, /**< Attempted to access past end of file. */ |
| 3407 | PHYSFS_ERR_FILES_STILL_OPEN, /**< Files still open. */ |
| 3408 | PHYSFS_ERR_INVALID_ARGUMENT, /**< Bad parameter passed to an function. */ |
| 3409 | PHYSFS_ERR_NOT_MOUNTED, /**< Requested archive/dir not mounted. */ |
| 3410 | PHYSFS_ERR_NOT_FOUND, /**< File (or whatever) not found. */ |
| 3411 | PHYSFS_ERR_SYMLINK_FORBIDDEN,/**< Symlink seen when not permitted. */ |
| 3412 | PHYSFS_ERR_NO_WRITE_DIR, /**< No write dir has been specified. */ |
| 3413 | PHYSFS_ERR_OPEN_FOR_READING, /**< Wrote to a file opened for reading. */ |
| 3414 | PHYSFS_ERR_OPEN_FOR_WRITING, /**< Read from a file opened for writing. */ |
| 3415 | PHYSFS_ERR_NOT_A_FILE, /**< Needed a file, got a directory (etc). */ |
| 3416 | PHYSFS_ERR_READ_ONLY, /**< Wrote to a read-only filesystem. */ |
| 3417 | PHYSFS_ERR_CORRUPT, /**< Corrupted data encountered. */ |
| 3418 | PHYSFS_ERR_SYMLINK_LOOP, /**< Infinite symbolic link loop. */ |
| 3419 | PHYSFS_ERR_IO, /**< i/o error (hardware failure, etc). */ |
| 3420 | PHYSFS_ERR_PERMISSION, /**< Permission denied. */ |
| 3421 | PHYSFS_ERR_NO_SPACE, /**< No space (disk full, over quota, etc) */ |
| 3422 | PHYSFS_ERR_BAD_FILENAME, /**< Filename is bogus/insecure. */ |
| 3423 | PHYSFS_ERR_BUSY, /**< Tried to modify a file the OS needs. */ |
| 3424 | PHYSFS_ERR_DIR_NOT_EMPTY, /**< Tried to delete dir with files in it. */ |
| 3425 | PHYSFS_ERR_OS_ERROR, /**< Unspecified OS-level error. */ |
| 3426 | PHYSFS_ERR_DUPLICATE, /**< Duplicate entry. */ |
| 3427 | PHYSFS_ERR_BAD_PASSWORD, /**< Bad password. */ |
| 3428 | PHYSFS_ERR_APP_CALLBACK /**< Application callback reported error. */ |
| 3429 | } PHYSFS_ErrorCode; |
| 3430 | |
| 3431 | |
| 3432 | /** |
| 3433 | * \fn PHYSFS_ErrorCode PHYSFS_getLastErrorCode(void) |
| 3434 | * \brief Get machine-readable error information. |
| 3435 | * |
| 3436 | * Get the last PhysicsFS error message as an integer value. This will return |
| 3437 | * PHYSFS_ERR_OK if there's been no error since the last call to this |
| 3438 | * function. Each thread has a unique error state associated with it, but |
| 3439 | * each time a new error message is set, it will overwrite the previous one |
| 3440 | * associated with that thread. It is safe to call this function at anytime, |
| 3441 | * even before PHYSFS_init(). |
| 3442 | * |
| 3443 | * PHYSFS_getLastError() and PHYSFS_getLastErrorCode() both reset the same |
| 3444 | * thread-specific error state. Calling one will wipe out the other's |
| 3445 | * data. If you need both, call PHYSFS_getLastErrorCode(), then pass that |
| 3446 | * value to PHYSFS_getErrorByCode(). |
| 3447 | * |
| 3448 | * Generally, applications should only concern themselves with whether a |
| 3449 | * given function failed; however, if you require more specifics, you can |
| 3450 | * try this function to glean information, if there's some specific problem |
| 3451 | * you're expecting and plan to handle. But with most things that involve |
| 3452 | * file systems, the best course of action is usually to give up, report the |
| 3453 | * problem to the user, and let them figure out what should be done about it. |
| 3454 | * For that, you might prefer PHYSFS_getErrorByCode() instead. |
| 3455 | * |
| 3456 | * \return Enumeration value that represents last reported error. |
| 3457 | * |
| 3458 | * \sa PHYSFS_getErrorByCode |
| 3459 | */ |
| 3460 | PHYSFS_DECL PHYSFS_ErrorCode PHYSFS_getLastErrorCode(void); |
| 3461 | |
| 3462 | |
| 3463 | /** |
| 3464 | * \fn const char *PHYSFS_getErrorByCode(PHYSFS_ErrorCode code) |
| 3465 | * \brief Get human-readable description string for a given error code. |
| 3466 | * |
| 3467 | * Get a static string, in UTF-8 format, that represents an English |
| 3468 | * description of a given error code. |
| 3469 | * |
| 3470 | * This string is guaranteed to never change (although we may add new strings |
| 3471 | * for new error codes in later versions of PhysicsFS), so you can use it |
| 3472 | * for keying a localization dictionary. |
| 3473 | * |
| 3474 | * It is safe to call this function at anytime, even before PHYSFS_init(). |
| 3475 | * |
| 3476 | * These strings are meant to be passed on directly to the user. |
| 3477 | * Generally, applications should only concern themselves with whether a |
| 3478 | * given function failed, but not care about the specifics much. |
| 3479 | * |
| 3480 | * Do not attempt to free the returned strings; they are read-only and you |
| 3481 | * don't own their memory pages. |
| 3482 | * |
| 3483 | * \param code Error code to convert to a string. |
| 3484 | * \return READ ONLY string of requested error message, NULL if this |
| 3485 | * is not a valid PhysicsFS error code. Always check for NULL if |
| 3486 | * you might be looking up an error code that didn't exist in an |
| 3487 | * earlier version of PhysicsFS. |
| 3488 | * |
| 3489 | * \sa PHYSFS_getLastErrorCode |
| 3490 | */ |
| 3491 | PHYSFS_DECL const char *PHYSFS_getErrorByCode(PHYSFS_ErrorCode code); |
| 3492 | |
| 3493 | /** |
| 3494 | * \fn void PHYSFS_setErrorCode(PHYSFS_ErrorCode code) |
| 3495 | * \brief Set the current thread's error code. |
| 3496 | * |
| 3497 | * This lets you set the value that will be returned by the next call to |
| 3498 | * PHYSFS_getLastErrorCode(). This will replace any existing error code, |
| 3499 | * whether set by your application or internally by PhysicsFS. |
| 3500 | * |
| 3501 | * Error codes are stored per-thread; what you set here will not be |
| 3502 | * accessible to another thread. |
| 3503 | * |
| 3504 | * Any call into PhysicsFS may change the current error code, so any code you |
| 3505 | * set here is somewhat fragile, and thus you shouldn't build any serious |
| 3506 | * error reporting framework on this function. The primary goal of this |
| 3507 | * function is to allow PHYSFS_Io implementations to set the error state, |
| 3508 | * which generally will be passed back to your application when PhysicsFS |
| 3509 | * makes a PHYSFS_Io call that fails internally. |
| 3510 | * |
| 3511 | * This function doesn't care if the error code is a value known to PhysicsFS |
| 3512 | * or not (but PHYSFS_getErrorByCode() will return NULL for unknown values). |
| 3513 | * The value will be reported unmolested by PHYSFS_getLastErrorCode(). |
| 3514 | * |
| 3515 | * \param code Error code to become the current thread's new error state. |
| 3516 | * |
| 3517 | * \sa PHYSFS_getLastErrorCode |
| 3518 | * \sa PHYSFS_getErrorByCode |
| 3519 | */ |
| 3520 | PHYSFS_DECL void PHYSFS_setErrorCode(PHYSFS_ErrorCode code); |
| 3521 | |
| 3522 | |
| 3523 | /** |
| 3524 | * \fn const char *PHYSFS_getPrefDir(const char *org, const char *app) |
| 3525 | * \brief Get the user-and-app-specific path where files can be written. |
| 3526 | * |
| 3527 | * Helper function. |
| 3528 | * |
| 3529 | * Get the "pref dir". This is meant to be where users can write personal |
| 3530 | * files (preferences and save games, etc) that are specific to your |
| 3531 | * application. This directory is unique per user, per application. |
| 3532 | * |
| 3533 | * This function will decide the appropriate location in the native filesystem, |
| 3534 | * create the directory if necessary, and return a string in |
| 3535 | * platform-dependent notation, suitable for passing to PHYSFS_setWriteDir(). |
| 3536 | * |
| 3537 | * On Windows, this might look like: |
| 3538 | * "C:\\Users\\bob\\AppData\\Roaming\\My Company\\My Program Name" |
| 3539 | * |
| 3540 | * On Linux, this might look like: |
| 3541 | * "/home/bob/.local/share/My Program Name" |
| 3542 | * |
| 3543 | * On Mac OS X, this might look like: |
| 3544 | * "/Users/bob/Library/Application Support/My Program Name" |
| 3545 | * |
| 3546 | * (etc.) |
| 3547 | * |
| 3548 | * You should probably use the pref dir for your write dir, and also put it |
| 3549 | * near the beginning of your search path. Older versions of PhysicsFS |
| 3550 | * offered only PHYSFS_getUserDir() and left you to figure out where the |
| 3551 | * files should go under that tree. This finds the correct location |
| 3552 | * for whatever platform, which not only changes between operating systems, |
| 3553 | * but also versions of the same operating system. |
| 3554 | * |
| 3555 | * You specify the name of your organization (if it's not a real organization, |
| 3556 | * your name or an Internet domain you own might do) and the name of your |
| 3557 | * application. These should be proper names. |
| 3558 | * |
| 3559 | * Both the (org) and (app) strings may become part of a directory name, so |
| 3560 | * please follow these rules: |
| 3561 | * |
| 3562 | * - Try to use the same org string (including case-sensitivity) for |
| 3563 | * all your applications that use this function. |
| 3564 | * - Always use a unique app string for each one, and make sure it never |
| 3565 | * changes for an app once you've decided on it. |
| 3566 | * - Unicode characters are legal, as long as it's UTF-8 encoded, but... |
| 3567 | * - ...only use letters, numbers, and spaces. Avoid punctuation like |
| 3568 | * "Game Name 2: Bad Guy's Revenge!" ... "Game Name 2" is sufficient. |
| 3569 | * |
| 3570 | * The pointer returned by this function remains valid until you call this |
| 3571 | * function again, or call PHYSFS_deinit(). This is not necessarily a fast |
| 3572 | * call, though, so you should call this once at startup and copy the string |
| 3573 | * if you need it. |
| 3574 | * |
| 3575 | * You should assume the path returned by this function is the only safe |
| 3576 | * place to write files (and that PHYSFS_getUserDir() and PHYSFS_getBaseDir(), |
| 3577 | * while they might be writable, or even parents of the returned path, aren't |
| 3578 | * where you should be writing things). |
| 3579 | * |
| 3580 | * \param org The name of your organization. |
| 3581 | * \param app The name of your application. |
| 3582 | * \return READ ONLY string of user dir in platform-dependent notation. NULL |
| 3583 | * if there's a problem (creating directory failed, etc). |
| 3584 | * |
| 3585 | * \sa PHYSFS_getBaseDir |
| 3586 | * \sa PHYSFS_getUserDir |
| 3587 | */ |
| 3588 | PHYSFS_DECL const char *PHYSFS_getPrefDir(const char *org, const char *app); |
| 3589 | |
| 3590 | |
| 3591 | /** |
| 3592 | * \struct PHYSFS_Archiver |
| 3593 | * \brief Abstract interface to provide support for user-defined archives. |
| 3594 | * |
| 3595 | * \warning This is advanced, hardcore stuff. You don't need this unless you |
| 3596 | * really know what you're doing. Most apps will not need this. |
| 3597 | * |
| 3598 | * Historically, PhysicsFS provided a means to mount various archive file |
| 3599 | * formats, and physical directories in the native filesystem. However, |
| 3600 | * applications have been limited to the file formats provided by the |
| 3601 | * library. This interface allows an application to provide their own |
| 3602 | * archive file types. |
| 3603 | * |
| 3604 | * Conceptually, a PHYSFS_Archiver provides directory entries, while |
| 3605 | * PHYSFS_Io provides data streams for those directory entries. The most |
| 3606 | * obvious use of PHYSFS_Archiver is to provide support for an archive |
| 3607 | * file type that isn't provided by PhysicsFS directly: perhaps some |
| 3608 | * proprietary format that only your application needs to understand. |
| 3609 | * |
| 3610 | * Internally, all the built-in archive support uses this interface, so the |
| 3611 | * best examples for building a PHYSFS_Archiver is the source code to |
| 3612 | * PhysicsFS itself. |
| 3613 | * |
| 3614 | * An archiver is added to the system with PHYSFS_registerArchiver(), and then |
| 3615 | * it will be available for use automatically with PHYSFS_mount(); if a |
| 3616 | * given archive can be handled with your archiver, it will be given control |
| 3617 | * as appropriate. |
| 3618 | * |
| 3619 | * These methods deal with dir handles. You have one instance of your |
| 3620 | * archiver, and it generates a unique, opaque handle for each opened |
| 3621 | * archive in its openArchive() method. Since the lifetime of an Archiver |
| 3622 | * (not an archive) is generally the entire lifetime of the process, and it's |
| 3623 | * assumed to be a singleton, we do not provide any instance data for the |
| 3624 | * archiver itself; the app can just use some static variables if necessary. |
| 3625 | * |
| 3626 | * Symlinks should always be followed (except in stat()); PhysicsFS will |
| 3627 | * use the stat() method to check for symlinks and make a judgement on |
| 3628 | * whether to continue to call other methods based on that. |
| 3629 | * |
| 3630 | * Archivers, when necessary, should set the PhysicsFS error state with |
| 3631 | * PHYSFS_setErrorCode() before returning. PhysicsFS will pass these errors |
| 3632 | * back to the application unmolested in most cases. |
| 3633 | * |
| 3634 | * Thread safety: PHYSFS_Archiver implementations are not guaranteed to be |
| 3635 | * thread safe in themselves. PhysicsFS provides thread safety when it calls |
| 3636 | * into a given archiver inside the library, but it does not promise that |
| 3637 | * using the same PHYSFS_File from two threads at once is thread-safe; as |
| 3638 | * such, your PHYSFS_Archiver can assume that locking is handled for you |
| 3639 | * so long as the PHYSFS_Io you return from PHYSFS_open* doesn't change any |
| 3640 | * of your Archiver state, as the PHYSFS_Io won't be as aggressively |
| 3641 | * protected. |
| 3642 | * |
| 3643 | * \sa PHYSFS_registerArchiver |
| 3644 | * \sa PHYSFS_deregisterArchiver |
| 3645 | * \sa PHYSFS_supportedArchiveTypes |
| 3646 | */ |
| 3647 | typedef struct PHYSFS_Archiver |
| 3648 | { |
| 3649 | /** |
| 3650 | * \brief Binary compatibility information. |
| 3651 | * |
| 3652 | * This must be set to zero at this time. Future versions of this |
| 3653 | * struct will increment this field, so we know what a given |
| 3654 | * implementation supports. We'll presumably keep supporting older |
| 3655 | * versions as we offer new features, though. |
| 3656 | */ |
| 3657 | PHYSFS_uint32 version; |
| 3658 | |
| 3659 | /** |
| 3660 | * \brief Basic info about this archiver. |
| 3661 | * |
| 3662 | * This is used to identify your archive, and is returned in |
| 3663 | * PHYSFS_supportedArchiveTypes(). |
| 3664 | */ |
| 3665 | PHYSFS_ArchiveInfo info; |
| 3666 | |
| 3667 | /** |
| 3668 | * \brief Open an archive provided by (io). |
| 3669 | * |
| 3670 | * This is where resources are allocated and data is parsed when mounting |
| 3671 | * an archive. |
| 3672 | * (name) is a filename associated with (io), but doesn't necessarily |
| 3673 | * map to anything, let alone a real filename. This possibly- |
| 3674 | * meaningless name is in platform-dependent notation. |
| 3675 | * (forWrite) is non-zero if this is to be used for |
| 3676 | * the write directory, and zero if this is to be used for an |
| 3677 | * element of the search path. |
| 3678 | * (claimed) should be set to 1 if this is definitely an archive your |
| 3679 | * archiver implementation can handle, even if it fails. We use to |
| 3680 | * decide if we should stop trying other archivers if you fail to open |
| 3681 | * it. For example: the .zip archiver will set this to 1 for something |
| 3682 | * that's got a .zip file signature, even if it failed because the file |
| 3683 | * was also truncated. No sense in trying other archivers here, we |
| 3684 | * already tried to handle it with the appropriate implementation!. |
| 3685 | * Return NULL on failure and set (claimed) appropriately. If no archiver |
| 3686 | * opened the archive or set (claimed), PHYSFS_mount() will report |
| 3687 | * PHYSFS_ERR_UNSUPPORTED. Otherwise, it will report the error from the |
| 3688 | * archiver that claimed the data through (claimed). |
| 3689 | * Return non-NULL on success. The pointer returned will be |
| 3690 | * passed as the "opaque" parameter for later calls. |
| 3691 | */ |
| 3692 | void *(*openArchive)(PHYSFS_Io *io, const char *name, |
| 3693 | int forWrite, int *claimed); |
| 3694 | |
| 3695 | /** |
| 3696 | * \brief List all files in (dirname). |
| 3697 | * |
| 3698 | * Each file is passed to (cb), where a copy is made if appropriate, so |
| 3699 | * you can dispose of it upon return from the callback. (dirname) is in |
| 3700 | * platform-independent notation. |
| 3701 | * If you have a failure, call PHYSFS_SetErrorCode() with whatever code |
| 3702 | * seem appropriate and return PHYSFS_ENUM_ERROR. |
| 3703 | * If the callback returns PHYSFS_ENUM_ERROR, please call |
| 3704 | * PHYSFS_SetErrorCode(PHYSFS_ERR_APP_CALLBACK) and then return |
| 3705 | * PHYSFS_ENUM_ERROR as well. Don't call the callback again in any |
| 3706 | * circumstances. |
| 3707 | * If the callback returns PHYSFS_ENUM_STOP, stop enumerating and return |
| 3708 | * PHYSFS_ENUM_STOP as well. Don't call the callback again in any |
| 3709 | * circumstances. Don't set an error code in this case. |
| 3710 | * Callbacks are only supposed to return a value from |
| 3711 | * PHYSFS_EnumerateCallbackResult. Any other result has undefined |
| 3712 | * behavior. |
| 3713 | * As long as the callback returned PHYSFS_ENUM_OK and you haven't |
| 3714 | * experienced any errors of your own, keep enumerating until you're done |
| 3715 | * and then return PHYSFS_ENUM_OK without setting an error code. |
| 3716 | * |
| 3717 | * \warning PHYSFS_enumerate returns zero or non-zero (success or failure), |
| 3718 | * so be aware this function pointer returns different values! |
| 3719 | */ |
| 3720 | PHYSFS_EnumerateCallbackResult (*enumerate)(void *opaque, |
| 3721 | const char *dirname, PHYSFS_EnumerateCallback cb, |
| 3722 | const char *origdir, void *callbackdata); |
| 3723 | |
| 3724 | /** |
| 3725 | * \brief Open a file in this archive for reading. |
| 3726 | * |
| 3727 | * This filename, (fnm), is in platform-independent notation. |
| 3728 | * Fail if the file does not exist. |
| 3729 | * Returns NULL on failure, and calls PHYSFS_setErrorCode(). |
| 3730 | * Returns non-NULL on success. The pointer returned will be |
| 3731 | * passed as the "opaque" parameter for later file calls. |
| 3732 | */ |
| 3733 | PHYSFS_Io *(*openRead)(void *opaque, const char *fnm); |
| 3734 | |
| 3735 | /** |
| 3736 | * \brief Open a file in this archive for writing. |
| 3737 | * |
| 3738 | * If the file does not exist, it should be created. If it exists, |
| 3739 | * it should be truncated to zero bytes. The writing offset should |
| 3740 | * be the start of the file. |
| 3741 | * If the archive is read-only, this operation should fail. |
| 3742 | * This filename is in platform-independent notation. |
| 3743 | * Returns NULL on failure, and calls PHYSFS_setErrorCode(). |
| 3744 | * Returns non-NULL on success. The pointer returned will be |
| 3745 | * passed as the "opaque" parameter for later file calls. |
| 3746 | */ |
| 3747 | PHYSFS_Io *(*openWrite)(void *opaque, const char *filename); |
| 3748 | |
| 3749 | /** |
| 3750 | * \brief Open a file in this archive for appending. |
| 3751 | * |
| 3752 | * If the file does not exist, it should be created. The writing |
| 3753 | * offset should be the end of the file. |
| 3754 | * If the archive is read-only, this operation should fail. |
| 3755 | * This filename is in platform-independent notation. |
| 3756 | * Returns NULL on failure, and calls PHYSFS_setErrorCode(). |
| 3757 | * Returns non-NULL on success. The pointer returned will be |
| 3758 | * passed as the "opaque" parameter for later file calls. |
| 3759 | */ |
| 3760 | PHYSFS_Io *(*openAppend)(void *opaque, const char *filename); |
| 3761 | |
| 3762 | /** |
| 3763 | * \brief Delete a file or directory in the archive. |
| 3764 | * |
| 3765 | * This same call is used for both files and directories; there is not a |
| 3766 | * separate rmdir() call. Directories are only meant to be removed if |
| 3767 | * they are empty. |
| 3768 | * If the archive is read-only, this operation should fail. |
| 3769 | * |
| 3770 | * Return non-zero on success, zero on failure. |
| 3771 | * This filename is in platform-independent notation. |
| 3772 | * On failure, call PHYSFS_setErrorCode(). |
| 3773 | */ |
| 3774 | int (*remove)(void *opaque, const char *filename); |
| 3775 | |
| 3776 | /** |
| 3777 | * \brief Create a directory in the archive. |
| 3778 | * |
| 3779 | * If the application is trying to make multiple dirs, PhysicsFS |
| 3780 | * will split them up into multiple calls before passing them to |
| 3781 | * your driver. |
| 3782 | * If the archive is read-only, this operation should fail. |
| 3783 | * Return non-zero on success, zero on failure. |
| 3784 | * This filename is in platform-independent notation. |
| 3785 | * On failure, call PHYSFS_setErrorCode(). |
| 3786 | */ |
| 3787 | int (*mkdir)(void *opaque, const char *filename); |
| 3788 | |
| 3789 | /** |
| 3790 | * \brief Obtain basic file metadata. |
| 3791 | * |
| 3792 | * On success, fill in all the fields in (stat), using |
| 3793 | * reasonable defaults for fields that apply to your archive. |
| 3794 | * |
| 3795 | * Returns non-zero on success, zero on failure. |
| 3796 | * This filename is in platform-independent notation. |
| 3797 | * On failure, call PHYSFS_setErrorCode(). |
| 3798 | */ |
| 3799 | int (*stat)(void *opaque, const char *fn, PHYSFS_Stat *stat); |
| 3800 | |
| 3801 | /** |
| 3802 | * \brief Destruct a previously-opened archive. |
| 3803 | * |
| 3804 | * Close this archive, and free any associated memory, |
| 3805 | * including the original PHYSFS_Io and (opaque) itself, if |
| 3806 | * applicable. Implementation can assume that it won't be called if |
| 3807 | * there are still files open from this archive. |
| 3808 | */ |
| 3809 | void (*closeArchive)(void *opaque); |
| 3810 | } PHYSFS_Archiver; |
| 3811 | |
| 3812 | /** |
| 3813 | * \fn int PHYSFS_registerArchiver(const PHYSFS_Archiver *archiver) |
| 3814 | * \brief Add a new archiver to the system. |
| 3815 | * |
| 3816 | * \warning This is advanced, hardcore stuff. You don't need this unless you |
| 3817 | * really know what you're doing. Most apps will not need this. |
| 3818 | * |
| 3819 | * If you want to provide your own archiver (for example, a custom archive |
| 3820 | * file format, or some virtual thing you want to make look like a filesystem |
| 3821 | * that you can access through the usual PhysicsFS APIs), this is where you |
| 3822 | * start. Once an archiver is successfully registered, then you can use |
| 3823 | * PHYSFS_mount() to add archives that your archiver supports to the |
| 3824 | * search path, or perhaps use it as the write dir. Internally, PhysicsFS |
| 3825 | * uses this function to register its own built-in archivers, like .zip |
| 3826 | * support, etc. |
| 3827 | * |
| 3828 | * You may not have two archivers that handle the same extension. If you are |
| 3829 | * going to have a clash, you can deregister the other archiver (including |
| 3830 | * built-in ones) with PHYSFS_deregisterArchiver(). |
| 3831 | * |
| 3832 | * The data in (archiver) is copied; you may free this pointer when this |
| 3833 | * function returns. |
| 3834 | * |
| 3835 | * Once this function returns successfully, PhysicsFS will be able to support |
| 3836 | * archives of this type until you deregister the archiver again. |
| 3837 | * |
| 3838 | * \param archiver The archiver to register. |
| 3839 | * \return Zero on error, non-zero on success. |
| 3840 | * |
| 3841 | * \sa PHYSFS_Archiver |
| 3842 | * \sa PHYSFS_deregisterArchiver |
| 3843 | */ |
| 3844 | PHYSFS_DECL int PHYSFS_registerArchiver(const PHYSFS_Archiver *archiver); |
| 3845 | |
| 3846 | /** |
| 3847 | * \fn int PHYSFS_deregisterArchiver(const char *ext) |
| 3848 | * \brief Remove an archiver from the system. |
| 3849 | * |
| 3850 | * If for some reason, you only need your previously-registered archiver to |
| 3851 | * live for a portion of your app's lifetime, you can remove it from the |
| 3852 | * system once you're done with it through this function. |
| 3853 | * |
| 3854 | * This fails if there are any archives still open that use this archiver. |
| 3855 | * |
| 3856 | * This function can also remove internally-supplied archivers, like .zip |
| 3857 | * support or whatnot. This could be useful in some situations, like |
| 3858 | * disabling support for them outright or overriding them with your own |
| 3859 | * implementation. Once an internal archiver is disabled like this, |
| 3860 | * PhysicsFS provides no mechanism to recover them, short of calling |
| 3861 | * PHYSFS_deinit() and PHYSFS_init() again. |
| 3862 | * |
| 3863 | * PHYSFS_deinit() will automatically deregister all archivers, so you don't |
| 3864 | * need to explicitly deregister yours if you otherwise shut down cleanly. |
| 3865 | * |
| 3866 | * \param ext Filename extension that the archiver handles. |
| 3867 | * \return Zero on error, non-zero on success. |
| 3868 | * |
| 3869 | * \sa PHYSFS_Archiver |
| 3870 | * \sa PHYSFS_registerArchiver |
| 3871 | */ |
| 3872 | PHYSFS_DECL int PHYSFS_deregisterArchiver(const char *ext); |
| 3873 | |
| 3874 | |
| 3875 | /* Everything above this line is part of the PhysicsFS 2.1 API. */ |
| 3876 | |
| 3877 | |
| 3878 | /** |
| 3879 | * \fn int PHYSFS_setRoot(const char *archive, const char *subdir) |
| 3880 | * \brief Make a subdirectory of an archive its root directory. |
| 3881 | * |
| 3882 | * This lets you narrow down the accessible files in a specific archive. For |
| 3883 | * example, if you have x.zip with a file in y/z.txt, mounted to /a, if you |
| 3884 | * call PHYSFS_setRoot("x.zip", "/y"), then the call |
| 3885 | * PHYSFS_openRead("/a/z.txt") will succeed. |
| 3886 | * |
| 3887 | * You can change an archive's root at any time, altering the interpolated |
| 3888 | * file tree (depending on where paths shift, a different archive may be |
| 3889 | * providing various files). If you set the root to NULL or "/", the |
| 3890 | * archive will be treated as if no special root was set (as if the archive |
| 3891 | * was just mounted normally). |
| 3892 | * |
| 3893 | * Changing the root only affects future operations on pathnames; a file |
| 3894 | * that was opened from a path that changed due to a setRoot will not be |
| 3895 | * affected. |
| 3896 | * |
| 3897 | * Setting a new root is not limited to archives in the search path; you may |
| 3898 | * set one on the write dir, too, which might be useful if you have files |
| 3899 | * open for write and thus can't change the write dir at the moment. |
| 3900 | * |
| 3901 | * It is not an error to set a subdirectory that does not exist to be the |
| 3902 | * root of an archive; however, no files will be visible in this case. If |
| 3903 | * the missing directories end up getting created (a mkdir to the physical |
| 3904 | * filesystem, etc) then this will be reflected in the interpolated tree. |
| 3905 | * |
| 3906 | * \param archive dir/archive on which to change root. |
| 3907 | * \param subdir new subdirectory to make the root of this archive. |
| 3908 | * \return nonzero on success, zero on failure. Use |
| 3909 | * PHYSFS_getLastErrorCode() to obtain the specific error. |
| 3910 | */ |
| 3911 | PHYSFS_DECL int PHYSFS_setRoot(const char *archive, const char *subdir); |
| 3912 | |
| 3913 | |
| 3914 | /* Everything above this line is part of the PhysicsFS 3.1 API. */ |
| 3915 | |
| 3916 | |
| 3917 | #ifdef __cplusplus |
| 3918 | } |
| 3919 | #endif |
| 3920 | |
| 3921 | #endif /* !defined _INCLUDE_PHYSFS_H_ */ |
| 3922 | |
| 3923 | /* end of physfs.h ... */ |
| 3924 | |
| 3925 | |