physfs.h
author Ryan C. Gordon <icculus@icculus.org>
Thu, 28 Jun 2001 11:00:14 +0000
changeset 3 0dd785321345
parent 2 24ba671694af
child 6 3662cbc014ef
permissions -rw-r--r--
Boatloads of updates to the spec.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/**
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
 * PhysicsFS; a portable, flexible file i/o abstraction.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
 * This API gives you access to a system file system in ways superior to the
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 *  stdio or system i/o calls. The brief benefits:
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
 *   - It's portable.
2
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
     8
 *   - It's safe. No file access is permitted outside the specified dirs.
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
 *   - It's flexible. Archives (.ZIP files) can be used transparently as
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
 *      directory structures.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
 * This system is largely inspired by Quake 3's PK3 files and the related
2
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
    13
 *  fs_* cvars. If you've ever tinkered with these, then this API will be
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
 *  familiar to you.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
 *
2
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
    16
 * With PhysicsFS, you have a single writing path and multiple "search paths"
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
    17
 *  for reading. You can think of this as a filesystem within a
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
 *  filesystem. If (on Windows) you were to set the writing directory to
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
 *  "C:\MyGame\MyWritingDirectory", then no PHYSFS calls could touch anything
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
 *  above this directory, including the "C:\MyGame" and "C:\" directories.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
 *  This prevents an application's internal scripting language from piddling
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
 *  over c:\config.sys, for example. If you'd rather give PHYSFS full access
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
 *  to the system's REAL file system, set the writing path to "C:\", but
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
 *  that's generally A Bad Thing for several reasons.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
 * Drive letters are hidden in PhysicsFS once you set up your initial paths.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
 *  The search paths create a single, hierarchical directory structure.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
 *  Not only does this lend itself well to general abstraction with archives,
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
 *  it also gives better support to operating systems like MacOS and Unix.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
 *  Generally speaking, you shouldn't ever hardcode a drive letter; not only
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
 *  does this hurt portability to non-Microsoft OSes, but it limits your win32
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
 *  users to a single drive, too. Use the PhysicsFS abstraction functions and
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
 *  allow user-defined configuration options, too. When opening a file, you
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
 *  specify it like it was on a Unix filesystem: if you want to write to
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
 *  "C:\MyGame\MyConfigFiles\game.cfg", then you might set the write path to
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
 *  "C:\MyGame" and then open "MyConfigFiles/game.cfg". This gives an
2
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
    37
 *  abstraction across all platforms. Specifying a file in this way is termed
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
    38
 *  "platform-independent notation" in this documentation. Specifying a path
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
    39
 *  as "C:\mydir\myfile" or "MacOS hard drive:My Directory:My File" is termed
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
    40
 *  "platform-dependent notation". The only time you use platform-dependent
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
    41
 *  notation is when setting up your write and search paths; after that, all
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
    42
 *  file access into those paths are done with platform-independent notation.
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
 * All files opened for writing are opened in relation to the write path,
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
 *  which is the root of the writable filesystem. When opening a file for
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
 *  reading, PhysicsFS goes through it's internal search path. This is NOT the
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
 *  same thing as the PATH environment variable. An application using
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
 *  PhysicsFS specifies directories to be searched which may be actual
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
 *  directories, or archive files that contain files and subdirectories of
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
 *  their own. See the end of these docs for currently supported archive
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
 *  formats.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
 * Once a search path is defined, you may open files for reading. If you've
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
 *  got the following search path defined (to use a win32 example again):
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
 *    C:\mygame
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
 *    C:\mygame\myuserfiles
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
 *    D:\mygamescdromdatafiles
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
 *    C:\mygame\installeddatafiles.zip
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
 * Then a call to PHYSFS_openread("textfiles/myfile.txt") (note the directory
2
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
    62
 *  separator, lack of drive letter, and lack of dir separator at the start of
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
    63
 *  the string; this is platform-independent notation) will check for
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
    64
 *  C:\mygame\textfiles\myfile.txt, then
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
 *  C:\mygame\myuserfiles\textfiles\myfile.txt, then
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
 *  D:\mygamescdromdatafiles\textfiles\myfile.txt, then, finally, for
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
 *  textfiles\myfile.txt inside of C:\mygame\installeddatafiles.zip. Remember
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
 *  that most archive types and platform filesystems store their filenames in
2
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
    69
 *  a case-sensitive manner, so you should be careful to specify it correctly.
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
 * Files opened through PhysicsFS may NOT contain "." or ".." as path
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
 *  elements. Not only are these meaningless on MacOS, they are a security
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
 *  hole. Also, symbolic links (which can be found in some archive types and
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
 *  directly in the filesystem on Unix platforms) are NOT followed until you
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
 *  call PHYSFS_permitSymbolicLinks(). That's left to your own discretion, as
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
 *  following a symlink can allow for access outside the write and search
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
 *  paths. There is no mechanism for creating new symlinks in PhysicsFS.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
 * The write path is not included in the search path unless you specifically
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
 *  add it. While you CAN change the write path as many times as you like,
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
    81
 *  you should probably set it once and stick to that path. Remember that
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
    82
 *  your program will not have permission to write in every directory on
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
    83
 *  Unix and NT systems.
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
 * All files are opened in binary mode; there is no endline conversion for
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
 *  textfiles. Other than that, PhysicsFS has some convenience functions for
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
    87
 *  platform-independence. There is a function to tell you the current
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
 *  platform's path separator ("\\" on windows, "/" on Unix, ":" on MacOS),
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
    89
 *  which is needed only to set up your search/write paths. There is a
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
    90
 *  function to tell you what CD-ROM drives contain accessible discs, and a
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
    91
 *  function to recommend a good search path, etc.
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
 * A recommended order for a search path is the write path, then the base path,
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
 *  then the cdrom path, then any archives discovered. Quake 3 does something
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
    95
 *  like this, but moves the archives to the start of the search path. Build
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
    96
 *  Engine games, like Duke Nukem 3D and Blood, place the archives last, and
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
    97
 *  use the base path for both searching and writing. There is a helper
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
    98
 *  function (PHYSFS_setSanePaths()) that puts together a basic configuration
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
    99
 *  for you, based on a few parameters. Also see the comments on
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   100
 *  PHYSFS_getBasePath(), and PHYSFS_getUserPath() for info on what those
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   101
 *  are and how they can help you determine an optimal searchpath.
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
 *
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   103
 * While you CAN use stdio/syscall file access in a program that has PHYSFS_*
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   104
 *  calls, doing so is not recommended, and you can not use system
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
 *  filehandles with PhysicsFS filehandles and vice versa.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
 * Note that archives need not be named as such: if you have a ZIP file and
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   108
 *  rename it with a .PKG extension, the file will still be recognized as a
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   109
 *  ZIP archive by PhysicsFS; the file's contents are used to determine its
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
 *  type.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
 * Currently supported archive types:
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
 *   - .ZIP (pkZip/WinZip/Info-ZIP compatible)
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
 * Please see the file LICENSE in the source's root directory.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
 *  This file written by Ryan C. Gordon.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
 */
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
#ifndef _INCLUDE_PHYSFS_H_
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
#define _INCLUDE_PHYSFS_H_
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
#ifdef __cplusplus
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
extern "C" {
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
#endif
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   128
typedef struct __PHYSFS_FILE__
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   129
{
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   130
    unsigned int opaque;
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   131
} PHYSFS_file;
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   132
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   133
typedef struct __PHYSFS_ARCHIVEINFO__
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   134
{
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   135
    const char *extension;
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   136
    const char *description;
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   137
} PHYSFS_ArchiveInfo;
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   138
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   139
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
/* functions... */
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
2
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   142
/**
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   143
 * Initialize PhysicsFS. This must be called before any other PhysicsFS
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   144
 *  function.
2
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   145
 *
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   146
 *   @param argv0 the argv[0] string passed to your program's mainline.
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   147
 *  @return nonzero on success, zero on error. Specifics of the error can be
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   148
 *          gleaned from PHYSFS_getLastError().
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   149
 */
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   150
int PHYSFS_init(const char *argv0);
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   151
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   152
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   153
/**
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   154
 * Shutdown PhysicsFS. This closes any files opened via PhysicsFS, blanks the
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   155
 *  search/write paths, frees memory, and invalidates all of your handles.
2
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   156
 *
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   157
 * Once deinitialized, PHYSFS_init() can be called again to restart the
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   158
 *  subsystem.
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   159
 *
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   160
 *  @return nonzero on success, zero on error. Specifics of the error can be
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   161
 *          gleaned from PHYSFS_getLastError(). If failure, state of PhysFS is
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   162
 *          undefined, and probably badly screwed up.
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   163
 */
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   164
void PHYSFS_deinit(void);
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   165
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
/**
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   168
 * Get a list of archive types supported by this implementation of PhysicFS.
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   169
 *  These are the file formats usable for search path entries. This is for
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   170
 *  informational purposes only. Note that the extension listed is merely
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   171
 *  convention: if we list "ZIP", you can open a PkZip-compatible archive
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   172
 *  with an extension of "XYZ", if you like.
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   173
 *
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   174
 * The returned value is an array of strings, with a NULL entry to signify the
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   175
 *  end of the list:
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   176
 *
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   177
 * PHYSFS_ArchiveInfo **i;
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   178
 *
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   179
 * for (i = PHYSFS_supportedArchiveTypes(); *i != NULL; i++)
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   180
 * {
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   181
 *     printf("Supported archive: [%s], which is [%s].\n",
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   182
 *              i->extension, i->description);
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   183
 * }
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   184
 *
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   185
 * The return values are pointers to static internal memory, and should
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   186
 *  be considered READ ONLY, and never freed.
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   187
 *
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   188
 *   @return READ ONLY Null-terminated array of READ ONLY structures.
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   189
 */
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   190
const PHYSFS_ArchiveInfo *PHYSFS_supportedArchiveTypes(void);
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   191
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   192
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   193
/**
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   194
 * Certain PhysicsFS functions return lists of information that are
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   195
 *  dynamically allocated. Use this function to free those resources.
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   196
 *
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   197
 *   @param list List of information specified as freeable by this function.
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   198
 */
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   199
void PHYSFS_freeList(void *list);
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   200
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   201
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   202
/**
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
 * Get the last PhysicsFS error message as a null-terminated string.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
 *  This will be NULL if there's been no error since the last call to this
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   205
 *  function. The pointer returned by this call points to an
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   206
 *  internal buffer. Each thread has a unique error state associated with it.
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
 *   @return READ ONLY string of last error message.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   209
 */
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
const char *PHYSFS_getLastError(void);
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
/**
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
 * Get a platform-dependent path separator. This is "\\" on win32, "/" on Unix,
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
 *  and ":" on MacOS. It may be more than one character, depending on the
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   216
 *  platform, and your code should take that into account. Note that this is
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217
 *  only useful for setting up the search/write paths, since access into those
2
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   218
 *  paths always use '/' (platform-independent notation) to separate
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   219
 *  directories. This is also handy for getting platform-independent access
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   220
 *  when using stdio calls.
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   221
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   222
 *   @return READ ONLY null-terminated string of platform's path separator.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   223
 */
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   224
const char *PHYSFS_getPathSeparator(void);
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   226
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   227
/**
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   228
 * Get an array of paths to available CD-ROM drives.
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   229
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   230
 * The paths returned are platform-dependent ("D:\" on Win32, "/cdrom" or
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   231
 *  whatnot on Unix). Paths are only returned if there is a disc ready and
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   232
 *  accessible in the drive. So if you've got two drives (D: and E:), and only
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   233
 *  E: has a disc in it, then that's all you get. If the user inserts a disc
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   234
 *  in D: and you call this function again, you get both drives. If, on a
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   235
 *  Unix box, the user unmounts a disc and remounts it elsewhere, the next
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   236
 *  call to this function will reflect that change. Fun.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   237
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   238
 * The returned value is an array of strings, with a NULL entry to signify the
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   239
 *  end of the list:
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   240
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   241
 * char **i;
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   242
 *
2
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   243
 * for (i = PHYSFS_getCdRomPaths(); *i != NULL; i++)
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   244
 *     printf("cdrom path [%s] is available.\n", *i);
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   245
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   246
 * This call may block while drives spin up. Be forewarned.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   247
 *
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   248
 * When you are done with the returned information, you may dispose of the
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   249
 *  resources by calling PHYSFS_freeList() with the returned pointer.
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   250
 *
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   251
 *   @return Null-terminated array of null-terminated strings.
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   252
 */
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   253
char **PHYSFS_getCdRomPaths(void);
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   254
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   255
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   256
/**
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   257
 * Helper function.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   258
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   259
 * Get the "base path". This is the directory where the application was run
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   260
 *  from, which is probably the installation directory, and may or may not
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   261
 *  be the process's current working directory.
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   262
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   263
 * You should probably use the base path in your search path.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   264
 *
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   265
 *  @return READ ONLY string of base path in platform-dependent notation.
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   266
 */
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   267
const char *PHYSFS_getBasePath(void);
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   268
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   269
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   270
/**
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   271
 * Helper function.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   272
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   273
 * Get the "user path". This is meant to be a suggestion of where a specific
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   274
 *  user of the system can store files. On Unix, this is her home directory.
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   275
 *  On systems with no concept of multiple home directories (MacOS, win95),
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   276
 *  this will default to something like "C:\mybasepath\users\username"
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   277
 *  where "username" will either be the login name, or "default" if the
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   278
 *  platform doesn't support multiple users, either.
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   279
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   280
 * You should probably use the user path as the basis for your write path, and
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   281
 *  also put it near the beginning of your search path.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   282
 *
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   283
 *  @return READ ONLY string of user path in platform-dependent notation.
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   284
 */
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   285
const char *PHYSFS_getUserPath(void);
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   286
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   287
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   288
/**
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   289
 * Get the current write path. The default write path is NULL.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   290
 *
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   291
 *  @return READ ONLY string of write path in platform-dependent notation,
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   292
 *           OR NULL IF NO WRITE PATH IS CURRENTLY SET.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   293
 */
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   294
const char *PHYSFS_getWritePath(char *buffer, int bufferSize);
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   295
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   296
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   297
/**
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   298
 * Set a new write path. This will override the previous setting. If the
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   299
 *  directory or a parent directory doesn't exist in the physical filesystem,
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   300
 *  PhysicsFS will attempt to create them as needed.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   301
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   302
 * This call will fail (and fail to change the write path) if the current path
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   303
 *  still has files open in it.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   304
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   305
 *   @param newPath The new directory to be the root of the write path,
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   306
 *                   specified in platform-dependent notation. Setting to NULL
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   307
 *                   disables the write path, so no files can be opened for
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   308
 *                   writing via PhysicsFS.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   309
 *  @return non-zero on success, zero on failure. All attempts to open a file
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   310
 *           for writing via PhysicsFS will fail until this call succeeds.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   311
 *           Specifics of the error can be gleaned from PHYSFS_getLastError().
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   312
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   313
 */
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   314
int PHYSFS_setWritePath(const char *newPath);
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   315
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   316
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   317
/**
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   318
 * Add a directory or archive to the search path. If this is a duplicate, the
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   319
 *  entry is not added again, even though the function succeeds.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   320
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   321
 *   @param newPath directory or archive to add to the path, in
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   322
 *                   platform-dependent notation.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   323
 *   @param appendToPath nonzero to append to search path, zero to prepend.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   324
 *  @return nonzero if added to path, zero on failure (bogus archive, path
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   325
 *                   missing, etc). Specifics of the error can be
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   326
 *                   gleaned from PHYSFS_getLastError().
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   327
 */
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   328
int PHYSFS_addToSearchPath(const char *newPath, int appendToPath);
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   329
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   330
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   331
/**
2
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   332
 * Remove a directory or archive from the search path.
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   333
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   334
 * This must be a (case-sensitive) match to a dir or archive already in the
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   335
 *  search path, specified in platform-dependent notation.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   336
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   337
 * This call will fail (and fail to remove from the path) if the element still
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   338
 *  has files open in it.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   339
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   340
 *    @param oldPath dir/archive to remove.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   341
 *   @return nonzero on success, zero on failure.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   342
 *            Specifics of the error can be gleaned from PHYSFS_getLastError().
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   343
 */
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   344
int PHYSFS_removeFromSearchPath(const char *oldPath);
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   345
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   346
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   347
/**
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   348
 * Get the current search path. The default search path is an empty list.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   349
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   350
 * The returned value is an array of strings, with a NULL entry to signify the
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   351
 *  end of the list:
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   352
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   353
 * char **i;
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   354
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   355
 * for (i = PHYSFS_getSearchPath(); *i != NULL; i++)
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   356
 *     printf("[%s] is in the search path.\n", *i);
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   357
 *
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   358
 * When you are done with the returned information, you may dispose of the
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   359
 *  resources by calling PHYSFS_freeList() with the returned pointer.
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   360
 *
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   361
 *   @return Null-terminated array of null-terminated strings.
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   362
 */
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   363
char **PHYSFS_getSearchPath(void);
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   364
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   365
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   366
/**
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   367
 * Helper function.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   368
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   369
 * Set up sane, default paths. The write path will be set to
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   370
 *  "userpath/.appName", which is created if it doesn't exist.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   371
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   372
 * The above is sufficient to make sure your program's configuration directory
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   373
 *  is separated from other clutter, and platform-independent. The period
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   374
 *  before "mygame" even hides the directory on Unix systems.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   375
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   376
 *  The search path will be:
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   377
 *
2
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   378
 *    - The Write Path (created if it doesn't exist)
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   379
 *    - The Write Path/appName (created if it doesn't exist)
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   380
 *    - The Base Path (PHYSFS_getBasePath())
2
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   381
 *    - The Base Path/appName (if it exists)
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   382
 *    - All found CD-ROM paths (optionally)
2
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   383
 *    - All found CD-ROM paths/appName (optionally, and if they exist)
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   384
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   385
 * These directories are then searched for files ending with the extension
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   386
 *  (archiveExt), which, if they are valid and supported archives, will also
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   387
 *  be added to the search path. If you specified "PKG" for (archiveExt), and
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   388
 *  there's a file named data.PKG in the base dir, it'll be checked. Archives
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   389
 *  can either be appended or prepended to the search path in alphabetical
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   390
 *  order, regardless of which directories they were found in.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   391
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   392
 * All of this can be accomplished from the application, but this just does it
2
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   393
 *  all for you. Feel free to add more to the search path manually, too.
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   394
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   395
 *    @param appName Program-specific name of your program, to separate it
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   396
 *                   from other programs using PhysicsFS.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   397
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   398
 *    @param archiveExt File extention used by your program to specify an
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   399
 *                      archive. For example, Quake 3 uses "pk3", even though
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   400
 *                      they are just zipfiles. Specify NULL to not dig out
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   401
 *                      archives automatically.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   402
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   403
 *    @param includeCdRoms Non-zero to include CD-ROMs in the search path, and
2
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   404
 *                         (if (archiveExt) != NULL) search them for archives.
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   405
 *                         This may cause a significant amount of blocking
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   406
 *                         while discs are accessed, and if there are no discs
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   407
 *                         in the drive (or even not mounted on Unix systems),
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   408
 *                         then they may not be made available anyhow. You may
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   409
 *                         want to specify zero and handle the disc setup
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   410
 *                         yourself.
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   411
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   412
 *    @param archivesFirst Non-zero to prepend the archives to the search path.
2
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   413
 *                          Zero to append them. Ignored if !(archiveExt).
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   414
 */
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   415
void PHYSFS_setSanePaths(const char *appName, const char *archiveExt,
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   416
                         int includeCdRoms, int archivesFirst);
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   417
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   418
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   419
/**
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   420
 * Create a directory. This is specified in platform-independent notation in
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   421
 *  relation to the write path. All missing parent directories are also
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   422
 *  created if they don't exist.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   423
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   424
 * So if you've got the write path set to "C:\mygame\writepath" and call
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   425
 *  PHYSFS_mkdir("downloads/maps") then the directories
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   426
 *  "C:\mygame\writepath\downloads" and "C:\mygame\writepath\downloads\maps"
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   427
 *  will be created if possible. If the creation of "maps" fails after we
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   428
 *  have successfully created "downloads", then the function leaves the
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   429
 *  created directory behind and reports failure.
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   430
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   431
 *   @param dirname New path to create.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   432
 *  @return nonzero on success, zero on error. Specifics of the error can be
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   433
 *          gleaned from PHYSFS_getLastError().
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   434
 */
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   435
int PHYSFS_mkdir(const char *dirName);
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   436
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   437
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   438
/**
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   439
 * Delete a file or directory. This is specified in platform-independent
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   440
 *  notation in relation to the write path.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   441
 *
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   442
 * A directory must be empty before this call can delete it.
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   443
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   444
 * So if you've got the write path set to "C:\mygame\writepath" and call
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   445
 *  PHYSFS_delete("downloads/maps/level1.map") then the file
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   446
 *  "C:\mygame\writepath\downloads\maps\level1.map" is removed from the
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   447
 *  physical filesystem, if it exists and the operating system permits the
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   448
 *  deletion.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   449
 *
2
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   450
 * Note that on Unix systems, deleting a file may be successful, but the
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   451
 *  actual file won't be removed until all processes that have an open
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   452
 *  filehandle to it (including your program) close their handles.
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   453
 *
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   454
 *   @param filename Filename to delete.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   455
 *  @return nonzero on success, zero on error. Specifics of the error can be
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   456
 *          gleaned from PHYSFS_getLastError().
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   457
 */
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   458
int PHYSFS_delete(const char *filename);
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   459
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   460
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   461
/**
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   462
 * Enable symbolic links. Some physical filesystems and archives contain
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   463
 *  files that are just pointers to other files. On the physical filesystem,
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   464
 *  opening such a link will (transparently) open the file that is pointed to.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   465
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   466
 * By default, PhysicsFS will check if a file is really a symlink during open
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   467
 *  calls and fail if it is. Otherwise, the link could take you outside the
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   468
 *  write and search paths, and compromise security.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   469
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   470
 * If you want to take that risk, call this function with a non-zero parameter.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   471
 *  Note that this is more for sandboxing a program's scripting language, in
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   472
 *  case untrusted scripts try to compromise the system. Generally speaking,
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   473
 *  a user could very well have a legitimate reason to set up a symlink, so
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   474
 *  unless you feel there's a specific danger in allowing them, you should
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   475
 *  permit them.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   476
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   477
 * Symbolic link permission can be enabled or disabled at any time, and is
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   478
 *  disabled by default.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   479
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   480
 *   @param allow nonzero to permit symlinks, zero to deny linking.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   481
 */
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   482
void PHYSFS_permitSymbolicLinks(int allow);
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   483
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   484
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   485
/**
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   486
 * Figure out where in the search path a file resides. The file is specified
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   487
 *  in platform-independent notation. The returned filename will be the
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   488
 *  element of the search path where the file was found, which may be a
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   489
 *  directory, or an archive. Even if there are multiple matches in different
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   490
 *  parts of the search path, only the first one found is used, just like
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   491
 *  when opening a file.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   492
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   493
 * So, if you look for "maps/level1.map", and C:\mygame is in your search
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   494
 *  path and C:\mygame\maps\level1.map exists, then "C:\mygame" is returned.
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   495
 *
2
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   496
 * If a match is a symbolic link, and you've not explicitly permitted symlinks,
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   497
 *  then it will be ignored, and the search for a match will continue.
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   498
 *
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   499
 *     @param filename file to look for.
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   500
 *    @return READ ONLY string of element of search path containing the
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   501
 *             the file in question. NULL if not found.
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   502
 */
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   503
const char *PHYSFS_getRealPath(const char *filename);
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   504
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   505
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   506
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   507
/**
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   508
 * Get a file listing of a search path's directory. Matching directories are
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   509
 *  interpolated. That is, if "C:\mypath" is in the search path and contains a
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   510
 *  directory "savegames" that contains "x.sav", "y.sav", and "z.sav", and
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   511
 *  there is also a "C:\userpath" in the search path that has a "savegames"
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   512
 *  subdirectory with "w.sav", then the following code:
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   513
 *
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   514
 * ------------------------------------------------
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   515
 * char **rc = PHYSFS_enumerateFiles("savegames");
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   516
 * char **i;
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   517
 *
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   518
 * for (i = rc; *i != NULL; i++)
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   519
 *     printf("We've got [%s].\n", *i);
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   520
 *
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   521
 * PHYSFS_freeList(rc);
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   522
 * ------------------------------------------------
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   523
 *
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   524
 *  ...will print:
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   525
 *
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   526
 * ------------------------------------------------
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   527
 * We've got [x.sav].
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   528
 * We've got [y.sav].
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   529
 * We've got [z.sav].
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   530
 * We've got [w.sav].
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   531
 * ------------------------------------------------
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   532
 *
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   533
 * Don't forget to call PHYSFS_freeList() with the return value from this
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   534
 *  function when you are done with it.
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   535
 *
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   536
 *    @param path directory in platform-independent notation to enumerate.
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   537
 *   @return Null-terminated array of null-terminated strings.
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   538
 */
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   539
char **PHYSFS_enumerateFiles(const char *path);
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   540
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   541
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   542
/**
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   543
 * Open a file for writing, in platform-independent notation and in relation
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   544
 *  to the write path as the root of the writable filesystem. The specified
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   545
 *  file is created if it doesn't exist. If it does exist, it is truncated to
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   546
 *  zero bytes, and the writing offset is set to the start.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   547
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   548
 *   @param filename File to open.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   549
 *  @return A valid PhysicsFS filehandle on success, NULL on error. Specifics
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   550
 *           of the error can be gleaned from PHYSFS_getLastError().
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   551
 */
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   552
PHYSFS_file *PHYSFS_openWrite(const char *filename);
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   553
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   554
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   555
/**
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   556
 * Open a file for writing, in platform-independent notation and in relation
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   557
 *  to the write path as the root of the writable filesystem. The specified
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   558
 *  file is created if it doesn't exist. If it does exist, the writing offset
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   559
 *  is set to the end of the file, so the first write will be the byte after
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   560
 *  the end.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   561
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   562
 *   @param filename File to open.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   563
 *  @return A valid PhysicsFS filehandle on success, NULL on error. Specifics
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   564
 *           of the error can be gleaned from PHYSFS_getLastError().
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   565
 */
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   566
PHYSFS_file *PHYSFS_openAppend(const char *filename);
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   567
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   568
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   569
/**
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   570
 * Open a file for reading, in platform-independent notation. The search path
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   571
 *  is checked one at a time until a matching file is found, in which case an
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   572
 *  abstract filehandle is associated with it, and reading may be done.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   573
 *  The reading offset is set to the first byte of the file.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   574
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   575
 *   @param filename File to open.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   576
 *  @return A valid PhysicsFS filehandle on success, NULL on error. Specifics
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   577
 *           of the error can be gleaned from PHYSFS_getLastError().
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   578
 */
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   579
PHYSFS_file *PHYSFS_openRead(const char *filename);
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   580
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   581
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   582
/**
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   583
 * Close a PhysicsFS filehandle. This call is capable of failing if the
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   584
 *  operating system was buffering writes to this file, and (now forced to
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   585
 *  write those changes to physical media) can not store the data for any
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   586
 *  reason. In such a case, the filehandle stays open. A well-written program
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   587
 *  should ALWAYS check the return value from the close call in addition to
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   588
 *  every writing call!
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   589
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   590
 *   @param handle handle returned from PHYSFS_open*().
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   591
 *  @return nonzero on success, zero on error. Specifics of the error can be
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   592
 *          gleaned from PHYSFS_getLastError().
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   593
 */
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   594
int PHYSFS_close(PHYSFS_file *handle);
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   595
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   596
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   597
/**
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   598
 * Read data from a PhysicsFS filehandle. The file must be opened for reading.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   599
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   600
 *   @param handle handle returned from PHYSFS_openRead().
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   601
 *   @param buffer buffer to store read data into.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   602
 *   @param objSize size in bytes of objects being read from (handle).
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   603
 *   @param objCount number of (objSize) objects to read from (handle).
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   604
 *  @return number of objects read. PHYSFS_getLastError() can shed light on
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   605
 *           the reason this might be < (objCount), as can PHYSFS_eof().
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   606
 */
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   607
int PHYSFS_read(PHYSFS_file *handle, void *buffer,
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   608
                unsigned int objSize, unsigned int objCount);
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   609
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   610
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   611
/**
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   612
 * Write data to a PhysicsFS filehandle. The file must be opened for writing.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   613
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   614
 *   @param handle retval from PHYSFS_openWrite() or PHYSFS_openAppend().
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   615
 *   @param buffer buffer to store read data into.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   616
 *   @param objSize size in bytes of objects being read from (handle).
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   617
 *   @param objCount number of (objSize) objects to read from (handle).
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   618
 *  @return number of objects read. PHYSFS_getLastError() can shed light on
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   619
 *           the reason this might be < (objCount).
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   620
 */
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   621
int PHYSFS_write(PHYSFS_file *handle, void *buffer,
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   622
                 unsigned int objSize, unsigned int objCount);
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   623
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   624
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   625
/**
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   626
 * Determine if the end of file has been reached in a PhysicsFS filehandle.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   627
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   628
 *   @param handle handle returned from PHYSFS_openRead().
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   629
 *  @return nonzero if EOF, zero if not.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   630
 */
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   631
int PHYSFS_eof(PHYSFS_file *handle);
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   632
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   633
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   634
/**
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   635
 * Determine current position within a PhysicsFS filehandle.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   636
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   637
 *   @param handle handle returned from PHYSFS_open*().
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   638
 *  @return offset in bytes from start of file. -1 if error occurred.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   639
 *           Specifics of the error can be gleaned from PHYSFS_getLastError().
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   640
 */
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   641
int PHYSFS_tell(PHYSFS_file *handle);
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   642
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   643
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   644
/**
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   645
 * Seek to a new position within a PhysicsFS filehandle. The next read or write
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   646
 *  will occur at that place. Seeking past the beginning or end of the file is
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   647
 *  not allowed.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   648
 *
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   649
 *   @param handle handle returned from PHYSFS_open*().
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   650
 *   @param pos number of bytes from start of file to seek to.
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   651
 *  @return nonzero on success, zero on error. Specifics of the error can be
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   652
 *          gleaned from PHYSFS_getLastError().
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   653
 */
3
0dd785321345 Boatloads of updates to the spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 2
diff changeset
   654
int PHYSFS_seek(PHYSFS_file *handle, int pos);
2
24ba671694af Fixed typos, expanded documentation, added init and deinit functions, and
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
   655
1
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   656
#ifdef __cplusplus
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   657
}
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   658
#endif
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   659
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   660
#endif  /* !defined _INCLUDE_PHYSFS_H_ */
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   661
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   662
/* end of physfs.h ... */
b5ce9d35fdb4 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   663