Changeset 25781 in project
- Timestamp:
- 01/07/12 22:10:31 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wiki/eggref/4/physfs
r25461 r25781 1 1 [[tags: egg physicsfs physfs zip 7z archive game]] 2 3 == physicsfs 2 4 3 5 PhysicsFS bindings for Chicken. … … 41 43 Remember that most archive types and platform filesystems store their filenames in a case-sensitive manner, so you should be careful to specify it correctly. 42 44 43 Files opened through PhysicsFS may NOT contain "." or ".." or ":" as dir elements. Not only are these meaningless on MacOS Classic and/or Unix, they are a security hole. Also, symbolic links (which can be found in some archive types and directly in the filesystem on Unix platforms) are NOT followed until you call (permit SymbolicLinks #t). That's left to your own discretion, as following a symlink can allow for access outside the write dir and search paths. For portability, there is no mechanism for creating new symlinks in PhysicsFS.45 Files opened through PhysicsFS may NOT contain "." or ".." or ":" as dir elements. Not only are these meaningless on MacOS Classic and/or Unix, they are a security hole. Also, symbolic links (which can be found in some archive types and directly in the filesystem on Unix platforms) are NOT followed until you call (permit-symbolic-links #t). That's left to your own discretion, as following a symlink can allow for access outside the write dir and search paths. For portability, there is no mechanism for creating new symlinks in PhysicsFS. 44 46 45 47 The write dir is not included in the search path unless you specifically add it. While you CAN change the write dir as many times as you like, you should probably set it once and stick to it. Remember that your program will not have permission to write in every directory on Unix and NT systems. … … 47 49 All files are opened in binary mode; there is no endline conversion for textfiles. Other than that, PhysicsFS has some convenience functions for platform-independence. There is a function to tell you the current platform's dir separator ("\\" on windows, "/" on Unix, ":" on MacOS), which is needed only to set up your search/write paths. There is a function to tell you what CD-ROM drives contain accessible discs, and a function to recommend a good search path, etc. 48 50 49 A recommended order for the search path is the write dir, then the base dir, then the cdrom dir, then any archives discovered. Quake 3 does something like this, but moves the archives to the start of the search path. Build Engine games, like Duke Nukem 3D and Blood, place the archives last, and use the base dir for both searching and writing. There is a helper function (set SaneConfig) that puts together a basic configuration for you, based on a few parameters. Also see the comments on (getBaseDir), and (getUserDir) for info on what those are and how they can help you determine an optimal search path.51 A recommended order for the search path is the write dir, then the base dir, then the cdrom dir, then any archives discovered. Quake 3 does something like this, but moves the archives to the start of the search path. Build Engine games, like Duke Nukem 3D and Blood, place the archives last, and use the base dir for both searching and writing. There is a helper function (set-sane-config) that puts together a basic configuration for you, based on a few parameters. Also see the comments on (get-base-dir), and (get-user-dir) for info on what those are and how they can help you determine an optimal search path. 50 52 51 53 PhysicsFS 2.0 adds the concept of "mounting" archives to arbitrary points in the search path. If a zipfile contains "maps/level.map" and you mount that archive at "mods/mymod", then you would have to open "mods/mymod/maps/level.map" to access the file, even though "mods/mymod" isn't actually specified in the .zip file. Unlike the Unix mentality of mounting a filesystem, "mods/mymod" doesn't actually have to exist when mounting the zipfile. It's a "virtual" directory. The mounting mechanism allows the developer to seperate archives in the tree and avoid trampling over files when added new archives, such as including mod support in a game...keeping external content on a tight leash in this manner can be of utmost importance to some applications. 52 54 53 PhysicsFS is mostly thread safe. The error messages returned by (get LastError) are unique by thread, and library-state-setting functions are mutex'd. For efficiency, individual file accesses are not locked, so you can not safely read/write/seek/close/etc the same file from two threads at the same time. Other race conditions are bugs that should be reported/patched.55 PhysicsFS is mostly thread safe. The error messages returned by (get-last-error) are unique by thread, and library-state-setting functions are mutex'd. For efficiency, individual file accesses are not locked, so you can not safely read/write/seek/close/etc the same file from two threads at the same time. Other race conditions are bugs that should be reported/patched. 54 56 55 57 While you CAN use stdio/syscall file access in a program that has physfs calls, doing so is not recommended, and you can not use system filehandles with PhysicsFS and vice versa. … … 71 73 All strings passed through PhysicsFS are in null-terminated UTF-8 format. This means that if all you care about is English (ASCII characters <= 127) then you just use regular C strings. If you care about Unicode (and you should!) then you need to figure out what your platform wants, needs, and offers. If you are on Windows and build with Unicode support, your TCHAR strings are two bytes per character (this is called "UCS-2 encoding"). You should convert them to UTF-8 before handing them to PhysicsFS with (utf8FromUcs2). If you're using Unix or Mac OS X, your wchar_t strings are four bytes per character ("UCS-4 encoding"). Use (utf8FromUcs4). Mac OS X can give you UTF-8 directly from a CFString, and many Unixes generally give you C strings in UTF-8 format everywhere. If you have a single-byte high ASCII charset, like so-many European "codepages" you may be out of luck. We'll convert from "Latin1" to UTF-8 only, and never back to Latin1. If you're above ASCII 127, all bets are off: move to Unicode or use your platform's facilities. Passing a C string with high-ASCII data that isn't UTF-8 encoded will NOT do what you expect! 72 74 73 Naturally, there's also (utf8 ToUcs2) and (utf8ToUcs4) to get data back into a format you like. Behind the scenes, PhysicsFS will use Unicode where possible: the UTF-8 strings on Windows will be converted and used with the multibyte Windows APIs, for example.75 Naturally, there's also (utf8-to-ucs2) and (utf8-to-ucs4) to get data back into a format you like. Behind the scenes, PhysicsFS will use Unicode where possible: the UTF-8 strings on Windows will be converted and used with the multibyte Windows APIs, for example. 74 76 75 77 PhysicsFS offers basic encoding conversion support, but not a whole string library. Get your stuff into whatever format you can work with. … … 81 83 == Reference 82 84 83 === File 84 ; File : A PhysicsFS file handle. 85 === Types 86 87 ==== <type>file</type> 88 89 A PhysicsFS file handle. 85 90 86 91 You get a pointer to one of these when you open a file for reading, writing, or appending via PhysicsFS. … … 88 93 As you can see from the lack of meaningful fields, you should treat this as opaque data. Don't try to manipulate the file handle, just pass the pointer you got, unmolested, to various PhysicsFS APIs. 89 94 90 === ArchiveInfo 91 92 ; ArchiveInfo : Information on various PhysicsFS-supported archives. 95 * <procedure>(file-opaque file)</procedure> 96 97 Fetches the opaque pointer contained within the file struct. 98 99 ==== <type>archive-info</type> 100 101 Information on various PhysicsFS-supported archives. 93 102 94 103 This structure gives you details on what sort of archives are supported by this implementation of PhysicsFS. Archives tend to be things like ZIP files and such. 95 104 96 Available fields: 97 * extension : Archive file extension: "ZIP", for example. 98 * description : Human-readable archive description. 99 * author : Person who did support for this archive. 100 * url : URL related to this archive 101 102 ; Version : Information the version of PhysicsFS in use. 105 * <procedure>(make-archive-info)</procedure> : Constructs an archive-info record, not that you should ever need to. 106 * <procedure>(archive-info? archive-info)</procedure> : Tests if an object is an archive-info. 107 * <procedure>(archive-info-extension archive-info)</procedure> : Archive file extension: "ZIP", for example. 108 * <procedure>(archive-info-description archive-info)</procedure> : Human-readable archive description. 109 * <procedure>(archive-info-author archive-info)</procedure> : Person who did support for this archive. 110 * <procedure>(archive-info-url archive-info)</procedure> : URL related to this archive 111 112 ==== <type>version</type> 113 114 Information the version of PhysicsFS in use. 103 115 104 116 Represents the library's version as three levels: major revision (increments with massive changes, additions, and enhancements), minor revision (increments with backwards-compatible changes to the major revision), and patchlevel (increments with fixes to the minor revision). 105 117 106 Available fields: 107 * major : major revision 108 * minor : minor revision 109 * patch : patchlevel 118 * <procedure>(make-version)</procedure> : Constructs a version record, not that you should ever need to. 119 * <procedure>(version? version)</procedure> : Tests if an object is a version. 120 * <procedure>(version-major version)</procedure> : major revision 121 * <procedure>(version-minor version)</procedure> : minor revision 122 * <procedure>(version-patch version)</procedure> : patch level 110 123 111 124 === PhysicsFS state 112 125 113 ; (getLinkedVersion) : Get the version of PhysicsFS that is linked against your program. 126 ==== <procedure>(get-linked-version)</procedure> 127 128 Get the version of PhysicsFS that is linked against your program. 114 129 115 130 If you are using a shared library (DLL) version of PhysFS, then it is possible that it will be different than the version you compiled against. … … 117 132 This function may be called safely at any time, even before PHYSFS_init(). 118 133 119 ; (init) : Initialize the PhysicsFS library. 134 ==== <procedure>(init)</procedure> 135 136 Initialize the PhysicsFS library. 120 137 121 138 This must be called before any other PhysicsFS function. … … 125 142 Returns nonzero on success, zero on error. Specifics of the error can be gleaned from (getLastError). 126 143 127 ; (deinit) : Deinitialize the PhysicsFS library. 144 ==== <procedure>(deinit)</procedure> 145 146 Deinitialize the PhysicsFS library. 128 147 129 148 This closes any files opened via PhysicsFS, blanks the search/write paths, frees memory, and invalidates all of your file handles. … … 131 150 Note that this call can FAIL if there's a file open for writing that refuses to close (for example, the underlying operating system was buffering writes to network filesystem, and the fileserver has crashed, or a hard drive has failed, etc). It is usually best to close all write handles yourself before calling this function, so that you can gracefully handle a specific failure. 132 151 133 Once successfully deinitialized, PHYSFS_init() can be called again to restart the subsystem. All default API states are restored at this point, with the exception of any custom allocator you might have specified, which survives between initializations.152 Once successfully deinitialized, (init) can be called again to restart the subsystem. All default API states are restored at this point, with the exception of any custom allocator you might have specified, which survives between initializations. 134 153 135 154 Returns nonzero on success, zero on error. Specifics of the error can be gleaned from (getLastError). If failure, state of PhysFS is undefined, and probably badly screwed up. 136 155 137 ; (supportedArchiveTypes) : Get a list of supported archive types. 156 ==== <procedure>(supported-archive-types)</procedure> 157 158 Get a list of supported archive types. 138 159 139 160 Get a list of archive types supported by this implementation of PhysicFS. These are the file formats usable for search path entries. This is for informational purposes only. Note that the extension listed is merely convention: if we list "ZIP", you can open a PkZip-compatible archive with an extension of "XYZ", if you like. … … 141 162 The returned value is a list of ArchiveInfo records. 142 163 143 ; (getLastError) : Get human-readable error information. 164 ==== <procedure>(get-last-error)</procedure> 165 166 Get human-readable error information. 144 167 145 168 Get the last PhysicsFS error message as a human-readable string. This will be empty if there's been no error since the last call to this function. The pointer returned by this call points to an internal buffer. Each thread has a unique error state associated with it, but each time a new error message is set, it will overwrite the previous one associated with that thread. It is safe to call this function at anytime, even before (init). … … 147 170 It is not wise to expect a specific string of characters here, since the error message may be localized into an unfamiliar language. These strings are meant to be passed on directly to the user. 148 171 149 ; (getDirSeparator) : Get platform-dependent dir separator string. 172 ==== <procedure>(get-dir-separator)</procedure> 173 174 Get platform-dependent dir separator string. 150 175 151 176 This returns "\\" on win32, "/" on Unix, and ":" on MacOS. It may be more than one character, depending on the platform, and your code should take that into account. Note that this is only useful for setting up the search/write paths, since access into those dirs always use '/' (platform-independent notation) to separate directories. This is also handy for getting platform-independent access when using stdio calls. 152 177 153 ; (permitSymbolicLinks bool) : Enable or disable following of symbolic links. 178 ==== <procedure>(permit-symbolic-links bool)</procedure> 179 180 Enable or disable following of symbolic links. 154 181 155 182 Some physical filesystems and archives contain files that are just pointers to other files. On the physical filesystem, opening such a link will (transparently) open the file that is pointed to. … … 163 190 Symbolic link permission can be enabled or disabled at any time after you've called (init), and is disabled by default. 164 191 165 ; (getCdRomDirs) : Get an array of paths to available CD-ROM drives. 192 ==== <procedure>(get-cdrom-dirs)</procedure> 193 194 Get an array of paths to available CD-ROM drives. 166 195 167 196 The dirs returned are platform-dependent ("D:\" on Win32, "/cdrom" or whatnot on Unix). Dirs are only returned if there is a disc ready and accessible in the drive. So if you've got two drives (D: and E:), and only E: has a disc in it, then that's all you get. If the user inserts a disc in D: and you call this function again, you get both drives. If, on a Unix box, the user unmounts a disc and remounts it elsewhere, the next call to this function will reflect that change. … … 171 200 This call may block while drives spin up. Be forewarned. 172 201 173 ; (getBaseDir) : Get the path where the application resides. 202 ==== <procedure>(get-base-dir)</procedure> 203 204 Get the path where the application resides. 174 205 175 206 Helper function. … … 179 210 You should probably use the base dir in your search path. 180 211 181 ; (getUserDir) : Get the path where user's home directory resides. 212 ==== <procedure>(get-user-dir)</procedure> 213 214 Get the path where user's home directory resides. 182 215 183 216 Helper function. … … 187 220 You should probably use the user dir as the basis for your write dir, and also put it near the beginning of your search path. 188 221 189 ; (getWriteDir) : Get path where PhysicsFS will allow file writing. 222 ==== <procedure>(get-write-dir)</procedure> 223 224 Get path where PhysicsFS will allow file writing. 190 225 191 226 Get the current write dir. The default write dir is NULL. 192 227 193 ; (setWriteDir dir) : Tell PhysicsFS where it may write files. 228 ==== <procedure>(set-write-dir dir)</procedure> 229 230 Tell PhysicsFS where it may write files. 194 231 195 232 Set a new write dir. This will override the previous setting. … … 197 234 This call will fail (and fail to change the write dir) if the current write dir still has files open in it. 198 235 199 ; (addToSearchPath newDir appendToPath) 236 ==== <procedure>(add-to-search-path newDir appendToPath)</procedure> 200 237 201 238 Add an archive or directory to the search path. … … 205 242 You must use this and not (mount) if binary compatibility with PhysicsFS 1.0 is important (which it may not be for many people). 206 243 207 ; (removeFromSearchPath oldDir) : Remove a directory or archive from the search path. 244 ==== <procedure>(remove-from-search-path oldDir)</procedure> 245 246 Remove a directory or archive from the search path. 208 247 209 248 This must be a (case-sensitive) match to a dir or archive already in the search path, specified in platform-dependent notation. … … 211 250 This call will fail (and fail to remove from the path) if the element still has files open in it. 212 251 213 ; (getSearchPath) : Get the current search path. 252 ==== <procedure>(get-search-path)</procedure> 253 254 Get the current search path. 214 255 215 256 The default search path is an empty list. 216 257 217 ; (setSaneConfig organization appName archiveExt includeCdRoms archivesFirst) : Set up sane, default paths. 258 ==== <procedure>(set-sane-config organization appName archiveExt includeCdRoms archivesFirst)</procedure> 259 260 Set up sane, default paths. 218 261 219 262 Helper function. … … 226 269 227 270 * The Write Dir (created if it doesn't exist) 228 * The Base Dir (get BaseDir)271 * The Base Dir (get-base-dir) 229 272 * All found CD-ROM dirs (optionally) 230 273 … … 234 277 === Directory Management 235 278 236 ; (mkdir dirName) : Create a directory. 279 ==== <procedure>(mkdir dirName)</procedure> 280 281 Create a directory. 237 282 238 283 This is specified in platform-independent notation in relation to the write dir. All missing parent directories are also created if they don't exist. … … 240 285 So if you've got the write dir set to "C:\mygame\writedir" and call (mkdir "downloads/maps") then the directories "C:\mygame\writedir\downloads" and "C:\mygame\writedir\downloads\maps" will be created if possible. If the creation of "maps" fails after we have successfully created "downloads", then the function leaves the created directory behind and reports failure. 241 286 242 ; (delete filename) : Delete a file or directory. 287 ==== <procedure>(delete filename)</procedure> 288 289 Delete a file or directory. 243 290 244 291 (filename) is specified in platform-independent notation in relation to the write dir. … … 254 301 Chances are, the bits that make up the file still exist, they are just made available to be written over at a later point. Don't consider this a security method or anything. :) 255 302 256 ; (getRealDir filename) : Figure out where in the search path a file resides. 303 ==== <procedure>(get-real-dir filename)</procedure> 304 305 Figure out where in the search path a file resides. 257 306 258 307 The file is specified in platform-independent notation. The returned filename will be the element of the search path where the file was found, which may be a directory, or an archive. Even if there are multiple matches in different parts of the search path, only the first one found is used, just like when opening a file. … … 264 313 If you specify a fake directory that only exists as a mount point, it'll be associated with the first archive mounted there, even though that directory isn't necessarily contained in a real archive. 265 314 266 ; (enumerateFiles dir) : Get a file listing of a search path's directory. 315 ==== <procedure>(enumerate-files dir)</procedure> 316 317 Get a file listing of a search path's directory. 267 318 268 319 Matching directories are interpolated. … … 270 321 Feel free to sort the list however you like. We only promise there will be no duplicates, but not what order the final list will come back in. 271 322 272 ; (exists filename) : Determine if a file exists in the search path. 323 ==== <procedure>(exists filename)</procedure> 324 325 Determine if a file exists in the search path. 273 326 274 327 Reports true if there is an entry anywhere in the search path by the name of (filename). … … 276 329 Note that entries that are symlinks are ignored if (permitSymbolicLinks #t) hasn't been called, so you might end up further down in the search path than expected. 277 330 278 ; (isDirectory filename) : Determine if a file in the search path is really a directory. 331 ==== <procedure>(directory? filename)</procedure> 332 333 Determine if a file in the search path is really a directory. 279 334 280 335 Determine if the first occurence of (fname) in the search path is really a directory entry. … … 282 337 Note that entries that are symlinks are ignored if (permitSymbolicLinks #t) hasn't been called, so you might end up further down in the search path than expected. 283 338 284 ; (isSymbolicLink filename) : Determine if a file in the search path is really a symbolic link. 339 ==== <procedure>(symbolic-link? filename)</procedure> 340 341 Determine if a file in the search path is really a symbolic link. 285 342 286 343 Determine if the first occurence of (filename) in the search path is really a symbolic link. … … 288 345 Note that entries that are symlinks are ignored if (permitSymbolicLinks #t) hasn't been called, and as such, this function will always return 0 in that case. 289 346 290 ; (getLastModTime filename) : Get the last modification time of a file. 347 ==== <procedure>(get-last-mod-time filename)</procedure> 348 349 Get the last modification time of a file. 291 350 292 351 The modtime is returned as a number of seconds since the epoch (Jan 1, 1970). The exact derivation and accuracy of this time depends on the particular archiver. If there is no reasonable way to obtain this information for a particular archiver, or there was some sort of error, this function returns (-1). … … 294 353 === Input/Output 295 354 296 ; (openWrite filename) : Open a file for writing. 355 ==== <procedure>(open-write filename)</procedure> 356 357 Open a file for writing. 297 358 298 359 Open a file for writing, in platform-independent notation and in relation to the write dir as the root of the writable filesystem. The specified file is created if it doesn't exist. If it does exist, it is truncated to zero bytes, and the writing offset is set to the start. … … 300 361 Note that entries that are symlinks are ignored if (permitSymbolicLinks #t) hasn't been called, and opening a symlink with this function will fail in such a case. 301 362 302 ; (openAppend filename) : Open a file for appending. 363 ==== <procedure>(open-append filename)</procedure> 364 365 Open a file for appending. 303 366 304 367 Open a file for writing, in platform-independent notation and in relation to the write dir as the root of the writable filesystem. The specified file is created if it doesn't exist. If it does exist, the writing offset is set to the end of the file, so the first write will be the byte after the end. … … 306 369 Note that entries that are symlinks are ignored if (permitSymbolicLinks #t) hasn't been called, and opening a symlink with this function will fail in such a case. 307 370 308 ; (openRead filename) : Open a file for reading. 371 ==== <procedure>(open-read filename)</procedure> 372 373 Open a file for reading. 309 374 310 375 Open a file for reading, in platform-independent notation. The search path is checked one at a time until a matching file is found, in which case an abstract filehandle is associated with it, and reading may be done. The reading offset is set to the first byte of the file. … … 312 377 Note that entries that are symlinks are ignored if (permitSymbolicLinks #t) hasn't been called, and opening a symlink with this function will fail in such a case. 313 378 314 ; (close handle) : Close a PhysicsFS filehandle. 379 ==== <procedure>(close handle)</procedure> 380 381 Close a PhysicsFS filehandle. 315 382 316 383 This call is capable of failing if the operating system was buffering writes to the physical media, and, now forced to write those changes to physical media, can not store the data for some reason. In such a case, the filehandle stays open. A well-written program should ALWAYS check the return value from the close call in addition to every writing call! 317 384 318 ; (read handle buffer objSize objCount) : Read data from a PhysicsFS filehandle 385 ==== <procedure>(read handle buffer objSize objCount)</procedure> 386 387 Read data from a PhysicsFS filehandle 319 388 320 389 The file must be opened for reading. 321 390 322 ; (write handle buffer objSize objCount) : Write data to a PhysicsFS filehandle 391 ==== <procedure>(write handle buffer objSize objCount)</procedure> 392 393 Write data to a PhysicsFS filehandle 323 394 324 395 The file must be opened for writing. … … 326 397 === File Positioning 327 398 328 ; (eof handle) : Check for end-of-file state on a PhysicsFS filehandle. 399 ==== <procedure>(eof handle)</procedure> 400 401 Check for end-of-file state on a PhysicsFS filehandle. 329 402 330 403 Determine if the end of file has been reached in a PhysicsFS filehandle. 331 404 332 ; (tell handle) : Determine current position within a PhysicsFS filehandle. 333 334 ; (seek handle pos) : Seek to a new position within a PhysicsFS filehandle. 405 ==== <procedure>(tell handle)</procedure> 406 407 Determine current position within a PhysicsFS filehandle. 408 409 ==== <procedure>(seek handle pos)</procedure> 410 411 Seek to a new position within a PhysicsFS filehandle. 335 412 336 413 The next read or write will occur at that place. Seeking past the beginning or end of the file is not allowed, and causes an error. 337 414 338 ; (fileLength handle) : Get total length of a file in bytes. 415 ==== <procedure>(file-length handle)</procedure> 416 417 Get total length of a file in bytes. 339 418 340 419 Note that if the file size can't be determined (since the archive is "streamed" or whatnot) than this will report (-1). Also note that if another process/thread is writing to this file at the same time, then the information this function supplies could be incorrect before you get it. Use with caution, or better yet, don't use at all. … … 342 421 === Buffering 343 422 344 ; (setBuffer handle bufsize) : Set up buffering for a PhysicsFS file handle. 423 ==== <procedure>(set-buffer handle bufsize)</procedure> 424 425 Set up buffering for a PhysicsFS file handle. 345 426 346 427 Define an i/o buffer for a file handle. A memory block of (bufsize) bytes will be allocated and associated with (handle). 347 428 348 For files opened for reading, up to (bufsize) bytes are read from (handle) and stored in the internal buffer. Calls to PHYSFS_read() will pull from this buffer until it is empty, and then refill it for more reading. Note that compressed files, like ZIP archives, will decompress while buffering, so this can be handy for offsetting CPU-intensive operations. The buffer isn't filled until you do your next read.429 For files opened for reading, up to (bufsize) bytes are read from (handle) and stored in the internal buffer. Calls to (read) will pull from this buffer until it is empty, and then refill it for more reading. Note that compressed files, like ZIP archives, will decompress while buffering, so this can be handy for offsetting CPU-intensive operations. The buffer isn't filled until you do your next read. 349 430 350 431 For files opened for writing, data will be buffered to memory until the buffer is full or the buffer is flushed. Closing a handle implicitly causes a flush...check your return values! … … 358 439 Please check the return value of this function! Failures can include not being able to seek backwards in a read-only file when removing the buffer, not being able to allocate the buffer, and not being able to flush the buffer to disk, among other unexpected problems. 359 440 360 ; (flush handle) : Flush a buffered PhysicsFS file handle. 441 ==== <procedure>(flush handle)</procedure> 442 443 Flush a buffered PhysicsFS file handle. 361 444 362 445 For buffered files opened for writing, this will put the current contents of the buffer to disk and flag the buffer as empty if possible. … … 366 449 === Byte Ordering 367 450 368 ; (swapSLE16 val) : Swap littleendian signed 16 to platform's native byte order. 451 ==== <procedure>(swap-sle16 val)</procedure> 452 453 Swap littleendian signed 16 to platform's native byte order. 369 454 370 455 Take a 16-bit signed value in littleendian format and convert it to the platform's native byte order. 371 456 372 ; (swapULE16 val) : Swap littleendian unsigned 16 to platform's native byte order. 457 ==== <procedure>(swap-ule16 val)</procedure> 458 459 Swap littleendian unsigned 16 to platform's native byte order. 373 460 374 461 Take a 16-bit unsigned value in littleendian format and convert it to the platform's native byte order. 375 462 376 ; (swapSLE32 val) : Swap littleendian signed 32 to platform's native byte order. 463 ==== <procedure>(swap-sle32 val)</procedure> 464 465 Swap littleendian signed 32 to platform's native byte order. 377 466 378 467 Take a 32-bit signed value in littleendian format and convert it to the platform's native byte order. 379 468 380 ; (swapULE32 val) : Swap littleendian unsigned 32 to platform's native byte order. 469 ==== <procedure>(swap-ule32 val)</procedure> 470 471 Swap littleendian unsigned 32 to platform's native byte order. 381 472 382 473 Take a 32-bit unsigned value in littleendian format and convert it to the platform's native byte order. 383 474 384 ; (swapSLE64 val) : Swap littleendian signed 64 to platform's native byte order. 475 ==== <procedure>(swap-sle64 val)</procedure> 476 477 Swap littleendian signed 64 to platform's native byte order. 385 478 386 479 Take a 64-bit signed value in littleendian format and convert it to the platform's native byte order. 387 480 388 ; (swapULE64 val) : Swap littleendian unsigned 64 to platform's native byte order. 481 ==== <procedure>(swap-ule64 val)</procedure> 482 483 Swap littleendian unsigned 64 to platform's native byte order. 389 484 390 485 Take a 64-bit unsigned value in littleendian format and convert it to the platform's native byte order. 391 486 392 ; (swapSBE16 val) : Swap bigendian signed 16 to platform's native byte order. 487 ==== <procedure>(swap-sbe16 val)</procedure> 488 489 Swap bigendian signed 16 to platform's native byte order. 393 490 394 491 Take a 16-bit signed value in bigendian format and convert it to the platform's native byte order. 395 492 396 ; (swapUBE16 val) : Swap bigendian unsigned 16 to platform's native byte order. 493 ==== <procedure>(swap-ube16 val)</procedure> 494 495 Swap bigendian unsigned 16 to platform's native byte order. 397 496 398 497 Take a 16-bit unsigned value in bigendian format and convert it to the platform's native byte order. 399 498 400 ; (swapSBE32 val) : Swap bigendian signed 32 to platform's native byte order. 499 ==== <procedure>(swap-sbe32 val)</procedure> 500 501 Swap bigendian signed 32 to platform's native byte order. 401 502 402 503 Take a 32-bit signed value in bigendian format and convert it to the platform's native byte order. 403 504 404 ; (swapUBE32 val) : Swap bigendian unsigned 32 to platform's native byte order. 505 ==== <procedure>(swap-ube32 val)</procedure> 506 507 Swap bigendian unsigned 32 to platform's native byte order. 405 508 406 509 Take a 32-bit unsigned value in bigendian format and convert it to the platform's native byte order. 407 510 408 ; (swapSBE64 val) : Swap bigendian signed 64 to platform's native byte order. 511 ==== <procedure>(swap-sbe64 val)</procedure> 512 513 Swap bigendian signed 64 to platform's native byte order. 409 514 410 515 Take a 64-bit signed value in bigendian format and convert it to the platform's native byte order. 411 516 412 ; (swapUBE64 val) : Swap bigendian unsigned 64 to platform's native byte order. 517 ==== <procedure>(swap-ube64 val)</procedure> 518 519 Swap bigendian unsigned 64 to platform's native byte order. 413 520 414 521 Take a 64-bit unsigned value in bigendian format and convert it to the platform's native byte order. 415 522 416 ; (readSLE16 file) : Read and convert a signed 16-bit littleendian value. 523 ==== <procedure>(read-sle16 file)</procedure> 524 525 Read and convert a signed 16-bit littleendian value. 417 526 418 527 Convenience function. Read a signed 16-bit littleendian value from a file and convert it to the platform's native byte order. 419 528 420 ; (readULE16 file) : Read and convert an unsigned 16-bit littleendian value. 529 ==== <procedure>(read-ule16 file)</procedure> 530 531 Read and convert an unsigned 16-bit littleendian value. 421 532 422 533 Convenience function. Read an unsigned 16-bit littleendian value from a file and convert it to the platform's native byte order. 423 534 424 ; (readSBE16 file) : Read and convert a signed 16-bit bigendian value. 535 ==== <procedure>(read-sbe16 file)</procedure> 536 537 Read and convert a signed 16-bit bigendian value. 425 538 426 539 Convenience function. Read a signed 16-bit bigendian value from a file and convert it to the platform's native byte order. 427 540 428 ; (readUBE16 file) : Read and convert an unsigned 16-bit bigendian value. 541 ==== <procedure>(read-ube16 file)</procedure> 542 543 Read and convert an unsigned 16-bit bigendian value. 429 544 430 545 Convenience function. Read an unsigned 16-bit bigendian value from a file and convert it to the platform's native byte order. 431 546 432 ; (readSLE32 file) : Read and convert a signed 32-bit littleendian value. 547 ==== <procedure>(read-sle32 file)</procedure> 548 549 Read and convert a signed 32-bit littleendian value. 433 550 434 551 Convenience function. Read a signed 32-bit littleendian value from a file and convert it to the platform's native byte order. 435 552 436 ; (readULE32 file) : Read and convert an unsigned 32-bit littleendian value. 553 ==== <procedure>(read-ule32 file)</procedure> 554 555 Read and convert an unsigned 32-bit littleendian value. 437 556 438 557 Convenience function. Read an unsigned 32-bit littleendian value from a file and convert it to the platform's native byte order. 439 558 440 ; (readSBE32 file) : Read and convert a signed 32-bit bigendian value. 559 ==== <procedure>(read-sbe32 file)</procedure> 560 561 Read and convert a signed 32-bit bigendian value. 441 562 442 563 Convenience function. Read a signed 32-bit bigendian value from a file and convert it to the platform's native byte order. 443 564 444 ; (readUBE32 file) : Read and convert an unsigned 32-bit bigendian value. 565 ==== <procedure>(read-ube32 file)</procedure> 566 567 Read and convert an unsigned 32-bit bigendian value. 445 568 446 569 Convenience function. Read an unsigned 32-bit bigendian value from a file and convert it to the platform's native byte order. 447 570 448 ; (readSLE64 file) : Read and convert a signed 64-bit littleendian value. 571 ==== <procedure>(read-sle64 file)</procedure> 572 573 Read and convert a signed 64-bit littleendian value. 449 574 450 575 Convenience function. Read a signed 64-bit littleendian value from a file and convert it to the platform's native byte order. 451 576 452 ; (readULE64 file) : Read and convert an unsigned 64-bit littleendian value. 577 ==== <procedure>(read-ule64 file)</procedure> 578 579 Read and convert an unsigned 64-bit littleendian value. 453 580 454 581 Convenience function. Read an unsigned 64-bit littleendian value from a file and convert it to the platform's native byte order. 455 582 456 ; (readSBE64 file) : Read and convert a signed 64-bit bigendian value. 583 ==== <procedure>(read-sbe64 file)</procedure> 584 585 Read and convert a signed 64-bit bigendian value. 457 586 458 587 Convenience function. Read a signed 64-bit bigendian value from a file and convert it to the platform's native byte order. 459 588 460 ; (readUBE64 file) : Read and convert an unsigned 64-bit bigendian value. 589 ==== <procedure>(read-ube64 file)</procedure> 590 591 Read and convert an unsigned 64-bit bigendian value. 461 592 462 593 Convenience function. Read an unsigned 64-bit bigendian value from a file and convert it to the platform's native byte order. 463 594 464 ; (writeSLE16 file val) : Convert and write a signed 16-bit littleendian value. 595 ==== <procedure>(write-sle16 file val)</procedure> 596 597 Convert and write a signed 16-bit littleendian value. 465 598 466 599 Convenience function. Convert a signed 16-bit value from the platform's native byte order to littleendian and write it to a file. 467 600 468 ; (writeULE16 file val) : Convert and write an unsigned 16-bit littleendian value. 601 ==== <procedure>(write-ule16 file val)</procedure> 602 603 Convert and write an unsigned 16-bit littleendian value. 469 604 470 605 Convenience function. Convert an unsigned 16-bit value from the platform's native byte order to littleendian and write it to a file. 471 606 472 ; (writeSBE16 file val) : Convert and write a signed 16-bit bigendian value. 607 ==== <procedure>(write-sbe16 file val)</procedure> 608 609 Convert and write a signed 16-bit bigendian value. 473 610 474 611 Convenience function. Convert a signed 16-bit value from the platform's native byte order to bigendian and write it to a file. 475 612 476 ; (writeUBE16 file val) : Convert and write an unsigned 16-bit bigendian value. 613 ==== <procedure>(write-ube16 file val)</procedure> 614 615 Convert and write an unsigned 16-bit bigendian value. 477 616 478 617 Convenience function. Convert an unsigned 16-bit value from the platform's native byte order to bigendian and write it to a file. 479 618 480 ; (writeSLE32 file val) : Convert and write a signed 32-bit littleendian value. 619 ==== <procedure>(write-sle32 file val)</procedure> 620 621 Convert and write a signed 32-bit littleendian value. 481 622 482 623 Convenience function. Convert a signed 32-bit value from the platform's native byte order to littleendian and write it to a file. 483 624 484 ; (writeULE32 file val) : Convert and write an unsigned 32-bit littleendian value. 625 ==== <procedure>(write-ule32 file val)</procedure> 626 627 Convert and write an unsigned 32-bit littleendian value. 485 628 486 629 Convenience function. Convert an unsigned 32-bit value from the platform's native byte order to littleendian and write it to a file. 487 630 488 ; (writeSBE32 file val) : Convert and write a signed 32-bit bigendian value. 631 ==== <procedure>(write-sbe32 file val)</procedure> 632 633 Convert and write a signed 32-bit bigendian value. 489 634 490 635 Convenience function. Convert a signed 32-bit value from the platform's native byte order to bigendian and write it to a file. 491 636 492 ; (writeUBE32 file val) : Convert and write an unsigned 32-bit bigendian value. 637 ==== <procedure>(write-ube32 file val)</procedure> 638 639 Convert and write an unsigned 32-bit bigendian value. 493 640 494 641 Convenience function. Convert an unsigned 32-bit value from the platform's native byte order to bigendian and write it to a file. 495 642 496 ; (writeSLE64 file val) : Convert and write a signed 64-bit littleendian value. 643 ==== <procedure>(write-sle64 file val)</procedure> 644 645 Convert and write a signed 64-bit littleendian value. 497 646 498 647 Convenience function. Convert a signed 64-bit value from the platform's native byte order to littleendian and write it to a file. 499 648 500 ; (writeULE64 file val) : Convert and write an unsigned 64-bit littleendian value. 649 ==== <procedure>(write-ule64 file val)</procedure> 650 651 Convert and write an unsigned 64-bit littleendian value. 501 652 502 653 Convenience function. Convert an unsigned 64-bit value from the platform's native byte order to littleendian and write it to a file. 503 654 504 ; (writeSBE64 file val) : Convert and write a signed 64-bit bigending value. 655 ==== <procedure>(write-sbe64 file val)</procedure> 656 657 Convert and write a signed 64-bit bigending value. 505 658 506 659 Convenience function. Convert a signed 64-bit value from the platform's native byte order to bigendian and write it to a file. 507 660 508 ; (writeUBE64 file val) : Convert and write an unsigned 64-bit bigendian value. 661 ==== <procedure>(write-ube64 file val)</procedure> 662 663 Convert and write an unsigned 64-bit bigendian value. 509 664 510 665 Convenience function. Convert an unsigned 64-bit value from the platform's native byte order to bigendian and write it to a file. … … 512 667 == PhysicsFS 2.0 Functionality 513 668 514 ; (isInit) : Determine if the PhysicsFS library is initialized. 669 ==== <procedure>(init?)</procedure> 670 671 Determine if the PhysicsFS library is initialized. 515 672 516 673 Once (init) returns successfully, this will return non-zero. Before a successful (init) and after (deinit) returns successfully, this will return zero. This function is safe to call at any time. 517 674 518 ; (symbolicLinksPermitted) : Determine if the symbolic links are permitted. 519 520 This reports the setting from the last call to (permitSymbolicLinks). If (permitSymbolicLinks) hasn't been called since the library was last initialized, symbolic links are implicitly disabled. 521 522 ; (mount newDir mountPoint appendToPath) : Add an archive or directory to the search path. 675 ==== <procedure>(symbolic-links-permitted)</procedure> 676 677 Determine if the symbolic links are permitted. 678 679 This reports the setting from the last call to (permit-symbolic-links). If (permitSymbolicLinks) hasn't been called since the library was last initialized, symbolic links are implicitly disabled. 680 681 ==== <procedure>(mount newDir mountPoint appendToPath)</procedure> 682 683 Add an archive or directory to the search path. 523 684 524 685 If this is a duplicate, the entry is not added again, even though the function succeeds. You may not add the same archive to two different mountpoints: duplicate checking is done against the archive and not the mountpoint. … … 528 689 The mountpoint does not need to exist prior to mounting, which is different than those familiar with the Unix concept of "mounting" may not expect. As well, more than one archive can be mounted to the same mountpoint, or mountpoints and archive contents can overlap...the interpolation mechanism still functions as usual. 529 690 530 ; (getMountPoint dir) : Determine a mounted archive's mountpoint. 691 ==== <procedure>(getMountPoint dir)</procedure> 692 693 Determine a mounted archive's mountpoint. 531 694 532 695 You give this function the name of an archive or dir you successfully added to the search path, and it reports the location in the interpolated tree where it is mounted. Files mounted with a NULL mountpoint or through (addToSearchPath) will report "/". The return value is READ ONLY and valid until the archive is removed from the search path. … … 534 697 === UTF8 Functions 535 698 536 ; (utf8FromUcs4 src len) : Convert a UCS-4 string to a UTF-8 string. 699 ==== <procedure>(utf8-from-ucs4 src len)</procedure> 700 701 Convert a UCS-4 string to a UTF-8 string. 537 702 538 703 UCS-4 strings are 32-bits per character: \c wchar_t on Unix. 539 704 540 ; (utf8ToUcs4 src len) : Convert a UTF-8 string to a UCS-4 string. 705 ==== <procedure>(utf8-to-ucs4 src len)</procedure> 706 707 Convert a UTF-8 string to a UCS-4 string. 541 708 542 709 UCS-4 strings are 32-bits per character: \c wchar_t on Unix. 543 710 544 ; (utf8FromUcs2 src len) : Convert a UCS-2 string to a UTF-8 string. 711 ==== <procedure>(utf8-from-ucs2 src len)</procedure> 712 713 Convert a UCS-2 string to a UTF-8 string. 545 714 546 715 UCS-2 strings are 16-bits per character: \c TCHAR on Windows, when building with Unicode support. … … 548 717 Please note that UCS-2 is not UTF-16; we do not support the "surrogate" values at this time. 549 718 550 ; (utf8ToUcs2 src len) : Convert a UTF-8 string to a UCS-2 string. 719 ==== <procedure>(utf8-to-ucs2 src len)</procedure> 720 721 Convert a UTF-8 string to a UCS-2 string. 551 722 552 723 UCS-2 strings are 16-bits per character: \c TCHAR on Windows, when building with Unicode support. … … 554 725 Please note that UCS-2 is not UTF-16; we do not support the "surrogate" values at this time. 555 726 556 ; (utf8FromLatin1 src len) : Convert a UTF-8 string to a Latin1 string. 727 ==== <procedure>(utf8-from-latin1 src len)</procedure> 728 729 Convert a UTF-8 string to a Latin1 string. 557 730 558 731 Latin1 strings are 8-bits per character: a popular "high ASCII" encoding. … … 560 733 Please note that we do not supply a UTF-8 to Latin1 converter, since Latin1 can't express most Unicode codepoints. It's a legacy encoding; you should be converting away from it at all times. 561 734 735 === Convenience Functions 736 737 ==== <procedure>(read-from-file file-name)</procedure> 738 739 Assuming that PhysicsFS has been initialized and that a location has been mounted, this function will read an entire file into a <type>blob</type>. 740 741 Throws errors if the parameter is not a string, or if the declared file name cannot be found, or if PhysicsFS is not initialized. 742 743 ==== <procedure>(write-to-file file-name data)</procedure> 744 745 Assuming that PhysicsFS has been initialized and that a mount point is available; given a file name and a <type>blob</type> this function will write the entire contents of the blob to the file. 746 747 Throws errors if the parameters are incorrect, or if PhysicsFS is not initialized. 748 749 == Known Issues 750 751 * 64-bit return values for foreign bindings are not supported by Chicken at the moment, and as such the read-foo64 bindings, and others, aren't actually available. 752 562 753 == Author 563 754 … … 566 757 == Version history 567 758 759 ; 2.0 : Switched from camel case to hyphenated style, added write-to-file and read-from-file 568 760 ; 1.0 : First release, interfaces conform to The Scheme Way 569 761 ; 0.1 : Alpha release, version with tests coming soon
Note: See TracChangeset
for help on using the changeset viewer.