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 * http://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 * This system is largely inspired by Quake 3's PK3 files and the related 24 * fs_* cvars. If you've ever tinkered with these, then this API will be 25 * familiar to you. 26 * 27 * With PhysicsFS, you have a single writing directory and multiple 28 * directories (the "search path") for reading. You can think of this as a 29 * filesystem within a filesystem. If (on Windows) you were to set the 30 * writing directory to "C:\MyGame\MyWritingDirectory", then no PHYSFS calls 31 * could touch anything above this directory, including the "C:\MyGame" and 32 * "C:\" directories. This prevents an application's internal scripting 33 * language from piddling over c:\\config.sys, for example. If you'd rather 34 * give PHYSFS full access to the system's REAL file system, set the writing 35 * dir to "C:\", but that's generally A Bad Thing for several reasons. 36 * 37 * Drive letters are hidden in PhysicsFS once you set up your initial paths. 38 * The search path creates a single, hierarchical directory structure. 39 * Not only does this lend itself well to general abstraction with archives, 40 * it also gives better support to operating systems like MacOS and Unix. 41 * Generally speaking, you shouldn't ever hardcode a drive letter; not only 42 * does this hurt portability to non-Microsoft OSes, but it limits your win32 43 * users to a single drive, too. Use the PhysicsFS abstraction functions and 44 * allow user-defined configuration options, too. When opening a file, you 45 * specify it like it was on a Unix filesystem: if you want to write to 46 * "C:\MyGame\MyConfigFiles\game.cfg", then you might set the write dir to 47 * "C:\MyGame" and then open "MyConfigFiles/game.cfg". This gives an 48 * abstraction across all platforms. Specifying a file in this way is termed 49 * "platform-independent notation" in this documentation. Specifying a 50 * a filename in a form such as "C:\mydir\myfile" or 51 * "MacOS hard drive:My Directory:My File" is termed "platform-dependent 52 * notation". The only time you use platform-dependent notation is when 53 * setting up your write directory and search path; after that, all file 54 * access into those directories are done with platform-independent notation. 55 * 56 * All files opened for writing are opened in relation to the write directory, 57 * which is the root of the writable filesystem. When opening a file for 58 * reading, PhysicsFS goes through the search path. This is NOT the 59 * same thing as the PATH environment variable. An application using 60 * PhysicsFS specifies directories to be searched which may be actual 61 * directories, or archive files that contain files and subdirectories of 62 * their own. See the end of these docs for currently supported archive 63 * formats. 64 * 65 * Once the search path is defined, you may open files for reading. If you've 66 * got the following search path defined (to use a win32 example again): 67 * 68 * - C:\\mygame 69 * - C:\\mygame\\myuserfiles 70 * - D:\\mygamescdromdatafiles 71 * - C:\\mygame\\installeddatafiles.zip 72 * 73 * Then a call to PHYSFS_openRead("textfiles/myfile.txt") (note the directory 74 * separator, lack of drive letter, and lack of dir separator at the start of 75 * the string; this is platform-independent notation) will check for 76 * C:\\mygame\\textfiles\\myfile.txt, then 77 * C:\\mygame\\myuserfiles\\textfiles\\myfile.txt, then 78 * D:\\mygamescdromdatafiles\\textfiles\\myfile.txt, then, finally, for 79 * textfiles\\myfile.txt inside of C:\\mygame\\installeddatafiles.zip. 80 * Remember that most archive types and platform filesystems store their 81 * filenames in a case-sensitive manner, so you should be careful to specify 82 * it correctly. 83 * 84 * Files opened through PhysicsFS may NOT contain "." or ".." or ":" as dir 85 * elements. Not only are these meaningless on MacOS Classic and/or Unix, 86 * they are a security hole. Also, symbolic links (which can be found in 87 * some archive types and directly in the filesystem on Unix platforms) are 88 * NOT followed until you call PHYSFS_permitSymbolicLinks(). That's left to 89 * your own discretion, as following a symlink can allow for access outside 90 * the write dir and search paths. For portability, there is no mechanism for 91 * creating new symlinks in PhysicsFS. 92 * 93 * The write dir is not included in the search path unless you specifically 94 * add it. While you CAN change the write dir as many times as you like, 95 * you should probably set it once and stick to it. Remember that your 96 * program will not have permission to write in every directory on Unix and 97 * NT systems. 98 * 99 * All files are opened in binary mode; there is no endline conversion for 100 * textfiles. Other than that, PhysicsFS has some convenience functions for 101 * platform-independence. There is a function to tell you the current 102 * platform's dir separator ("\\" on windows, "/" on Unix, ":" on MacOS), 103 * which is needed only to set up your search/write paths. There is a 104 * function to tell you what CD-ROM drives contain accessible discs, and a 105 * function to recommend a good search path, etc. 106 * 107 * A recommended order for the search path is the write dir, then the base dir, 108 * then the cdrom dir, then any archives discovered. Quake 3 does something 109 * like this, but moves the archives to the start of the search path. Build 110 * Engine games, like Duke Nukem 3D and Blood, place the archives last, and 111 * use the base dir for both searching and writing. There is a helper 112 * function (PHYSFS_setSaneConfig()) that puts together a basic configuration 113 * for you, based on a few parameters. Also see the comments on 114 * PHYSFS_getBaseDir(), and PHYSFS_getUserDir() for info on what those 115 * are and how they can help you determine an optimal search path. 116 * 117 * PhysicsFS 2.0 adds the concept of "mounting" archives to arbitrary points 118 * in the search path. If a zipfile contains "maps/level.map" and you mount 119 * that archive at "mods/mymod", then you would have to open 120 * "mods/mymod/maps/level.map" to access the file, even though "mods/mymod" 121 * isn't actually specified in the .zip file. Unlike the Unix mentality of 122 * mounting a filesystem, "mods/mymod" doesn't actually have to exist when 123 * mounting the zipfile. It's a "virtual" directory. The mounting mechanism 124 * allows the developer to seperate archives in the tree and avoid trampling 125 * over files when added new archives, such as including mod support in a 126 * game...keeping external content on a tight leash in this manner can be of 127 * utmost importance to some applications. 128 * 129 * PhysicsFS is mostly thread safe. The error messages returned by 130 * PHYSFS_getLastError are unique by thread, and library-state-setting 131 * functions are mutex'd. For efficiency, individual file accesses are 132 * not locked, so you can not safely read/write/seek/close/etc the same 133 * file from two threads at the same time. Other race conditions are bugs 134 * that should be reported/patched. 135 * 136 * While you CAN use stdio/syscall file access in a program that has PHYSFS_* 137 * calls, doing so is not recommended, and you can not use system 138 * filehandles with PhysicsFS and vice versa. 139 * 140 * Note that archives need not be named as such: if you have a ZIP file and 141 * rename it with a .PKG extension, the file will still be recognized as a 142 * ZIP archive by PhysicsFS; the file's contents are used to determine its 143 * type where possible. 144 * 145 * Currently supported archive types: 146 * - .ZIP (pkZip/WinZip/Info-ZIP compatible) 147 * - .GRP (Build Engine groupfile archives) 148 * - .PAK (Quake I/II archive format) 149 * - .HOG (Descent I/II HOG file archives) 150 * - .MVL (Descent II movielib archives) 151 * - .WAD (DOOM engine archives) 152 * 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 and build with Unicode support, your TCHAR 167 * strings are two bytes per character (this is called "UCS-2 encoding"). You 168 * should convert them to UTF-8 before handing them to PhysicsFS with 169 * PHYSFS_utf8FromUcs2(). If you're using Unix or Mac OS X, your wchar_t 170 * strings are four bytes per character ("UCS-4 encoding"). Use 171 * PHYSFS_utf8FromUcs4(). Mac OS X can give you UTF-8 directly from a 172 * CFString, and many Unixes generally give you C strings in UTF-8 format 173 * everywhere. If you have a single-byte high ASCII charset, like so-many 174 * European "codepages" you may be out of luck. We'll convert from "Latin1" 175 * to UTF-8 only, and never back to Latin1. If you're above ASCII 127, all 176 * bets are off: move to Unicode or use your platform's facilities. Passing a 177 * C string with high-ASCII data that isn't UTF-8 encoded will NOT do what 178 * you expect! 179 * 180 * Naturally, there's also PHYSFS_utf8ToUcs2() and PHYSFS_utf8ToUcs4() to get 181 * data back into a format you like. Behind the scenes, PhysicsFS will use 182 * Unicode where possible: the UTF-8 strings on Windows will be converted 183 * and used with the multibyte Windows APIs, for example. 184 * 185 * PhysicsFS offers basic encoding conversion support, but not a whole string 186 * library. Get your stuff into whatever format you can work with. 187 * 188 * Some platforms and archivers don't offer full Unicode support behind the 189 * scenes. For example, OS/2 only offers "codepages" and the filesystem 190 * itself doesn't support multibyte encodings. We make an earnest effort to 191 * convert to/from the current locale here, but all bets are off if 192 * you want to hand an arbitrary Japanese character through to these systems. 193 * Modern OSes (Mac OS X, Linux, Windows, PocketPC, etc) should all be fine. 194 * Many game-specific archivers are seriously unprepared for Unicode (the 195 * Descent HOG/MVL and Build Engine GRP archivers, for example, only offer a 196 * DOS 8.3 filename, for example). Nothing can be done for these, but they 197 * tend to be legacy formats for existing content that was all ASCII (and 198 * thus, valid UTF-8) anyhow. Other formats, like .ZIP, don't explicitly 199 * offer Unicode support, but unofficially expect filenames to be UTF-8 200 * encoded, and thus Just Work. Most everything does the right thing without 201 * bothering you, but it's good to be aware of these nuances in case they 202 * don't. 203 * 204 * 205 * Other stuff: 206 * 207 * Please see the file LICENSE.txt in the source's root directory for licensing 208 * and redistribution rights. 209 * 210 * Please see the file CREDITS.txt in the source's root directory for a more or 211 * less complete list of who's responsible for this. 212 * 213 * \author Ryan C. Gordon. 214 */ 215 216 #ifndef _INCLUDE_PHYSFS_H_ 217 #define _INCLUDE_PHYSFS_H_ 218 219 #ifdef __cplusplus 220 extern "C" { 221 #endif 222 223 #ifndef DOXYGEN_SHOULD_IGNORE_THIS 224 #if (defined _MSC_VER) 225 #define __EXPORT__ __declspec(dllexport) 226 #elif (__GNUC__ >= 3) 227 #define __EXPORT__ __attribute__((visibility("default"))) 228 #else 229 #define __EXPORT__ 230 #endif 231 #endif /* DOXYGEN_SHOULD_IGNORE_THIS */ 232 233 /** 234 * \typedef PHYSFS_uint8 235 * \brief An unsigned, 8-bit integer type. 236 */ 237 typedef unsigned char PHYSFS_uint8; 238 239 /** 240 * \typedef PHYSFS_sint8 241 * \brief A signed, 8-bit integer type. 242 */ 243 typedef signed char PHYSFS_sint8; 244 245 /** 246 * \typedef PHYSFS_uint16 247 * \brief An unsigned, 16-bit integer type. 248 */ 249 typedef unsigned short PHYSFS_uint16; 250 251 /** 252 * \typedef PHYSFS_sint16 253 * \brief A signed, 16-bit integer type. 254 */ 255 typedef signed short PHYSFS_sint16; 256 257 /** 258 * \typedef PHYSFS_uint32 259 * \brief An unsigned, 32-bit integer type. 260 */ 261 typedef unsigned int PHYSFS_uint32; 262 263 /** 264 * \typedef PHYSFS_sint32 265 * \brief A signed, 32-bit integer type. 266 */ 267 typedef signed int PHYSFS_sint32; 268 269 /** 270 * \typedef PHYSFS_uint64 271 * \brief An unsigned, 64-bit integer type. 272 * \warning on platforms without any sort of 64-bit datatype, this is 273 * equivalent to PHYSFS_uint32! 274 */ 275 276 /** 277 * \typedef PHYSFS_sint64 278 * \brief A signed, 64-bit integer type. 279 * \warning on platforms without any sort of 64-bit datatype, this is 280 * equivalent to PHYSFS_sint32! 281 */ 282 283 284 #if (defined PHYSFS_NO_64BIT_SUPPORT) /* oh well. */ 285 typedef PHYSFS_uint32 PHYSFS_uint64; 286 typedef PHYSFS_sint32 PHYSFS_sint64; 287 #elif (defined _MSC_VER) 288 typedef signed __int64 PHYSFS_sint64; 289 typedef unsigned __int64 PHYSFS_uint64; 290 #else 291 typedef unsigned long long PHYSFS_uint64; 292 typedef signed long long PHYSFS_sint64; 293 #endif 294 295 296 #ifndef DOXYGEN_SHOULD_IGNORE_THIS 297 /* Make sure the types really have the right sizes */ 298 #define PHYSFS_COMPILE_TIME_ASSERT(name, x) \ 299 typedef int PHYSFS_dummy_ ## name[(x) * 2 - 1] 300 301 PHYSFS_COMPILE_TIME_ASSERT(uint8, sizeof(PHYSFS_uint8) == 1); 302 PHYSFS_COMPILE_TIME_ASSERT(sint8, sizeof(PHYSFS_sint8) == 1); 303 PHYSFS_COMPILE_TIME_ASSERT(uint16, sizeof(PHYSFS_uint16) == 2); 304 PHYSFS_COMPILE_TIME_ASSERT(sint16, sizeof(PHYSFS_sint16) == 2); 305 PHYSFS_COMPILE_TIME_ASSERT(uint32, sizeof(PHYSFS_uint32) == 4); 306 PHYSFS_COMPILE_TIME_ASSERT(sint32, sizeof(PHYSFS_sint32) == 4); 307 308 #ifndef PHYSFS_NO_64BIT_SUPPORT 309 PHYSFS_COMPILE_TIME_ASSERT(uint64, sizeof(PHYSFS_uint64) == 8); 310 PHYSFS_COMPILE_TIME_ASSERT(sint64, sizeof(PHYSFS_sint64) == 8); 311 #endif 312 313 #undef PHYSFS_COMPILE_TIME_ASSERT 314 315 #endif /* DOXYGEN_SHOULD_IGNORE_THIS */ 316 317 318 /** 319 * \struct PHYSFS_File 320 * \brief A PhysicsFS file handle. 321 * 322 * You get a pointer to one of these when you open a file for reading, 323 * writing, or appending via PhysicsFS. 324 * 325 * As you can see from the lack of meaningful fields, you should treat this 326 * as opaque data. Don't try to manipulate the file handle, just pass the 327 * pointer you got, unmolested, to various PhysicsFS APIs. 328 * 329 * \sa PHYSFS_openRead 330 * \sa PHYSFS_openWrite 331 * \sa PHYSFS_openAppend 332 * \sa PHYSFS_close 333 * \sa PHYSFS_read 334 * \sa PHYSFS_write 335 * \sa PHYSFS_seek 336 * \sa PHYSFS_tell 337 * \sa PHYSFS_eof 338 * \sa PHYSFS_setBuffer 339 * \sa PHYSFS_flush 340 */ 341 typedef struct PHYSFS_File 342 { 343 void *opaque; /**< That's all you get. Don't touch. */ 344 } PHYSFS_File; 345 346 347 /** 348 * \def PHYSFS_file 349 * \brief 1.0 API compatibility define. 350 * 351 * PHYSFS_file is identical to PHYSFS_File. This #define is here for backwards 352 * compatibility with the 1.0 API, which had an inconsistent capitalization 353 * convention in this case. New code should use PHYSFS_File, as this #define 354 * may go away someday. 355 * 356 * \sa PHYSFS_File 357 */ 358 #define PHYSFS_file PHYSFS_File 359 360 361 /** 362 * \struct PHYSFS_ArchiveInfo 363 * \brief Information on various PhysicsFS-supported archives. 364 * 365 * This structure gives you details on what sort of archives are supported 366 * by this implementation of PhysicsFS. Archives tend to be things like 367 * ZIP files and such. 368 * 369 * \warning Not all binaries are created equal! PhysicsFS can be built with 370 * or without support for various archives. You can check with 371 * PHYSFS_supportedArchiveTypes() to see if your archive type is 372 * supported. 373 * 374 * \sa PHYSFS_supportedArchiveTypes 375 */ 376 typedef struct PHYSFS_ArchiveInfo 377 { 378 const char *extension; /**< Archive file extension: "ZIP", for example. */ 379 const char *description; /**< Human-readable archive description. */ 380 const char *author; /**< Person who did support for this archive. */ 381 const char *url; /**< URL related to this archive */ 382 } PHYSFS_ArchiveInfo; 383 384 385 /** 386 * \struct PHYSFS_Version 387 * \brief Information the version of PhysicsFS in use. 388 * 389 * Represents the library's version as three levels: major revision 390 * (increments with massive changes, additions, and enhancements), 391 * minor revision (increments with backwards-compatible changes to the 392 * major revision), and patchlevel (increments with fixes to the minor 393 * revision). 394 * 395 * \sa PHYSFS_VERSION 396 * \sa PHYSFS_getLinkedVersion 397 */ 398 typedef struct PHYSFS_Version 399 { 400 PHYSFS_uint8 major; /**< major revision */ 401 PHYSFS_uint8 minor; /**< minor revision */ 402 PHYSFS_uint8 patch; /**< patchlevel */ 403 } PHYSFS_Version; 404 405 #ifndef DOXYGEN_SHOULD_IGNORE_THIS 406 #define PHYSFS_VER_MAJOR 2 407 #define PHYSFS_VER_MINOR 0 408 #define PHYSFS_VER_PATCH 2 409 #endif /* DOXYGEN_SHOULD_IGNORE_THIS */ 410 411 412 /* PhysicsFS state stuff ... */ 413 414 /** 415 * \def PHYSFS_VERSION(x) 416 * \brief Macro to determine PhysicsFS version program was compiled against. 417 * 418 * This macro fills in a PHYSFS_Version structure with the version of the 419 * library you compiled against. This is determined by what header the 420 * compiler uses. Note that if you dynamically linked the library, you might 421 * have a slightly newer or older version at runtime. That version can be 422 * determined with PHYSFS_getLinkedVersion(), which, unlike PHYSFS_VERSION, 423 * is not a macro. 424 * 425 * \param x A pointer to a PHYSFS_Version struct to initialize. 426 * 427 * \sa PHYSFS_Version 428 * \sa PHYSFS_getLinkedVersion 429 */ 430 #define PHYSFS_VERSION(x) \ 431 { \ 432 (x)->major = PHYSFS_VER_MAJOR; \ 433 (x)->minor = PHYSFS_VER_MINOR; \ 434 (x)->patch = PHYSFS_VER_PATCH; \ 435 } 436 437 438 /** 439 * \fn void PHYSFS_getLinkedVersion(PHYSFS_Version *ver) 440 * \brief Get the version of PhysicsFS that is linked against your program. 441 * 442 * If you are using a shared library (DLL) version of PhysFS, then it is 443 * possible that it will be different than the version you compiled against. 444 * 445 * This is a real function; the macro PHYSFS_VERSION tells you what version 446 * of PhysFS you compiled against: 447 * 448 * \code 449 * PHYSFS_Version compiled; 450 * PHYSFS_Version linked; 451 * 452 * PHYSFS_VERSION(&compiled); 453 * PHYSFS_getLinkedVersion(&linked); 454 * printf("We compiled against PhysFS version %d.%d.%d ...\n", 455 * compiled.major, compiled.minor, compiled.patch); 456 * printf("But we linked against PhysFS version %d.%d.%d.\n", 457 * linked.major, linked.minor, linked.patch); 458 * \endcode 459 * 460 * This function may be called safely at any time, even before PHYSFS_init(). 461 * 462 * \sa PHYSFS_VERSION 463 */ 464 __EXPORT__ void PHYSFS_getLinkedVersion(PHYSFS_Version *ver); 465 466 467 /** 468 * \fn int PHYSFS_init(const char *argv0) 469 * \brief Initialize the PhysicsFS library. 470 * 471 * This must be called before any other PhysicsFS function. 472 * 473 * This should be called prior to any attempts to change your process's 474 * current working directory. 475 * 476 * \param argv0 the argv[0] string passed to your program's mainline. 477 * This may be NULL on most platforms (such as ones without a 478 * standard main() function), but you should always try to pass 479 * something in here. Unix-like systems such as Linux _need_ to 480 * pass argv[0] from main() in here. 481 * \return nonzero on success, zero on error. Specifics of the error can be 482 * gleaned from PHYSFS_getLastError(). 483 * 484 * \sa PHYSFS_deinit 485 * \sa PHYSFS_isInit 486 */ 487 __EXPORT__ int PHYSFS_init(const char *argv0); 488 489 490 /** 491 * \fn int PHYSFS_deinit(void) 492 * \brief Deinitialize the PhysicsFS library. 493 * 494 * This closes any files opened via PhysicsFS, blanks the search/write paths, 495 * frees memory, and invalidates all of your file handles. 496 * 497 * Note that this call can FAIL if there's a file open for writing that 498 * refuses to close (for example, the underlying operating system was 499 * buffering writes to network filesystem, and the fileserver has crashed, 500 * or a hard drive has failed, etc). It is usually best to close all write 501 * handles yourself before calling this function, so that you can gracefully 502 * handle a specific failure. 503 * 504 * Once successfully deinitialized, PHYSFS_init() can be called again to 505 * restart the subsystem. All default API states are restored at this 506 * point, with the exception of any custom allocator you might have 507 * specified, which survives between initializations. 508 * 509 * \return nonzero on success, zero on error. Specifics of the error can be 510 * gleaned from PHYSFS_getLastError(). If failure, state of PhysFS is 511 * undefined, and probably badly screwed up. 512 * 513 * \sa PHYSFS_init 514 * \sa PHYSFS_isInit 515 */ 516 __EXPORT__ int PHYSFS_deinit(void); 517 518 519 /** 520 * \fn const PHYSFS_ArchiveInfo **PHYSFS_supportedArchiveTypes(void) 521 * \brief Get a list of supported archive types. 522 * 523 * Get a list of archive types supported by this implementation of PhysicFS. 524 * These are the file formats usable for search path entries. This is for 525 * informational purposes only. Note that the extension listed is merely 526 * convention: if we list "ZIP", you can open a PkZip-compatible archive 527 * with an extension of "XYZ", if you like. 528 * 529 * The returned value is an array of pointers to PHYSFS_ArchiveInfo structures, 530 * with a NULL entry to signify the end of the list: 531 * 532 * \code 533 * PHYSFS_ArchiveInfo **i; 534 * 535 * for (i = PHYSFS_supportedArchiveTypes(); *i != NULL; i++) 536 * { 537 * printf("Supported archive: [%s], which is [%s].\n", 538 * (*i)->extension, (*i)->description); 539 * } 540 * \endcode 541 * 542 * The return values are pointers to static internal memory, and should 543 * be considered READ ONLY, and never freed. 544 * 545 * \return READ ONLY Null-terminated array of READ ONLY structures. 546 */ 547 __EXPORT__ const PHYSFS_ArchiveInfo **PHYSFS_supportedArchiveTypes(void); 548 549 550 /** 551 * \fn void PHYSFS_freeList(void *listVar) 552 * \brief Deallocate resources of lists returned by PhysicsFS. 553 * 554 * Certain PhysicsFS functions return lists of information that are 555 * dynamically allocated. Use this function to free those resources. 556 * 557 * \param listVar List of information specified as freeable by this function. 558 * 559 * \sa PHYSFS_getCdRomDirs 560 * \sa PHYSFS_enumerateFiles 561 * \sa PHYSFS_getSearchPath 562 */ 563 __EXPORT__ void PHYSFS_freeList(void *listVar); 564 565 566 /** 567 * \fn const char *PHYSFS_getLastError(void) 568 * \brief Get human-readable error information. 569 * 570 * Get the last PhysicsFS error message as a human-readable, null-terminated 571 * string. This will be NULL if there's been no error since the last call to 572 * this function. The pointer returned by this call points to an internal 573 * buffer. Each thread has a unique error state associated with it, but each 574 * time a new error message is set, it will overwrite the previous one 575 * associated with that thread. It is safe to call this function at anytime, 576 * even before PHYSFS_init(). 577 * 578 * It is not wise to expect a specific string of characters here, since the 579 * error message may be localized into an unfamiliar language. These strings 580 * are meant to be passed on directly to the user. 581 * 582 * \return READ ONLY string of last error message. 583 */ 584 __EXPORT__ const char *PHYSFS_getLastError(void); 585 586 587 /** 588 * \fn const char *PHYSFS_getDirSeparator(void) 589 * \brief Get platform-dependent dir separator string. 590 * 591 * This returns "\\" on win32, "/" on Unix, and ":" on MacOS. It may be more 592 * than one character, depending on the platform, and your code should take 593 * that into account. Note that this is only useful for setting up the 594 * search/write paths, since access into those dirs always use '/' 595 * (platform-independent notation) to separate directories. This is also 596 * handy for getting platform-independent access when using stdio calls. 597 * 598 * \return READ ONLY null-terminated string of platform's dir separator. 599 */ 600 __EXPORT__ const char *PHYSFS_getDirSeparator(void); 601 602 603 /** 604 * \fn void PHYSFS_permitSymbolicLinks(int allow) 605 * \brief Enable or disable following of symbolic links. 606 * 607 * Some physical filesystems and archives contain files that are just pointers 608 * to other files. On the physical filesystem, opening such a link will 609 * (transparently) open the file that is pointed to. 610 * 611 * By default, PhysicsFS will check if a file is really a symlink during open 612 * calls and fail if it is. Otherwise, the link could take you outside the 613 * write and search paths, and compromise security. 614 * 615 * If you want to take that risk, call this function with a non-zero parameter. 616 * Note that this is more for sandboxing a program's scripting language, in 617 * case untrusted scripts try to compromise the system. Generally speaking, 618 * a user could very well have a legitimate reason to set up a symlink, so 619 * unless you feel there's a specific danger in allowing them, you should 620 * permit them. 621 * 622 * Symlinks are only explicitly checked when dealing with filenames 623 * in platform-independent notation. That is, when setting up your 624 * search and write paths, etc, symlinks are never checked for. 625 * 626 * Symbolic link permission can be enabled or disabled at any time after 627 * you've called PHYSFS_init(), and is disabled by default. 628 * 629 * \param allow nonzero to permit symlinks, zero to deny linking. 630 * 631 * \sa PHYSFS_symbolicLinksPermitted 632 */ 633 __EXPORT__ void PHYSFS_permitSymbolicLinks(int allow); 634 635 636 /* !!! FIXME: const this? */ 637 /** 638 * \fn char **PHYSFS_getCdRomDirs(void) 639 * \brief Get an array of paths to available CD-ROM drives. 640 * 641 * The dirs returned are platform-dependent ("D:\" on Win32, "/cdrom" or 642 * whatnot on Unix). Dirs are only returned if there is a disc ready and 643 * accessible in the drive. So if you've got two drives (D: and E:), and only 644 * E: has a disc in it, then that's all you get. If the user inserts a disc 645 * in D: and you call this function again, you get both drives. If, on a 646 * Unix box, the user unmounts a disc and remounts it elsewhere, the next 647 * call to this function will reflect that change. 648 * 649 * This function refers to "CD-ROM" media, but it really means "inserted disc 650 * media," such as DVD-ROM, HD-DVD, CDRW, and Blu-Ray discs. It looks for 651 * filesystems, and as such won't report an audio CD, unless there's a 652 * mounted filesystem track on it. 653 * 654 * The returned value is an array of strings, with a NULL entry to signify the 655 * end of the list: 656 * 657 * \code 658 * char **cds = PHYSFS_getCdRomDirs(); 659 * char **i; 660 * 661 * for (i = cds; *i != NULL; i++) 662 * printf("cdrom dir [%s] is available.\n", *i); 663 * 664 * PHYSFS_freeList(cds); 665 * \endcode 666 * 667 * This call may block while drives spin up. Be forewarned. 668 * 669 * When you are done with the returned information, you may dispose of the 670 * resources by calling PHYSFS_freeList() with the returned pointer. 671 * 672 * \return Null-terminated array of null-terminated strings. 673 * 674 * \sa PHYSFS_getCdRomDirsCallback 675 */ 676 __EXPORT__ char **PHYSFS_getCdRomDirs(void); 677 678 679 /** 680 * \fn const char *PHYSFS_getBaseDir(void) 681 * \brief Get the path where the application resides. 682 * 683 * Helper function. 684 * 685 * Get the "base dir". This is the directory where the application was run 686 * from, which is probably the installation directory, and may or may not 687 * be the process's current working directory. 688 * 689 * You should probably use the base dir in your search path. 690 * 691 * \return READ ONLY string of base dir in platform-dependent notation. 692 * 693 * \sa PHYSFS_getUserDir 694 */ 695 __EXPORT__ const char *PHYSFS_getBaseDir(void); 696 697 698 /** 699 * \fn const char *PHYSFS_getUserDir(void) 700 * \brief Get the path where user's home directory resides. 701 * 702 * Helper function. 703 * 704 * Get the "user dir". This is meant to be a suggestion of where a specific 705 * user of the system can store files. On Unix, this is her home directory. 706 * On systems with no concept of multiple home directories (MacOS, win95), 707 * this will default to something like "C:\mybasedir\users\username" 708 * where "username" will either be the login name, or "default" if the 709 * platform doesn't support multiple users, either. 710 * 711 * You should probably use the user dir as the basis for your write dir, and 712 * also put it near the beginning of your search path. 713 * 714 * \return READ ONLY string of user dir in platform-dependent notation. 715 * 716 * \sa PHYSFS_getBaseDir 717 */ 718 __EXPORT__ const char *PHYSFS_getUserDir(void); 719 720 721 /** 722 * \fn const char *PHYSFS_getWriteDir(void) 723 * \brief Get path where PhysicsFS will allow file writing. 724 * 725 * Get the current write dir. The default write dir is NULL. 726 * 727 * \return READ ONLY string of write dir in platform-dependent notation, 728 * OR NULL IF NO WRITE PATH IS CURRENTLY SET. 729 * 730 * \sa PHYSFS_setWriteDir 731 */ 732 __EXPORT__ const char *PHYSFS_getWriteDir(void); 733 734 735 /** 736 * \fn int PHYSFS_setWriteDir(const char *newDir) 737 * \brief Tell PhysicsFS where it may write files. 738 * 739 * Set a new write dir. This will override the previous setting. 740 * 741 * This call will fail (and fail to change the write dir) if the current 742 * write dir still has files open in it. 743 * 744 * \param newDir The new directory to be the root of the write dir, 745 * specified in platform-dependent notation. Setting to NULL 746 * disables the write dir, so no files can be opened for 747 * writing via PhysicsFS. 748 * \return non-zero on success, zero on failure. All attempts to open a file 749 * for writing via PhysicsFS will fail until this call succeeds. 750 * Specifics of the error can be gleaned from PHYSFS_getLastError(). 751 * 752 * \sa PHYSFS_getWriteDir 753 */ 754 __EXPORT__ int PHYSFS_setWriteDir(const char *newDir); 755 756 757 /** 758 * \fn int PHYSFS_addToSearchPath(const char *newDir, int appendToPath) 759 * \brief Add an archive or directory to the search path. 760 * 761 * This is a legacy call in PhysicsFS 2.0, equivalent to: 762 * PHYSFS_mount(newDir, NULL, appendToPath); 763 * 764 * You must use this and not PHYSFS_mount if binary compatibility with 765 * PhysicsFS 1.0 is important (which it may not be for many people). 766 * 767 * \sa PHYSFS_mount 768 * \sa PHYSFS_removeFromSearchPath 769 * \sa PHYSFS_getSearchPath 770 */ 771 __EXPORT__ int PHYSFS_addToSearchPath(const char *newDir, int appendToPath); 772 773 774 /** 775 * \fn int PHYSFS_removeFromSearchPath(const char *oldDir) 776 * \brief Remove a directory or archive from the search path. 777 * 778 * This must be a (case-sensitive) match to a dir or archive already in the 779 * search path, specified in platform-dependent notation. 780 * 781 * This call will fail (and fail to remove from the path) if the element still 782 * has files open in it. 783 * 784 * \param oldDir dir/archive to remove. 785 * \return nonzero on success, zero on failure. 786 * Specifics of the error can be gleaned from PHYSFS_getLastError(). 787 * 788 * \sa PHYSFS_addToSearchPath 789 * \sa PHYSFS_getSearchPath 790 */ 791 __EXPORT__ int PHYSFS_removeFromSearchPath(const char *oldDir); 792 793 794 /** 795 * \fn char **PHYSFS_getSearchPath(void) 796 * \brief Get the current search path. 797 * 798 * The default search path is an empty list. 799 * 800 * The returned value is an array of strings, with a NULL entry to signify the 801 * end of the list: 802 * 803 * \code 804 * char **i; 805 * 806 * for (i = PHYSFS_getSearchPath(); *i != NULL; i++) 807 * printf("[%s] is in the search path.\n", *i); 808 * \endcode 809 * 810 * When you are done with the returned information, you may dispose of the 811 * resources by calling PHYSFS_freeList() with the returned pointer. 812 * 813 * \return Null-terminated array of null-terminated strings. NULL if there 814 * was a problem (read: OUT OF MEMORY). 815 * 816 * \sa PHYSFS_getSearchPathCallback 817 * \sa PHYSFS_addToSearchPath 818 * \sa PHYSFS_removeFromSearchPath 819 */ 820 __EXPORT__ char **PHYSFS_getSearchPath(void); 821 822 823 /** 824 * \fn int PHYSFS_setSaneConfig(const char *organization, const char *appName, const char *archiveExt, int includeCdRoms, int archivesFirst) 825 * \brief Set up sane, default paths. 826 * 827 * Helper function. 828 * 829 * The write dir will be set to "userdir/.organization/appName", which is 830 * created if it doesn't exist. 831 * 832 * The above is sufficient to make sure your program's configuration directory 833 * is separated from other clutter, and platform-independent. The period 834 * before "mygame" even hides the directory on Unix systems. 835 * 836 * The search path will be: 837 * 838 * - The Write Dir (created if it doesn't exist) 839 * - The Base Dir (PHYSFS_getBaseDir()) 840 * - All found CD-ROM dirs (optionally) 841 * 842 * These directories are then searched for files ending with the extension 843 * (archiveExt), which, if they are valid and supported archives, will also 844 * be added to the search path. If you specified "PKG" for (archiveExt), and 845 * there's a file named data.PKG in the base dir, it'll be checked. Archives 846 * can either be appended or prepended to the search path in alphabetical 847 * order, regardless of which directories they were found in. 848 * 849 * All of this can be accomplished from the application, but this just does it 850 * all for you. Feel free to add more to the search path manually, too. 851 * 852 * \param organization Name of your company/group/etc to be used as a 853 * dirname, so keep it small, and no-frills. 854 * 855 * \param appName Program-specific name of your program, to separate it 856 * from other programs using PhysicsFS. 857 * 858 * \param archiveExt File extension used by your program to specify an 859 * archive. For example, Quake 3 uses "pk3", even though 860 * they are just zipfiles. Specify NULL to not dig out 861 * archives automatically. Do not specify the '.' char; 862 * If you want to look for ZIP files, specify "ZIP" and 863 * not ".ZIP" ... the archive search is case-insensitive. 864 * 865 * \param includeCdRoms Non-zero to include CD-ROMs in the search path, and 866 * (if (archiveExt) != NULL) search them for archives. 867 * This may cause a significant amount of blocking 868 * while discs are accessed, and if there are no discs 869 * in the drive (or even not mounted on Unix systems), 870 * then they may not be made available anyhow. You may 871 * want to specify zero and handle the disc setup 872 * yourself. 873 * 874 * \param archivesFirst Non-zero to prepend the archives to the search path. 875 * Zero to append them. Ignored if !(archiveExt). 876 * 877 * \return nonzero on success, zero on error. Specifics of the error can be 878 * gleaned from PHYSFS_getLastError(). 879 */ 880 __EXPORT__ int PHYSFS_setSaneConfig(const char *organization, 881 const char *appName, 882 const char *archiveExt, 883 int includeCdRoms, 884 int archivesFirst); 885 886 887 /* Directory management stuff ... */ 888 889 /** 890 * \fn int PHYSFS_mkdir(const char *dirName) 891 * \brief Create a directory. 892 * 893 * This is specified in platform-independent notation in relation to the 894 * write dir. All missing parent directories are also created if they 895 * don't exist. 896 * 897 * So if you've got the write dir set to "C:\mygame\writedir" and call 898 * PHYSFS_mkdir("downloads/maps") then the directories 899 * "C:\mygame\writedir\downloads" and "C:\mygame\writedir\downloads\maps" 900 * will be created if possible. If the creation of "maps" fails after we 901 * have successfully created "downloads", then the function leaves the 902 * created directory behind and reports failure. 903 * 904 * \param dirName New dir to create. 905 * \return nonzero on success, zero on error. Specifics of the error can be 906 * gleaned from PHYSFS_getLastError(). 907 * 908 * \sa PHYSFS_delete 909 */ 910 __EXPORT__ int PHYSFS_mkdir(const char *dirName); 911 912 913 /** 914 * \fn int PHYSFS_delete(const char *filename) 915 * \brief Delete a file or directory. 916 * 917 * (filename) is specified in platform-independent notation in relation to the 918 * write dir. 919 * 920 * A directory must be empty before this call can delete it. 921 * 922 * Deleting a symlink will remove the link, not what it points to, regardless 923 * of whether you "permitSymLinks" or not. 924 * 925 * So if you've got the write dir set to "C:\mygame\writedir" and call 926 * PHYSFS_delete("downloads/maps/level1.map") then the file 927 * "C:\mygame\writedir\downloads\maps\level1.map" is removed from the 928 * physical filesystem, if it exists and the operating system permits the 929 * deletion. 930 * 931 * Note that on Unix systems, deleting a file may be successful, but the 932 * actual file won't be removed until all processes that have an open 933 * filehandle to it (including your program) close their handles. 934 * 935 * Chances are, the bits that make up the file still exist, they are just 936 * made available to be written over at a later point. Don't consider this 937 * a security method or anything. :) 938 * 939 * \param filename Filename to delete. 940 * \return nonzero on success, zero on error. Specifics of the error can be 941 * gleaned from PHYSFS_getLastError(). 942 */ 943 __EXPORT__ int PHYSFS_delete(const char *filename); 944 945 946 /** 947 * \fn const char *PHYSFS_getRealDir(const char *filename) 948 * \brief Figure out where in the search path a file resides. 949 * 950 * The file is specified in platform-independent notation. The returned 951 * filename will be the element of the search path where the file was found, 952 * which may be a directory, or an archive. Even if there are multiple 953 * matches in different parts of the search path, only the first one found 954 * is used, just like when opening a file. 955 * 956 * So, if you look for "maps/level1.map", and C:\\mygame is in your search 957 * path and C:\\mygame\\maps\\level1.map exists, then "C:\mygame" is returned. 958 * 959 * If a any part of a match is a symbolic link, and you've not explicitly 960 * permitted symlinks, then it will be ignored, and the search for a match 961 * will continue. 962 * 963 * If you specify a fake directory that only exists as a mount point, it'll 964 * be associated with the first archive mounted there, even though that 965 * directory isn't necessarily contained in a real archive. 966 * 967 * \param filename file to look for. 968 * \return READ ONLY string of element of search path containing the 969 * the file in question. NULL if not found. 970 */ 971 __EXPORT__ const char *PHYSFS_getRealDir(const char *filename); 972 973 974 /** 975 * \fn char **PHYSFS_enumerateFiles(const char *dir) 976 * \brief Get a file listing of a search path's directory. 977 * 978 * Matching directories are interpolated. That is, if "C:\mydir" is in the 979 * search path and contains a directory "savegames" that contains "x.sav", 980 * "y.sav", and "z.sav", and there is also a "C:\userdir" in the search path 981 * that has a "savegames" subdirectory with "w.sav", then the following code: 982 * 983 * \code 984 * char **rc = PHYSFS_enumerateFiles("savegames"); 985 * char **i; 986 * 987 * for (i = rc; *i != NULL; i++) 988 * printf(" * We've got [%s].\n", *i); 989 * 990 * PHYSFS_freeList(rc); 991 * \endcode 992 * 993 * \...will print: 994 * 995 * \verbatim 996 * We've got [x.sav]. 997 * We've got [y.sav]. 998 * We've got [z.sav]. 999 * We've got [w.sav].\endverbatim 1000 * 1001 * Feel free to sort the list however you like. We only promise there will 1002 * be no duplicates, but not what order the final list will come back in. 1003 * 1004 * Don't forget to call PHYSFS_freeList() with the return value from this 1005 * function when you are done with it. 1006 * 1007 * \param dir directory in platform-independent notation to enumerate. 1008 * \return Null-terminated array of null-terminated strings. 1009 * 1010 * \sa PHYSFS_enumerateFilesCallback 1011 */ 1012 __EXPORT__ char **PHYSFS_enumerateFiles(const char *dir); 1013 1014 1015 /** 1016 * \fn int PHYSFS_exists(const char *fname) 1017 * \brief Determine if a file exists in the search path. 1018 * 1019 * Reports true if there is an entry anywhere in the search path by the 1020 * name of (fname). 1021 * 1022 * Note that entries that are symlinks are ignored if 1023 * PHYSFS_permitSymbolicLinks(1) hasn't been called, so you 1024 * might end up further down in the search path than expected. 1025 * 1026 * \param fname filename in platform-independent notation. 1027 * \return non-zero if filename exists. zero otherwise. 1028 * 1029 * \sa PHYSFS_isDirectory 1030 * \sa PHYSFS_isSymbolicLink 1031 */ 1032 __EXPORT__ int PHYSFS_exists(const char *fname); 1033 1034 1035 /** 1036 * \fn int PHYSFS_isDirectory(const char *fname) 1037 * \brief Determine if a file in the search path is really a directory. 1038 * 1039 * Determine if the first occurence of (fname) in the search path is 1040 * really a directory entry. 1041 * 1042 * Note that entries that are symlinks are ignored if 1043 * PHYSFS_permitSymbolicLinks(1) hasn't been called, so you 1044 * might end up further down in the search path than expected. 1045 * 1046 * \param fname filename in platform-independent notation. 1047 * \return non-zero if filename exists and is a directory. zero otherwise. 1048 * 1049 * \sa PHYSFS_exists 1050 * \sa PHYSFS_isSymbolicLink 1051 */ 1052 __EXPORT__ int PHYSFS_isDirectory(const char *fname); 1053 1054 1055 /** 1056 * \fn int PHYSFS_isSymbolicLink(const char *fname) 1057 * \brief Determine if a file in the search path is really a symbolic link. 1058 * 1059 * Determine if the first occurence of (fname) in the search path is 1060 * really a symbolic link. 1061 * 1062 * Note that entries that are symlinks are ignored if 1063 * PHYSFS_permitSymbolicLinks(1) hasn't been called, and as such, 1064 * this function will always return 0 in that case. 1065 * 1066 * \param fname filename in platform-independent notation. 1067 * \return non-zero if filename exists and is a symlink. zero otherwise. 1068 * 1069 * \sa PHYSFS_exists 1070 * \sa PHYSFS_isDirectory 1071 */ 1072 __EXPORT__ int PHYSFS_isSymbolicLink(const char *fname); 1073 1074 1075 /** 1076 * \fn PHYSFS_sint64 PHYSFS_getLastModTime(const char *filename) 1077 * \brief Get the last modification time of a file. 1078 * 1079 * The modtime is returned as a number of seconds since the epoch 1080 * (Jan 1, 1970). The exact derivation and accuracy of this time depends on 1081 * the particular archiver. If there is no reasonable way to obtain this 1082 * information for a particular archiver, or there was some sort of error, 1083 * this function returns (-1). 1084 * 1085 * \param filename filename to check, in platform-independent notation. 1086 * \return last modified time of the file. -1 if it can't be determined. 1087 */ 1088 __EXPORT__ PHYSFS_sint64 PHYSFS_getLastModTime(const char *filename); 1089 1090 1091 /* i/o stuff... */ 1092 1093 /** 1094 * \fn PHYSFS_File *PHYSFS_openWrite(const char *filename) 1095 * \brief Open a file for writing. 1096 * 1097 * Open a file for writing, in platform-independent notation and in relation 1098 * to the write dir as the root of the writable filesystem. The specified 1099 * file is created if it doesn't exist. If it does exist, it is truncated to 1100 * zero bytes, and the writing offset is set to the start. 1101 * 1102 * Note that entries that are symlinks are ignored if 1103 * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a 1104 * symlink with this function will fail in such a case. 1105 * 1106 * \param filename File to open. 1107 * \return A valid PhysicsFS filehandle on success, NULL on error. Specifics 1108 * of the error can be gleaned from PHYSFS_getLastError(). 1109 * 1110 * \sa PHYSFS_openRead 1111 * \sa PHYSFS_openAppend 1112 * \sa PHYSFS_write 1113 * \sa PHYSFS_close 1114 */ 1115 __EXPORT__ PHYSFS_File *PHYSFS_openWrite(const char *filename); 1116 1117 1118 /** 1119 * \fn PHYSFS_File *PHYSFS_openAppend(const char *filename) 1120 * \brief Open a file for appending. 1121 * 1122 * Open a file for writing, in platform-independent notation and in relation 1123 * to the write dir as the root of the writable filesystem. The specified 1124 * file is created if it doesn't exist. If it does exist, the writing offset 1125 * is set to the end of the file, so the first write will be the byte after 1126 * the end. 1127 * 1128 * Note that entries that are symlinks are ignored if 1129 * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a 1130 * symlink with this function will fail in such a case. 1131 * 1132 * \param filename File to open. 1133 * \return A valid PhysicsFS filehandle on success, NULL on error. Specifics 1134 * of the error can be gleaned from PHYSFS_getLastError(). 1135 * 1136 * \sa PHYSFS_openRead 1137 * \sa PHYSFS_openWrite 1138 * \sa PHYSFS_write 1139 * \sa PHYSFS_close 1140 */ 1141 __EXPORT__ PHYSFS_File *PHYSFS_openAppend(const char *filename); 1142 1143 1144 /** 1145 * \fn PHYSFS_File *PHYSFS_openRead(const char *filename) 1146 * \brief Open a file for reading. 1147 * 1148 * Open a file for reading, in platform-independent notation. The search path 1149 * is checked one at a time until a matching file is found, in which case an 1150 * abstract filehandle is associated with it, and reading may be done. 1151 * The reading offset is set to the first byte of the file. 1152 * 1153 * Note that entries that are symlinks are ignored if 1154 * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a 1155 * symlink with this function will fail in such a case. 1156 * 1157 * \param filename File to open. 1158 * \return A valid PhysicsFS filehandle on success, NULL on error. Specifics 1159 * of the error can be gleaned from PHYSFS_getLastError(). 1160 * 1161 * \sa PHYSFS_openWrite 1162 * \sa PHYSFS_openAppend 1163 * \sa PHYSFS_read 1164 * \sa PHYSFS_close 1165 */ 1166 __EXPORT__ PHYSFS_File *PHYSFS_openRead(const char *filename); 1167 1168 1169 /** 1170 * \fn int PHYSFS_close(PHYSFS_File *handle) 1171 * \brief Close a PhysicsFS filehandle. 1172 * 1173 * This call is capable of failing if the operating system was buffering 1174 * writes to the physical media, and, now forced to write those changes to 1175 * physical media, can not store the data for some reason. In such a case, 1176 * the filehandle stays open. A well-written program should ALWAYS check the 1177 * return value from the close call in addition to every writing call! 1178 * 1179 * \param handle handle returned from PHYSFS_open*(). 1180 * \return nonzero on success, zero on error. Specifics of the error can be 1181 * gleaned from PHYSFS_getLastError(). 1182 * 1183 * \sa PHYSFS_openRead 1184 * \sa PHYSFS_openWrite 1185 * \sa PHYSFS_openAppend 1186 */ 1187 __EXPORT__ int PHYSFS_close(PHYSFS_File *handle); 1188 1189 1190 /** 1191 * \fn PHYSFS_sint64 PHYSFS_read(PHYSFS_File *handle, void *buffer, PHYSFS_uint32 objSize, PHYSFS_uint32 objCount) 1192 * \brief Read data from a PhysicsFS filehandle 1193 * 1194 * The file must be opened for reading. 1195 * 1196 * \param handle handle returned from PHYSFS_openRead(). 1197 * \param buffer buffer to store read data into. 1198 * \param objSize size in bytes of objects being read from (handle). 1199 * \param objCount number of (objSize) objects to read from (handle). 1200 * \return number of objects read. PHYSFS_getLastError() can shed light on 1201 * the reason this might be < (objCount), as can PHYSFS_eof(). 1202 * -1 if complete failure. 1203 * 1204 * \sa PHYSFS_eof 1205 */ 1206 __EXPORT__ PHYSFS_sint64 PHYSFS_read(PHYSFS_File *handle, 1207 void *buffer, 1208 PHYSFS_uint32 objSize, 1209 PHYSFS_uint32 objCount); 1210 1211 /** 1212 * \fn PHYSFS_sint64 PHYSFS_write(PHYSFS_File *handle, const void *buffer, PHYSFS_uint32 objSize, PHYSFS_uint32 objCount) 1213 * \brief Write data to a PhysicsFS filehandle 1214 * 1215 * The file must be opened for writing. 1216 * 1217 * \param handle retval from PHYSFS_openWrite() or PHYSFS_openAppend(). 1218 * \param buffer buffer of bytes to write to (handle). 1219 * \param objSize size in bytes of objects being written to (handle). 1220 * \param objCount number of (objSize) objects to write to (handle). 1221 * \return number of objects written. PHYSFS_getLastError() can shed light on 1222 * the reason this might be < (objCount). -1 if complete failure. 1223 */ 1224 __EXPORT__ PHYSFS_sint64 PHYSFS_write(PHYSFS_File *handle, 1225 const void *buffer, 1226 PHYSFS_uint32 objSize, 1227 PHYSFS_uint32 objCount); 1228 1229 1230 /* File position stuff... */ 1231 1232 /** 1233 * \fn int PHYSFS_eof(PHYSFS_File *handle) 1234 * \brief Check for end-of-file state on a PhysicsFS filehandle. 1235 * 1236 * Determine if the end of file has been reached in a PhysicsFS filehandle. 1237 * 1238 * \param handle handle returned from PHYSFS_openRead(). 1239 * \return nonzero if EOF, zero if not. 1240 * 1241 * \sa PHYSFS_read 1242 * \sa PHYSFS_tell 1243 */ 1244 __EXPORT__ int PHYSFS_eof(PHYSFS_File *handle); 1245 1246 1247 /** 1248 * \fn PHYSFS_sint64 PHYSFS_tell(PHYSFS_File *handle) 1249 * \brief Determine current position within a PhysicsFS filehandle. 1250 * 1251 * \param handle handle returned from PHYSFS_open*(). 1252 * \return offset in bytes from start of file. -1 if error occurred. 1253 * Specifics of the error can be gleaned from PHYSFS_getLastError(). 1254 * 1255 * \sa PHYSFS_seek 1256 */ 1257 __EXPORT__ PHYSFS_sint64 PHYSFS_tell(PHYSFS_File *handle); 1258 1259 1260 /** 1261 * \fn int PHYSFS_seek(PHYSFS_File *handle, PHYSFS_uint64 pos) 1262 * \brief Seek to a new position within a PhysicsFS filehandle. 1263 * 1264 * The next read or write will occur at that place. Seeking past the 1265 * beginning or end of the file is not allowed, and causes an error. 1266 * 1267 * \param handle handle returned from PHYSFS_open*(). 1268 * \param pos number of bytes from start of file to seek to. 1269 * \return nonzero on success, zero on error. Specifics of the error can be 1270 * gleaned from PHYSFS_getLastError(). 1271 * 1272 * \sa PHYSFS_tell 1273 */ 1274 __EXPORT__ int PHYSFS_seek(PHYSFS_File *handle, PHYSFS_uint64 pos); 1275 1276 1277 /** 1278 * \fn PHYSFS_sint64 PHYSFS_fileLength(PHYSFS_File *handle) 1279 * \brief Get total length of a file in bytes. 1280 * 1281 * Note that if the file size can't be determined (since the archive is 1282 * "streamed" or whatnot) than this will report (-1). Also note that if 1283 * another process/thread is writing to this file at the same time, then 1284 * the information this function supplies could be incorrect before you 1285 * get it. Use with caution, or better yet, don't use at all. 1286 * 1287 * \param handle handle returned from PHYSFS_open*(). 1288 * \return size in bytes of the file. -1 if can't be determined. 1289 * 1290 * \sa PHYSFS_tell 1291 * \sa PHYSFS_seek 1292 */ 1293 __EXPORT__ PHYSFS_sint64 PHYSFS_fileLength(PHYSFS_File *handle); 1294 1295 1296 /* Buffering stuff... */ 1297 1298 /** 1299 * \fn int PHYSFS_setBuffer(PHYSFS_File *handle, PHYSFS_uint64 bufsize) 1300 * \brief Set up buffering for a PhysicsFS file handle. 1301 * 1302 * Define an i/o buffer for a file handle. A memory block of (bufsize) bytes 1303 * will be allocated and associated with (handle). 1304 * 1305 * For files opened for reading, up to (bufsize) bytes are read from (handle) 1306 * and stored in the internal buffer. Calls to PHYSFS_read() will pull 1307 * from this buffer until it is empty, and then refill it for more reading. 1308 * Note that compressed files, like ZIP archives, will decompress while 1309 * buffering, so this can be handy for offsetting CPU-intensive operations. 1310 * The buffer isn't filled until you do your next read. 1311 * 1312 * For files opened for writing, data will be buffered to memory until the 1313 * buffer is full or the buffer is flushed. Closing a handle implicitly 1314 * causes a flush...check your return values! 1315 * 1316 * Seeking, etc transparently accounts for buffering. 1317 * 1318 * You can resize an existing buffer by calling this function more than once 1319 * on the same file. Setting the buffer size to zero will free an existing 1320 * buffer. 1321 * 1322 * PhysicsFS file handles are unbuffered by default. 1323 * 1324 * Please check the return value of this function! Failures can include 1325 * not being able to seek backwards in a read-only file when removing the 1326 * buffer, not being able to allocate the buffer, and not being able to 1327 * flush the buffer to disk, among other unexpected problems. 1328 * 1329 * \param handle handle returned from PHYSFS_open*(). 1330 * \param bufsize size, in bytes, of buffer to allocate. 1331 * \return nonzero if successful, zero on error. 1332 * 1333 * \sa PHYSFS_flush 1334 * \sa PHYSFS_read 1335 * \sa PHYSFS_write 1336 * \sa PHYSFS_close 1337 */ 1338 __EXPORT__ int PHYSFS_setBuffer(PHYSFS_File *handle, PHYSFS_uint64 bufsize); 1339 1340 1341 /** 1342 * \fn int PHYSFS_flush(PHYSFS_File *handle) 1343 * \brief Flush a buffered PhysicsFS file handle. 1344 * 1345 * For buffered files opened for writing, this will put the current contents 1346 * of the buffer to disk and flag the buffer as empty if possible. 1347 * 1348 * For buffered files opened for reading or unbuffered files, this is a safe 1349 * no-op, and will report success. 1350 * 1351 * \param handle handle returned from PHYSFS_open*(). 1352 * \return nonzero if successful, zero on error. 1353 * 1354 * \sa PHYSFS_setBuffer 1355 * \sa PHYSFS_close 1356 */ 1357 __EXPORT__ int PHYSFS_flush(PHYSFS_File *handle); 1358 1359 1360 /* Byteorder stuff... */ 1361 1362 /** 1363 * \fn PHYSFS_sint16 PHYSFS_swapSLE16(PHYSFS_sint16 val) 1364 * \brief Swap littleendian signed 16 to platform's native byte order. 1365 * 1366 * Take a 16-bit signed value in littleendian format and convert it to 1367 * the platform's native byte order. 1368 * 1369 * \param val value to convert 1370 * \return converted value. 1371 */ 1372 __EXPORT__ PHYSFS_sint16 PHYSFS_swapSLE16(PHYSFS_sint16 val); 1373 1374 1375 /** 1376 * \fn PHYSFS_uint16 PHYSFS_swapULE16(PHYSFS_uint16 val) 1377 * \brief Swap littleendian unsigned 16 to platform's native byte order. 1378 * 1379 * Take a 16-bit unsigned value in littleendian format and convert it to 1380 * the platform's native byte order. 1381 * 1382 * \param val value to convert 1383 * \return converted value. 1384 */ 1385 __EXPORT__ PHYSFS_uint16 PHYSFS_swapULE16(PHYSFS_uint16 val); 1386 1387 /** 1388 * \fn PHYSFS_sint32 PHYSFS_swapSLE32(PHYSFS_sint32 val) 1389 * \brief Swap littleendian signed 32 to platform's native byte order. 1390 * 1391 * Take a 32-bit signed value in littleendian format and convert it to 1392 * the platform's native byte order. 1393 * 1394 * \param val value to convert 1395 * \return converted value. 1396 */ 1397 __EXPORT__ PHYSFS_sint32 PHYSFS_swapSLE32(PHYSFS_sint32 val); 1398 1399 1400 /** 1401 * \fn PHYSFS_uint32 PHYSFS_swapULE32(PHYSFS_uint32 val) 1402 * \brief Swap littleendian unsigned 32 to platform's native byte order. 1403 * 1404 * Take a 32-bit unsigned value in littleendian format and convert it to 1405 * the platform's native byte order. 1406 * 1407 * \param val value to convert 1408 * \return converted value. 1409 */ 1410 __EXPORT__ PHYSFS_uint32 PHYSFS_swapULE32(PHYSFS_uint32 val); 1411 1412 /** 1413 * \fn PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 val) 1414 * \brief Swap littleendian signed 64 to platform's native byte order. 1415 * 1416 * Take a 64-bit signed value in littleendian format and convert it to 1417 * the platform's native byte order. 1418 * 1419 * \param val value to convert 1420 * \return converted value. 1421 * 1422 * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without 1423 * any sort of 64-bit support. 1424 */ 1425 __EXPORT__ PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 val); 1426 1427 1428 /** 1429 * \fn PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 val) 1430 * \brief Swap littleendian unsigned 64 to platform's native byte order. 1431 * 1432 * Take a 64-bit unsigned value in littleendian format and convert it to 1433 * the platform's native byte order. 1434 * 1435 * \param val value to convert 1436 * \return converted value. 1437 * 1438 * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without 1439 * any sort of 64-bit support. 1440 */ 1441 __EXPORT__ PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 val); 1442 1443 1444 /** 1445 * \fn PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 val) 1446 * \brief Swap bigendian signed 16 to platform's native byte order. 1447 * 1448 * Take a 16-bit signed value in bigendian format and convert it to 1449 * the platform's native byte order. 1450 * 1451 * \param val value to convert 1452 * \return converted value. 1453 */ 1454 __EXPORT__ PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 val); 1455 1456 1457 /** 1458 * \fn PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 val) 1459 * \brief Swap bigendian unsigned 16 to platform's native byte order. 1460 * 1461 * Take a 16-bit unsigned value in bigendian format and convert it to 1462 * the platform's native byte order. 1463 * 1464 * \param val value to convert 1465 * \return converted value. 1466 */ 1467 __EXPORT__ PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 val); 1468 1469 /** 1470 * \fn PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 val) 1471 * \brief Swap bigendian signed 32 to platform's native byte order. 1472 * 1473 * Take a 32-bit signed value in bigendian format and convert it to 1474 * the platform's native byte order. 1475 * 1476 * \param val value to convert 1477 * \return converted value. 1478 */ 1479 __EXPORT__ PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 val); 1480 1481 1482 /** 1483 * \fn PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 val) 1484 * \brief Swap bigendian unsigned 32 to platform's native byte order. 1485 * 1486 * Take a 32-bit unsigned value in bigendian format and convert it to 1487 * the platform's native byte order. 1488 * 1489 * \param val value to convert 1490 * \return converted value. 1491 */ 1492 __EXPORT__ PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 val); 1493 1494 1495 /** 1496 * \fn PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 val) 1497 * \brief Swap bigendian signed 64 to platform's native byte order. 1498 * 1499 * Take a 64-bit signed value in bigendian format and convert it to 1500 * the platform's native byte order. 1501 * 1502 * \param val value to convert 1503 * \return converted value. 1504 * 1505 * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without 1506 * any sort of 64-bit support. 1507 */ 1508 __EXPORT__ PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 val); 1509 1510 1511 /** 1512 * \fn PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 val) 1513 * \brief Swap bigendian unsigned 64 to platform's native byte order. 1514 * 1515 * Take a 64-bit unsigned value in bigendian format and convert it to 1516 * the platform's native byte order. 1517 * 1518 * \param val value to convert 1519 * \return converted value. 1520 * 1521 * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without 1522 * any sort of 64-bit support. 1523 */ 1524 __EXPORT__ PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 val); 1525 1526 1527 /** 1528 * \fn int PHYSFS_readSLE16(PHYSFS_File *file, PHYSFS_sint16 *val) 1529 * \brief Read and convert a signed 16-bit littleendian value. 1530 * 1531 * Convenience function. Read a signed 16-bit littleendian value from a 1532 * file and convert it to the platform's native byte order. 1533 * 1534 * \param file PhysicsFS file handle from which to read. 1535 * \param val pointer to where value should be stored. 1536 * \return zero on failure, non-zero on success. If successful, (*val) will 1537 * store the result. On failure, you can find out what went wrong 1538 * from PHYSFS_getLastError(). 1539 */ 1540 __EXPORT__ int PHYSFS_readSLE16(PHYSFS_File *file, PHYSFS_sint16 *val); 1541 1542 1543 /** 1544 * \fn int PHYSFS_readULE16(PHYSFS_File *file, PHYSFS_uint16 *val) 1545 * \brief Read and convert an unsigned 16-bit littleendian value. 1546 * 1547 * Convenience function. Read an unsigned 16-bit littleendian value from a 1548 * file and convert it to the platform's native byte order. 1549 * 1550 * \param file PhysicsFS file handle from which to read. 1551 * \param val pointer to where value should be stored. 1552 * \return zero on failure, non-zero on success. If successful, (*val) will 1553 * store the result. On failure, you can find out what went wrong 1554 * from PHYSFS_getLastError(). 1555 * 1556 */ 1557 __EXPORT__ int PHYSFS_readULE16(PHYSFS_File *file, PHYSFS_uint16 *val); 1558 1559 1560 /** 1561 * \fn int PHYSFS_readSBE16(PHYSFS_File *file, PHYSFS_sint16 *val) 1562 * \brief Read and convert a signed 16-bit bigendian value. 1563 * 1564 * Convenience function. Read a signed 16-bit bigendian value from a 1565 * file and convert it to the platform's native byte order. 1566 * 1567 * \param file PhysicsFS file handle from which to read. 1568 * \param val pointer to where value should be stored. 1569 * \return zero on failure, non-zero on success. If successful, (*val) will 1570 * store the result. On failure, you can find out what went wrong 1571 * from PHYSFS_getLastError(). 1572 */ 1573 __EXPORT__ int PHYSFS_readSBE16(PHYSFS_File *file, PHYSFS_sint16 *val); 1574 1575 1576 /** 1577 * \fn int PHYSFS_readUBE16(PHYSFS_File *file, PHYSFS_uint16 *val) 1578 * \brief Read and convert an unsigned 16-bit bigendian value. 1579 * 1580 * Convenience function. Read an unsigned 16-bit bigendian value from a 1581 * file and convert it to the platform's native byte order. 1582 * 1583 * \param file PhysicsFS file handle from which to read. 1584 * \param val pointer to where value should be stored. 1585 * \return zero on failure, non-zero on success. If successful, (*val) will 1586 * store the result. On failure, you can find out what went wrong 1587 * from PHYSFS_getLastError(). 1588 * 1589 */ 1590 __EXPORT__ int PHYSFS_readUBE16(PHYSFS_File *file, PHYSFS_uint16 *val); 1591 1592 1593 /** 1594 * \fn int PHYSFS_readSLE32(PHYSFS_File *file, PHYSFS_sint32 *val) 1595 * \brief Read and convert a signed 32-bit littleendian value. 1596 * 1597 * Convenience function. Read a signed 32-bit littleendian value from a 1598 * file and convert it to the platform's native byte order. 1599 * 1600 * \param file PhysicsFS file handle from which to read. 1601 * \param val pointer to where value should be stored. 1602 * \return zero on failure, non-zero on success. If successful, (*val) will 1603 * store the result. On failure, you can find out what went wrong 1604 * from PHYSFS_getLastError(). 1605 */ 1606 __EXPORT__ int PHYSFS_readSLE32(PHYSFS_File *file, PHYSFS_sint32 *val); 1607 1608 1609 /** 1610 * \fn int PHYSFS_readULE32(PHYSFS_File *file, PHYSFS_uint32 *val) 1611 * \brief Read and convert an unsigned 32-bit littleendian value. 1612 * 1613 * Convenience function. Read an unsigned 32-bit littleendian value from a 1614 * file and convert it to the platform's native byte order. 1615 * 1616 * \param file PhysicsFS file handle from which to read. 1617 * \param val pointer to where value should be stored. 1618 * \return zero on failure, non-zero on success. If successful, (*val) will 1619 * store the result. On failure, you can find out what went wrong 1620 * from PHYSFS_getLastError(). 1621 * 1622 */ 1623 __EXPORT__ int PHYSFS_readULE32(PHYSFS_File *file, PHYSFS_uint32 *val); 1624 1625 1626 /** 1627 * \fn int PHYSFS_readSBE32(PHYSFS_File *file, PHYSFS_sint32 *val) 1628 * \brief Read and convert a signed 32-bit bigendian value. 1629 * 1630 * Convenience function. Read a signed 32-bit bigendian value from a 1631 * file and convert it to the platform's native byte order. 1632 * 1633 * \param file PhysicsFS file handle from which to read. 1634 * \param val pointer to where value should be stored. 1635 * \return zero on failure, non-zero on success. If successful, (*val) will 1636 * store the result. On failure, you can find out what went wrong 1637 * from PHYSFS_getLastError(). 1638 */ 1639 __EXPORT__ int PHYSFS_readSBE32(PHYSFS_File *file, PHYSFS_sint32 *val); 1640 1641 1642 /** 1643 * \fn int PHYSFS_readUBE32(PHYSFS_File *file, PHYSFS_uint32 *val) 1644 * \brief Read and convert an unsigned 32-bit bigendian value. 1645 * 1646 * Convenience function. Read an unsigned 32-bit bigendian value from a 1647 * file and convert it to the platform's native byte order. 1648 * 1649 * \param file PhysicsFS file handle from which to read. 1650 * \param val pointer to where value should be stored. 1651 * \return zero on failure, non-zero on success. If successful, (*val) will 1652 * store the result. On failure, you can find out what went wrong 1653 * from PHYSFS_getLastError(). 1654 * 1655 */ 1656 __EXPORT__ int PHYSFS_readUBE32(PHYSFS_File *file, PHYSFS_uint32 *val); 1657 1658 1659 /** 1660 * \fn int PHYSFS_readSLE64(PHYSFS_File *file, PHYSFS_sint64 *val) 1661 * \brief Read and convert a signed 64-bit littleendian value. 1662 * 1663 * Convenience function. Read a signed 64-bit littleendian value from a 1664 * file and convert it to the platform's native byte order. 1665 * 1666 * \param file PhysicsFS file handle from which to read. 1667 * \param val pointer to where value should be stored. 1668 * \return zero on failure, non-zero on success. If successful, (*val) will 1669 * store the result. On failure, you can find out what went wrong 1670 * from PHYSFS_getLastError(). 1671 * 1672 * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without 1673 * any sort of 64-bit support. 1674 */ 1675 __EXPORT__ int PHYSFS_readSLE64(PHYSFS_File *file, PHYSFS_sint64 *val); 1676 1677 1678 /** 1679 * \fn int PHYSFS_readULE64(PHYSFS_File *file, PHYSFS_uint64 *val) 1680 * \brief Read and convert an unsigned 64-bit littleendian value. 1681 * 1682 * Convenience function. Read an unsigned 64-bit littleendian value from a 1683 * file and convert it to the platform's native byte order. 1684 * 1685 * \param file PhysicsFS file handle from which to read. 1686 * \param val pointer to where value should be stored. 1687 * \return zero on failure, non-zero on success. If successful, (*val) will 1688 * store the result. On failure, you can find out what went wrong 1689 * from PHYSFS_getLastError(). 1690 * 1691 * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without 1692 * any sort of 64-bit support. 1693 */ 1694 __EXPORT__ int PHYSFS_readULE64(PHYSFS_File *file, PHYSFS_uint64 *val); 1695 1696 1697 /** 1698 * \fn int PHYSFS_readSBE64(PHYSFS_File *file, PHYSFS_sint64 *val) 1699 * \brief Read and convert a signed 64-bit bigendian value. 1700 * 1701 * Convenience function. Read a signed 64-bit bigendian value from a 1702 * file and convert it to the platform's native byte order. 1703 * 1704 * \param file PhysicsFS file handle from which to read. 1705 * \param val pointer to where value should be stored. 1706 * \return zero on failure, non-zero on success. If successful, (*val) will 1707 * store the result. On failure, you can find out what went wrong 1708 * from PHYSFS_getLastError(). 1709 * 1710 * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without 1711 * any sort of 64-bit support. 1712 */ 1713 __EXPORT__ int PHYSFS_readSBE64(PHYSFS_File *file, PHYSFS_sint64 *val); 1714 1715 1716 /** 1717 * \fn int PHYSFS_readUBE64(PHYSFS_File *file, PHYSFS_uint64 *val) 1718 * \brief Read and convert an unsigned 64-bit bigendian value. 1719 * 1720 * Convenience function. Read an unsigned 64-bit bigendian value from a 1721 * file and convert it to the platform's native byte order. 1722 * 1723 * \param file PhysicsFS file handle from which to read. 1724 * \param val pointer to where value should be stored. 1725 * \return zero on failure, non-zero on success. If successful, (*val) will 1726 * store the result. On failure, you can find out what went wrong 1727 * from PHYSFS_getLastError(). 1728 * 1729 * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without 1730 * any sort of 64-bit support. 1731 */ 1732 __EXPORT__ int PHYSFS_readUBE64(PHYSFS_File *file, PHYSFS_uint64 *val); 1733 1734 1735 /** 1736 * \fn int PHYSFS_writeSLE16(PHYSFS_File *file, PHYSFS_sint16 val) 1737 * \brief Convert and write a signed 16-bit littleendian value. 1738 * 1739 * Convenience function. Convert a signed 16-bit value from the platform's 1740 * native byte order to littleendian and write it to a file. 1741 * 1742 * \param file PhysicsFS file handle to which to write. 1743 * \param val Value to convert and write. 1744 * \return zero on failure, non-zero on success. On failure, you can 1745 * find out what went wrong from PHYSFS_getLastError(). 1746 */ 1747 __EXPORT__ int PHYSFS_writeSLE16(PHYSFS_File *file, PHYSFS_sint16 val); 1748 1749 1750 /** 1751 * \fn int PHYSFS_writeULE16(PHYSFS_File *file, PHYSFS_uint16 val) 1752 * \brief Convert and write an unsigned 16-bit littleendian value. 1753 * 1754 * Convenience function. Convert an unsigned 16-bit value from the platform's 1755 * native byte order to littleendian and write it to a file. 1756 * 1757 * \param file PhysicsFS file handle to which to write. 1758 * \param val Value to convert and write. 1759 * \return zero on failure, non-zero on success. On failure, you can 1760 * find out what went wrong from PHYSFS_getLastError(). 1761 */ 1762 __EXPORT__ int PHYSFS_writeULE16(PHYSFS_File *file, PHYSFS_uint16 val); 1763 1764 1765 /** 1766 * \fn int PHYSFS_writeSBE16(PHYSFS_File *file, PHYSFS_sint16 val) 1767 * \brief Convert and write a signed 16-bit bigendian value. 1768 * 1769 * Convenience function. Convert a signed 16-bit value from the platform's 1770 * native byte order to bigendian and write it to a file. 1771 * 1772 * \param file PhysicsFS file handle to which to write. 1773 * \param val Value to convert and write. 1774 * \return zero on failure, non-zero on success. On failure, you can 1775 * find out what went wrong from PHYSFS_getLastError(). 1776 */ 1777 __EXPORT__ int PHYSFS_writeSBE16(PHYSFS_File *file, PHYSFS_sint16 val); 1778 1779 1780 /** 1781 * \fn int PHYSFS_writeUBE16(PHYSFS_File *file, PHYSFS_uint16 val) 1782 * \brief Convert and write an unsigned 16-bit bigendian value. 1783 * 1784 * Convenience function. Convert an unsigned 16-bit value from the platform's 1785 * native byte order to bigendian and write it to a file. 1786 * 1787 * \param file PhysicsFS file handle to which to write. 1788 * \param val Value to convert and write. 1789 * \return zero on failure, non-zero on success. On failure, you can 1790 * find out what went wrong from PHYSFS_getLastError(). 1791 */ 1792 __EXPORT__ int PHYSFS_writeUBE16(PHYSFS_File *file, PHYSFS_uint16 val); 1793 1794 1795 /** 1796 * \fn int PHYSFS_writeSLE32(PHYSFS_File *file, PHYSFS_sint32 val) 1797 * \brief Convert and write a signed 32-bit littleendian value. 1798 * 1799 * Convenience function. Convert a signed 32-bit value from the platform's 1800 * native byte order to littleendian and write it to a file. 1801 * 1802 * \param file PhysicsFS file handle to which to write. 1803 * \param val Value to convert and write. 1804 * \return zero on failure, non-zero on success. On failure, you can 1805 * find out what went wrong from PHYSFS_getLastError(). 1806 */ 1807 __EXPORT__ int PHYSFS_writeSLE32(PHYSFS_File *file, PHYSFS_sint32 val); 1808 1809 1810 /** 1811 * \fn int PHYSFS_writeULE32(PHYSFS_File *file, PHYSFS_uint32 val) 1812 * \brief Convert and write an unsigned 32-bit littleendian value. 1813 * 1814 * Convenience function. Convert an unsigned 32-bit value from the platform's 1815 * native byte order to littleendian and write it to a file. 1816 * 1817 * \param file PhysicsFS file handle to which to write. 1818 * \param val Value to convert and write. 1819 * \return zero on failure, non-zero on success. On failure, you can 1820 * find out what went wrong from PHYSFS_getLastError(). 1821 */ 1822 __EXPORT__ int PHYSFS_writeULE32(PHYSFS_File *file, PHYSFS_uint32 val); 1823 1824 1825 /** 1826 * \fn int PHYSFS_writeSBE32(PHYSFS_File *file, PHYSFS_sint32 val) 1827 * \brief Convert and write a signed 32-bit bigendian value. 1828 * 1829 * Convenience function. Convert a signed 32-bit value from the platform's 1830 * native byte order to bigendian and write it to a file. 1831 * 1832 * \param file PhysicsFS file handle to which to write. 1833 * \param val Value to convert and write. 1834 * \return zero on failure, non-zero on success. On failure, you can 1835 * find out what went wrong from PHYSFS_getLastError(). 1836 */ 1837 __EXPORT__ int PHYSFS_writeSBE32(PHYSFS_File *file, PHYSFS_sint32 val); 1838 1839 1840 /** 1841 * \fn int PHYSFS_writeUBE32(PHYSFS_File *file, PHYSFS_uint32 val) 1842 * \brief Convert and write an unsigned 32-bit bigendian value. 1843 * 1844 * Convenience function. Convert an unsigned 32-bit value from the platform's 1845 * native byte order to bigendian and write it to a file. 1846 * 1847 * \param file PhysicsFS file handle to which to write. 1848 * \param val Value to convert and write. 1849 * \return zero on failure, non-zero on success. On failure, you can 1850 * find out what went wrong from PHYSFS_getLastError(). 1851 */ 1852 __EXPORT__ int PHYSFS_writeUBE32(PHYSFS_File *file, PHYSFS_uint32 val); 1853 1854 1855 /** 1856 * \fn int PHYSFS_writeSLE64(PHYSFS_File *file, PHYSFS_sint64 val) 1857 * \brief Convert and write a signed 64-bit littleendian value. 1858 * 1859 * Convenience function. Convert a signed 64-bit value from the platform's 1860 * native byte order to littleendian and write it to a file. 1861 * 1862 * \param file PhysicsFS file handle to which to write. 1863 * \param val Value to convert and write. 1864 * \return zero on failure, non-zero on success. On failure, you can 1865 * find out what went wrong from PHYSFS_getLastError(). 1866 * 1867 * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without 1868 * any sort of 64-bit support. 1869 */ 1870 __EXPORT__ int PHYSFS_writeSLE64(PHYSFS_File *file, PHYSFS_sint64 val); 1871 1872 1873 /** 1874 * \fn int PHYSFS_writeULE64(PHYSFS_File *file, PHYSFS_uint64 val) 1875 * \brief Convert and write an unsigned 64-bit littleendian value. 1876 * 1877 * Convenience function. Convert an unsigned 64-bit value from the platform's 1878 * native byte order to littleendian and write it to a file. 1879 * 1880 * \param file PhysicsFS file handle to which to write. 1881 * \param val Value to convert and write. 1882 * \return zero on failure, non-zero on success. On failure, you can 1883 * find out what went wrong from PHYSFS_getLastError(). 1884 * 1885 * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without 1886 * any sort of 64-bit support. 1887 */ 1888 __EXPORT__ int PHYSFS_writeULE64(PHYSFS_File *file, PHYSFS_uint64 val); 1889 1890 1891 /** 1892 * \fn int PHYSFS_writeSBE64(PHYSFS_File *file, PHYSFS_sint64 val) 1893 * \brief Convert and write a signed 64-bit bigending value. 1894 * 1895 * Convenience function. Convert a signed 64-bit value from the platform's 1896 * native byte order to bigendian and write it to a file. 1897 * 1898 * \param file PhysicsFS file handle to which to write. 1899 * \param val Value to convert and write. 1900 * \return zero on failure, non-zero on success. On failure, you can 1901 * find out what went wrong from PHYSFS_getLastError(). 1902 * 1903 * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without 1904 * any sort of 64-bit support. 1905 */ 1906 __EXPORT__ int PHYSFS_writeSBE64(PHYSFS_File *file, PHYSFS_sint64 val); 1907 1908 1909 /** 1910 * \fn int PHYSFS_writeUBE64(PHYSFS_File *file, PHYSFS_uint64 val) 1911 * \brief Convert and write an unsigned 64-bit bigendian value. 1912 * 1913 * Convenience function. Convert an unsigned 64-bit value from the platform's 1914 * native byte order to bigendian and write it to a file. 1915 * 1916 * \param file PhysicsFS file handle to which to write. 1917 * \param val Value to convert and write. 1918 * \return zero on failure, non-zero on success. On failure, you can 1919 * find out what went wrong from PHYSFS_getLastError(). 1920 * 1921 * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without 1922 * any sort of 64-bit support. 1923 */ 1924 __EXPORT__ int PHYSFS_writeUBE64(PHYSFS_File *file, PHYSFS_uint64 val); 1925 1926 1927 /* Everything above this line is part of the PhysicsFS 1.0 API. */ 1928 1929 /** 1930 * \fn int PHYSFS_isInit(void) 1931 * \brief Determine if the PhysicsFS library is initialized. 1932 * 1933 * Once PHYSFS_init() returns successfully, this will return non-zero. 1934 * Before a successful PHYSFS_init() and after PHYSFS_deinit() returns 1935 * successfully, this will return zero. This function is safe to call at 1936 * any time. 1937 * 1938 * \return non-zero if library is initialized, zero if library is not. 1939 * 1940 * \sa PHYSFS_init 1941 * \sa PHYSFS_deinit 1942 */ 1943 __EXPORT__ int PHYSFS_isInit(void); 1944 1945 1946 /** 1947 * \fn int PHYSFS_symbolicLinksPermitted(void) 1948 * \brief Determine if the symbolic links are permitted. 1949 * 1950 * This reports the setting from the last call to PHYSFS_permitSymbolicLinks(). 1951 * If PHYSFS_permitSymbolicLinks() hasn't been called since the library was 1952 * last initialized, symbolic links are implicitly disabled. 1953 * 1954 * \return non-zero if symlinks are permitted, zero if not. 1955 * 1956 * \sa PHYSFS_permitSymbolicLinks 1957 */ 1958 __EXPORT__ int PHYSFS_symbolicLinksPermitted(void); 1959 1960 1961 /** 1962 * \struct PHYSFS_Allocator 1963 * \brief PhysicsFS allocation function pointers. 1964 * 1965 * (This is for limited, hardcore use. If you don't immediately see a need 1966 * for it, you can probably ignore this forever.) 1967 * 1968 * You create one of these structures for use with PHYSFS_setAllocator. 1969 * Allocators are assumed to be reentrant by the caller; please mutex 1970 * accordingly. 1971 * 1972 * Allocations are always discussed in 64-bits, for future expansion...we're 1973 * on the cusp of a 64-bit transition, and we'll probably be allocating 6 1974 * gigabytes like it's nothing sooner or later, and I don't want to change 1975 * this again at that point. If you're on a 32-bit platform and have to 1976 * downcast, it's okay to return NULL if the allocation is greater than 1977 * 4 gigabytes, since you'd have to do so anyhow. 1978 * 1979 * \sa PHYSFS_setAllocator 1980 */ 1981 typedef struct PHYSFS_Allocator 1982 { 1983 int (*Init)(void); /**< Initialize. Can be NULL. Zero on failure. */ 1984 void (*Deinit)(void); /**< Deinitialize your allocator. Can be NULL. */ 1985 void *(*Malloc)(PHYSFS_uint64); /**< Allocate like malloc(). */ 1986 void *(*Realloc)(void *, PHYSFS_uint64); /**< Reallocate like realloc(). */ 1987 void (*Free)(void *); /**< Free memory from Malloc or Realloc. */ 1988 } PHYSFS_Allocator; 1989 1990 1991 /** 1992 * \fn int PHYSFS_setAllocator(const PHYSFS_Allocator *allocator) 1993 * \brief Hook your own allocation routines into PhysicsFS. 1994 * 1995 * (This is for limited, hardcore use. If you don't immediately see a need 1996 * for it, you can probably ignore this forever.) 1997 * 1998 * By default, PhysicsFS will use whatever is reasonable for a platform 1999 * to manage dynamic memory (usually ANSI C malloc/realloc/calloc/free, but 2000 * some platforms might use something else), but in some uncommon cases, the 2001 * app might want more control over the library's memory management. This 2002 * lets you redirect PhysicsFS to use your own allocation routines instead. 2003 * You can only call this function before PHYSFS_init(); if the library is 2004 * initialized, it'll reject your efforts to change the allocator mid-stream. 2005 * You may call this function after PHYSFS_deinit() if you are willing to 2006 * shut down the library and restart it with a new allocator; this is a safe 2007 * and supported operation. The allocator remains intact between deinit/init 2008 * calls. If you want to return to the platform's default allocator, pass a 2009 * NULL in here. 2010 * 2011 * If you aren't immediately sure what to do with this function, you can 2012 * safely ignore it altogether. 2013 * 2014 * \param allocator Structure containing your allocator's entry points. 2015 * \return zero on failure, non-zero on success. This call only fails 2016 * when used between PHYSFS_init() and PHYSFS_deinit() calls. 2017 */ 2018 __EXPORT__ int PHYSFS_setAllocator(const PHYSFS_Allocator *allocator); 2019 2020 2021 /** 2022 * \fn int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath) 2023 * \brief Add an archive or directory to the search path. 2024 * 2025 * If this is a duplicate, the entry is not added again, even though the 2026 * function succeeds. You may not add the same archive to two different 2027 * mountpoints: duplicate checking is done against the archive and not the 2028 * mountpoint. 2029 * 2030 * When you mount an archive, it is added to a virtual file system...all files 2031 * in all of the archives are interpolated into a single hierachical file 2032 * tree. Two archives mounted at the same place (or an archive with files 2033 * overlapping another mountpoint) may have overlapping files: in such a case, 2034 * the file earliest in the search path is selected, and the other files are 2035 * inaccessible to the application. This allows archives to be used to 2036 * override previous revisions; you can use the mounting mechanism to place 2037 * archives at a specific point in the file tree and prevent overlap; this 2038 * is useful for downloadable mods that might trample over application data 2039 * or each other, for example. 2040 * 2041 * The mountpoint does not need to exist prior to mounting, which is different 2042 * than those familiar with the Unix concept of "mounting" may not expect. 2043 * As well, more than one archive can be mounted to the same mountpoint, or 2044 * mountpoints and archive contents can overlap...the interpolation mechanism 2045 * still functions as usual. 2046 * 2047 * \param newDir directory or archive to add to the path, in 2048 * platform-dependent notation. 2049 * \param mountPoint Location in the interpolated tree that this archive 2050 * will be "mounted", in platform-independent notation. 2051 * NULL or "" is equivalent to "/". 2052 * \param appendToPath nonzero to append to search path, zero to prepend. 2053 * \return nonzero if added to path, zero on failure (bogus archive, dir 2054 * missing, etc). Specifics of the error can be 2055 * gleaned from PHYSFS_getLastError(). 2056 * 2057 * \sa PHYSFS_removeFromSearchPath 2058 * \sa PHYSFS_getSearchPath 2059 * \sa PHYSFS_getMountPoint 2060 */ 2061 __EXPORT__ int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath); 2062 2063 /** 2064 * \fn int PHYSFS_getMountPoint(const char *dir) 2065 * \brief Determine a mounted archive's mountpoint. 2066 * 2067 * You give this function the name of an archive or dir you successfully 2068 * added to the search path, and it reports the location in the interpolated 2069 * tree where it is mounted. Files mounted with a NULL mountpoint or through 2070 * PHYSFS_addToSearchPath() will report "/". The return value is READ ONLY 2071 * and valid until the archive is removed from the search path. 2072 * 2073 * \param dir directory or archive previously added to the path, in 2074 * platform-dependent notation. This must match the string 2075 * used when adding, even if your string would also reference 2076 * the same file with a different string of characters. 2077 * \return READ-ONLY string of mount point if added to path, NULL on failure 2078 * (bogus archive, etc) Specifics of the error can be gleaned from 2079 * PHYSFS_getLastError(). 2080 * 2081 * \sa PHYSFS_removeFromSearchPath 2082 * \sa PHYSFS_getSearchPath 2083 * \sa PHYSFS_getMountPoint 2084 */ 2085 __EXPORT__ const char *PHYSFS_getMountPoint(const char *dir); 2086 2087 2088 /** 2089 * \typedef PHYSFS_StringCallback 2090 * \brief Function signature for callbacks that report strings. 2091 * 2092 * These are used to report a list of strings to an original caller, one 2093 * string per callback. All strings are UTF-8 encoded. Functions should not 2094 * try to modify or free the string's memory. 2095 * 2096 * These callbacks are used, starting in PhysicsFS 1.1, as an alternative to 2097 * functions that would return lists that need to be cleaned up with 2098 * PHYSFS_freeList(). The callback means that the library doesn't need to 2099 * allocate an entire list and all the strings up front. 2100 * 2101 * Be aware that promises data ordering in the list versions are not 2102 * necessarily so in the callback versions. Check the documentation on 2103 * specific APIs, but strings may not be sorted as you expect. 2104 * 2105 * \param data User-defined data pointer, passed through from the API 2106 * that eventually called the callback. 2107 * \param str The string data about which the callback is meant to inform. 2108 * 2109 * \sa PHYSFS_getCdRomDirsCallback 2110 * \sa PHYSFS_getSearchPathCallback 2111 */ 2112 typedef void (*PHYSFS_StringCallback)(void *data, const char *str); 2113 2114 2115 /** 2116 * \typedef PHYSFS_EnumFilesCallback 2117 * \brief Function signature for callbacks that enumerate files. 2118 * 2119 * These are used to report a list of directory entries to an original caller, 2120 * one file/dir/symlink per callback. All strings are UTF-8 encoded. 2121 * Functions should not try to modify or free any string's memory. 2122 * 2123 * These callbacks are used, starting in PhysicsFS 1.1, as an alternative to 2124 * functions that would return lists that need to be cleaned up with 2125 * PHYSFS_freeList(). The callback means that the library doesn't need to 2126 * allocate an entire list and all the strings up front. 2127 * 2128 * Be aware that promises data ordering in the list versions are not 2129 * necessarily so in the callback versions. Check the documentation on 2130 * specific APIs, but strings may not be sorted as you expect. 2131 * 2132 * \param data User-defined data pointer, passed through from the API 2133 * that eventually called the callback. 2134 * \param origdir A string containing the full path, in platform-independent 2135 * notation, of the directory containing this file. In most 2136 * cases, this is the directory on which you requested 2137 * enumeration, passed in the callback for your convenience. 2138 * \param fname The filename that is being enumerated. It may not be in 2139 * alphabetical order compared to other callbacks that have 2140 * fired, and it will not contain the full path. You can 2141 * recreate the fullpath with $origdir/$fname ... The file 2142 * can be a subdirectory, a file, a symlink, etc. 2143 * 2144 * \sa PHYSFS_enumerateFilesCallback 2145 */ 2146 typedef void (*PHYSFS_EnumFilesCallback)(void *data, const char *origdir, 2147 const char *fname); 2148 2149 2150 /** 2151 * \fn void PHYSFS_getCdRomDirsCallback(PHYSFS_StringCallback c, void *d) 2152 * \brief Enumerate CD-ROM directories, using an application-defined callback. 2153 * 2154 * Internally, PHYSFS_getCdRomDirs() just calls this function and then builds 2155 * a list before returning to the application, so functionality is identical 2156 * except for how the information is represented to the application. 2157 * 2158 * Unlike PHYSFS_getCdRomDirs(), this function does not return an array. 2159 * Rather, it calls a function specified by the application once per 2160 * detected disc: 2161 * 2162 * \code 2163 * 2164 * static void foundDisc(void *data, const char *cddir) 2165 * { 2166 * printf("cdrom dir [%s] is available.\n", cddir); 2167 * } 2168 * 2169 * // ... 2170 * PHYSFS_getCdRomDirsCallback(foundDisc, NULL); 2171 * \endcode 2172 * 2173 * This call may block while drives spin up. Be forewarned. 2174 * 2175 * \param c Callback function to notify about detected drives. 2176 * \param d Application-defined data passed to callback. Can be NULL. 2177 * 2178 * \sa PHYSFS_StringCallback 2179 * \sa PHYSFS_getCdRomDirs 2180 */ 2181 __EXPORT__ void PHYSFS_getCdRomDirsCallback(PHYSFS_StringCallback c, void *d); 2182 2183 2184 /** 2185 * \fn void PHYSFS_getSearchPathCallback(PHYSFS_StringCallback c, void *d) 2186 * \brief Enumerate the search path, using an application-defined callback. 2187 * 2188 * Internally, PHYSFS_getSearchPath() just calls this function and then builds 2189 * a list before returning to the application, so functionality is identical 2190 * except for how the information is represented to the application. 2191 * 2192 * Unlike PHYSFS_getSearchPath(), this function does not return an array. 2193 * Rather, it calls a function specified by the application once per 2194 * element of the search path: 2195 * 2196 * \code 2197 * 2198 * static void printSearchPath(void *data, const char *pathItem) 2199 * { 2200 * printf("[%s] is in the search path.\n", pathItem); 2201 * } 2202 * 2203 * // ... 2204 * PHYSFS_getSearchPathCallback(printSearchPath, NULL); 2205 * \endcode 2206 * 2207 * Elements of the search path are reported in order search priority, so the 2208 * first archive/dir that would be examined when looking for a file is the 2209 * first element passed through the callback. 2210 * 2211 * \param c Callback function to notify about search path elements. 2212 * \param d Application-defined data passed to callback. Can be NULL. 2213 * 2214 * \sa PHYSFS_StringCallback 2215 * \sa PHYSFS_getSearchPath 2216 */ 2217 __EXPORT__ void PHYSFS_getSearchPathCallback(PHYSFS_StringCallback c, void *d); 2218 2219 2220 /** 2221 * \fn void PHYSFS_enumerateFilesCallback(const char *dir, PHYSFS_EnumFilesCallback c, void *d) 2222 * \brief Get a file listing of a search path's directory, using an application-defined callback. 2223 * 2224 * Internally, PHYSFS_enumerateFiles() just calls this function and then builds 2225 * a list before returning to the application, so functionality is identical 2226 * except for how the information is represented to the application. 2227 * 2228 * Unlike PHYSFS_enumerateFiles(), this function does not return an array. 2229 * Rather, it calls a function specified by the application once per 2230 * element of the search path: 2231 * 2232 * \code 2233 * 2234 * static void printDir(void *data, const char *origdir, const char *fname) 2235 * { 2236 * printf(" * We've got [%s] in [%s].\n", fname, origdir); 2237 * } 2238 * 2239 * // ... 2240 * PHYSFS_enumerateFilesCallback("/some/path", printDir, NULL); 2241 * \endcode 2242 * 2243 * Items sent to the callback are not guaranteed to be in any order whatsoever. 2244 * There is no sorting done at this level, and if you need that, you should 2245 * probably use PHYSFS_enumerateFiles() instead, which guarantees 2246 * alphabetical sorting. This form reports whatever is discovered in each 2247 * archive before moving on to the next. Even within one archive, we can't 2248 * guarantee what order it will discover data. <em>Any sorting you find in 2249 * these callbacks is just pure luck. Do not rely on it.</em> 2250 * 2251 * \param dir Directory, in platform-independent notation, to enumerate. 2252 * \param c Callback function to notify about search path elements. 2253 * \param d Application-defined data passed to callback. Can be NULL. 2254 * 2255 * \sa PHYSFS_EnumFilesCallback 2256 * \sa PHYSFS_enumerateFiles 2257 */ 2258 __EXPORT__ void PHYSFS_enumerateFilesCallback(const char *dir, 2259 PHYSFS_EnumFilesCallback c, 2260 void *d); 2261 2262 /** 2263 * \fn void PHYSFS_utf8FromUcs4(const PHYSFS_uint32 *src, char *dst, PHYSFS_uint64 len) 2264 * \brief Convert a UCS-4 string to a UTF-8 string. 2265 * 2266 * UCS-4 strings are 32-bits per character: \c wchar_t on Unix. 2267 * 2268 * To ensure that the destination buffer is large enough for the conversion, 2269 * please allocate a buffer that is the same size as the source buffer. UTF-8 2270 * never uses more than 32-bits per character, so while it may shrink a UCS-4 2271 * string, it will never expand it. 2272 * 2273 * Strings that don't fit in the destination buffer will be truncated, but 2274 * will always be null-terminated and never have an incomplete UTF-8 2275 * sequence at the end. If the buffer length is 0, this function does nothing. 2276 * 2277 * \param src Null-terminated source string in UCS-4 format. 2278 * \param dst Buffer to store converted UTF-8 string. 2279 * \param len Size, in bytes, of destination buffer. 2280 */ 2281 __EXPORT__ void PHYSFS_utf8FromUcs4(const PHYSFS_uint32 *src, char *dst, 2282 PHYSFS_uint64 len); 2283 2284 /** 2285 * \fn void PHYSFS_utf8ToUcs4(const char *src, PHYSFS_uint32 *dst, PHYSFS_uint64 len) 2286 * \brief Convert a UTF-8 string to a UCS-4 string. 2287 * 2288 * UCS-4 strings are 32-bits per character: \c wchar_t on Unix. 2289 * 2290 * To ensure that the destination buffer is large enough for the conversion, 2291 * please allocate a buffer that is four times the size of the source buffer. 2292 * UTF-8 uses from one to four bytes per character, but UCS-4 always uses 2293 * four, so an entirely low-ASCII string will quadruple in size! 2294 * 2295 * Strings that don't fit in the destination buffer will be truncated, but 2296 * will always be null-terminated and never have an incomplete UCS-4 2297 * sequence at the end. If the buffer length is 0, this function does nothing. 2298 * 2299 * \param src Null-terminated source string in UTF-8 format. 2300 * \param dst Buffer to store converted UCS-4 string. 2301 * \param len Size, in bytes, of destination buffer. 2302 */ 2303 __EXPORT__ void PHYSFS_utf8ToUcs4(const char *src, PHYSFS_uint32 *dst, 2304 PHYSFS_uint64 len); 2305 2306 /** 2307 * \fn void PHYSFS_utf8FromUcs2(const PHYSFS_uint16 *src, char *dst, PHYSFS_uint64 len) 2308 * \brief Convert a UCS-2 string to a UTF-8 string. 2309 * 2310 * UCS-2 strings are 16-bits per character: \c TCHAR on Windows, when building 2311 * with Unicode support. 2312 * 2313 * To ensure that the destination buffer is large enough for the conversion, 2314 * please allocate a buffer that is double the size of the source buffer. 2315 * UTF-8 never uses more than 32-bits per character, so while it may shrink 2316 * a UCS-2 string, it may also expand it. 2317 * 2318 * Strings that don't fit in the destination buffer will be truncated, but 2319 * will always be null-terminated and never have an incomplete UTF-8 2320 * sequence at the end. If the buffer length is 0, this function does nothing. 2321 * 2322 * Please note that UCS-2 is not UTF-16; we do not support the "surrogate" 2323 * values at this time. 2324 * 2325 * \param src Null-terminated source string in UCS-2 format. 2326 * \param dst Buffer to store converted UTF-8 string. 2327 * \param len Size, in bytes, of destination buffer. 2328 */ 2329 __EXPORT__ void PHYSFS_utf8FromUcs2(const PHYSFS_uint16 *src, char *dst, 2330 PHYSFS_uint64 len); 2331 2332 /** 2333 * \fn PHYSFS_utf8ToUcs2(const char *src, PHYSFS_uint16 *dst, PHYSFS_uint64 len) 2334 * \brief Convert a UTF-8 string to a UCS-2 string. 2335 * 2336 * UCS-2 strings are 16-bits per character: \c TCHAR on Windows, when building 2337 * with Unicode support. 2338 * 2339 * To ensure that the destination buffer is large enough for the conversion, 2340 * please allocate a buffer that is double the size of the source buffer. 2341 * UTF-8 uses from one to four bytes per character, but UCS-2 always uses 2342 * two, so an entirely low-ASCII string will double in size! 2343 * 2344 * Strings that don't fit in the destination buffer will be truncated, but 2345 * will always be null-terminated and never have an incomplete UCS-2 2346 * sequence at the end. If the buffer length is 0, this function does nothing. 2347 * 2348 * Please note that UCS-2 is not UTF-16; we do not support the "surrogate" 2349 * values at this time. 2350 * 2351 * \param src Null-terminated source string in UTF-8 format. 2352 * \param dst Buffer to store converted UCS-2 string. 2353 * \param len Size, in bytes, of destination buffer. 2354 */ 2355 __EXPORT__ void PHYSFS_utf8ToUcs2(const char *src, PHYSFS_uint16 *dst, 2356 PHYSFS_uint64 len); 2357 2358 /** 2359 * \fn void PHYSFS_utf8FromLatin1(const char *src, char *dst, PHYSFS_uint64 len) 2360 * \brief Convert a UTF-8 string to a Latin1 string. 2361 * 2362 * Latin1 strings are 8-bits per character: a popular "high ASCII" 2363 * encoding. 2364 * 2365 * To ensure that the destination buffer is large enough for the conversion, 2366 * please allocate a buffer that is double the size of the source buffer. 2367 * UTF-8 expands latin1 codepoints over 127 from 1 to 2 bytes, so the string 2368 * may grow in some cases. 2369 * 2370 * Strings that don't fit in the destination buffer will be truncated, but 2371 * will always be null-terminated and never have an incomplete UTF-8 2372 * sequence at the end. If the buffer length is 0, this function does nothing. 2373 * 2374 * Please note that we do not supply a UTF-8 to Latin1 converter, since Latin1 2375 * can't express most Unicode codepoints. It's a legacy encoding; you should 2376 * be converting away from it at all times. 2377 * 2378 * \param src Null-terminated source string in Latin1 format. 2379 * \param dst Buffer to store converted UTF-8 string. 2380 * \param len Size, in bytes, of destination buffer. 2381 */ 2382 __EXPORT__ void PHYSFS_utf8FromLatin1(const char *src, char *dst, 2383 PHYSFS_uint64 len); 2384 2385 /* Everything above this line is part of the PhysicsFS 2.0 API. */ 2386 2387 2388 #ifdef __cplusplus 2389 } 2390 #endif 2391 2392 #endif /* !defined _INCLUDE_PHYSFS_H_ */ 2393 2394 /* end of physfs.h ... */ 2395 2396