author | Ryan C. Gordon <icculus@icculus.org> |
Thu, 25 Feb 2016 01:16:42 -0500 | |
changeset 1371 | da48b9ff4c9b |
parent 1363 | a3dabf75a0d0 |
child 1372 | 1a64a2857a0c |
permissions | -rw-r--r-- |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1 |
/** |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
2 |
* PhysicsFS; a portable, flexible file i/o abstraction. |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
3 |
* |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
4 |
* Documentation is in physfs.h. It's verbose, honest. :) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 |
* |
809
116b8fe30371
Renamed LICENSE to LICENSE.txt
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
6 |
* Please see the file LICENSE.txt in the source's root directory. |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
7 |
* |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 |
* This file written by Ryan C. Gordon. |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
9 |
*/ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
10 |
|
1098
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1090
diff
changeset
|
11 |
/* !!! FIXME: ERR_PAST_EOF shouldn't trigger for reads. Just return zero. */ |
1226
3ea51c799aba
Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents:
1225
diff
changeset
|
12 |
/* !!! FIXME: use snprintf(), not sprintf(). */ |
1098
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1090
diff
changeset
|
13 |
|
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
14 |
#define __PHYSICSFS_INTERNAL__ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
15 |
#include "physfs_internal.h" |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
16 |
|
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
17 |
|
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
18 |
typedef struct __PHYSFS_DIRHANDLE__ |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
19 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
20 |
void *opaque; /* Instance data unique to the archiver. */ |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
21 |
char *dirName; /* Path to archive in platform-dependent notation. */ |
679
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
22 |
char *mountPoint; /* Mountpoint in virtual file tree. */ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
23 |
const PHYSFS_Archiver *funcs; /* Ptr to archiver info for this handle. */ |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
24 |
struct __PHYSFS_DIRHANDLE__ *next; /* linked list stuff. */ |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
25 |
} DirHandle; |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
26 |
|
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
27 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
28 |
typedef struct __PHYSFS_FILEHANDLE__ |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
29 |
{ |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
30 |
PHYSFS_Io *io; /* Instance data unique to the archiver for this file. */ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
31 |
PHYSFS_uint8 forReading; /* Non-zero if reading, zero if write/append */ |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
32 |
const DirHandle *dirHandle; /* Archiver instance that created this */ |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
33 |
PHYSFS_uint8 *buffer; /* Buffer, if set (NULL otherwise). Don't touch! */ |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
34 |
PHYSFS_uint32 bufsize; /* Bufsize, if set (0 otherwise). Don't touch! */ |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
35 |
PHYSFS_uint32 buffill; /* Buffer fill size. Don't touch! */ |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
36 |
PHYSFS_uint32 bufpos; /* Buffer position. Don't touch! */ |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
37 |
struct __PHYSFS_FILEHANDLE__ *next; /* linked list stuff. */ |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
38 |
} FileHandle; |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
39 |
|
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
40 |
|
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
41 |
typedef struct __PHYSFS_ERRSTATETYPE__ |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
42 |
{ |
1012
f254870dd7dd
Attempt to clean up the thread ID mess in platform_unix ...
Ryan C. Gordon <icculus@icculus.org>
parents:
986
diff
changeset
|
43 |
void *tid; |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
44 |
PHYSFS_ErrorCode code; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
45 |
struct __PHYSFS_ERRSTATETYPE__ *next; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
46 |
} ErrState; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
47 |
|
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
48 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
49 |
/* General PhysicsFS state ... */ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
50 |
static int initialized = 0; |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
51 |
static ErrState *errorStates = NULL; |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
52 |
static DirHandle *searchPath = NULL; |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
53 |
static DirHandle *writeDir = NULL; |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
54 |
static FileHandle *openWriteList = NULL; |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
55 |
static FileHandle *openReadList = NULL; |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
56 |
static char *baseDir = NULL; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
57 |
static char *userDir = NULL; |
1242
1e6db80d2393
Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1240
diff
changeset
|
58 |
static char *prefDir = NULL; |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
59 |
static int allowSymLinks = 0; |
1277
f6996bfaec19
Made archiver list dynamic, in preparation for external archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1270
diff
changeset
|
60 |
static const PHYSFS_Archiver **archivers = NULL; |
f6996bfaec19
Made archiver list dynamic, in preparation for external archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1270
diff
changeset
|
61 |
static const PHYSFS_ArchiveInfo **archiveInfo = NULL; |
1322
5476917b8ddf
Allow application-supplied archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1315
diff
changeset
|
62 |
static volatile size_t numArchivers = 0; |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
63 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
64 |
/* mutexes ... */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
65 |
static void *errorLock = NULL; /* protects error message list. */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
66 |
static void *stateLock = NULL; /* protects other PhysFS static state. */ |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
67 |
|
644
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
634
diff
changeset
|
68 |
/* allocator ... */ |
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
634
diff
changeset
|
69 |
static int externalAllocator = 0; |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
70 |
PHYSFS_Allocator allocator; |
644
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
634
diff
changeset
|
71 |
|
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
72 |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
73 |
/* PHYSFS_Io implementation for i/o to physical filesystem... */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
74 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
75 |
/* !!! FIXME: maybe refcount the paths in a string pool? */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
76 |
typedef struct __PHYSFS_NativeIoInfo |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
77 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
78 |
void *handle; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
79 |
const char *path; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
80 |
int mode; /* 'r', 'w', or 'a' */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
81 |
} NativeIoInfo; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
82 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
83 |
static PHYSFS_sint64 nativeIo_read(PHYSFS_Io *io, void *buf, PHYSFS_uint64 len) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
84 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
85 |
NativeIoInfo *info = (NativeIoInfo *) io->opaque; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
86 |
return __PHYSFS_platformRead(info->handle, buf, len); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
87 |
} /* nativeIo_read */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
88 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
89 |
static PHYSFS_sint64 nativeIo_write(PHYSFS_Io *io, const void *buffer, |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
90 |
PHYSFS_uint64 len) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
91 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
92 |
NativeIoInfo *info = (NativeIoInfo *) io->opaque; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
93 |
return __PHYSFS_platformWrite(info->handle, buffer, len); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
94 |
} /* nativeIo_write */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
95 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
96 |
static int nativeIo_seek(PHYSFS_Io *io, PHYSFS_uint64 offset) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
97 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
98 |
NativeIoInfo *info = (NativeIoInfo *) io->opaque; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
99 |
return __PHYSFS_platformSeek(info->handle, offset); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
100 |
} /* nativeIo_seek */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
101 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
102 |
static PHYSFS_sint64 nativeIo_tell(PHYSFS_Io *io) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
103 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
104 |
NativeIoInfo *info = (NativeIoInfo *) io->opaque; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
105 |
return __PHYSFS_platformTell(info->handle); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
106 |
} /* nativeIo_tell */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
107 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
108 |
static PHYSFS_sint64 nativeIo_length(PHYSFS_Io *io) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
109 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
110 |
NativeIoInfo *info = (NativeIoInfo *) io->opaque; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
111 |
return __PHYSFS_platformFileLength(info->handle); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
112 |
} /* nativeIo_length */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
113 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
114 |
static PHYSFS_Io *nativeIo_duplicate(PHYSFS_Io *io) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
115 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
116 |
NativeIoInfo *info = (NativeIoInfo *) io->opaque; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
117 |
return __PHYSFS_createNativeIo(info->path, info->mode); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
118 |
} /* nativeIo_duplicate */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
119 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
120 |
static int nativeIo_flush(PHYSFS_Io *io) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
121 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
122 |
return __PHYSFS_platformFlush(io->opaque); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
123 |
} /* nativeIo_flush */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
124 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
125 |
static void nativeIo_destroy(PHYSFS_Io *io) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
126 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
127 |
NativeIoInfo *info = (NativeIoInfo *) io->opaque; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
128 |
__PHYSFS_platformClose(info->handle); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
129 |
allocator.Free((void *) info->path); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
130 |
allocator.Free(info); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
131 |
allocator.Free(io); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
132 |
} /* nativeIo_destroy */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
133 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
134 |
static const PHYSFS_Io __PHYSFS_nativeIoInterface = |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
135 |
{ |
1280
bd174b99fa5b
Add binary compatibility to PHYSFS_Io.
Ryan C. Gordon <icculus@icculus.org>
parents:
1279
diff
changeset
|
136 |
CURRENT_PHYSFS_IO_API_VERSION, NULL, |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
137 |
nativeIo_read, |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
138 |
nativeIo_write, |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
139 |
nativeIo_seek, |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
140 |
nativeIo_tell, |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
141 |
nativeIo_length, |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
142 |
nativeIo_duplicate, |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
143 |
nativeIo_flush, |
1280
bd174b99fa5b
Add binary compatibility to PHYSFS_Io.
Ryan C. Gordon <icculus@icculus.org>
parents:
1279
diff
changeset
|
144 |
nativeIo_destroy |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
145 |
}; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
146 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
147 |
PHYSFS_Io *__PHYSFS_createNativeIo(const char *path, const int mode) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
148 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
149 |
PHYSFS_Io *io = NULL; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
150 |
NativeIoInfo *info = NULL; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
151 |
void *handle = NULL; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
152 |
char *pathdup = NULL; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
153 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
154 |
assert((mode == 'r') || (mode == 'w') || (mode == 'a')); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
155 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
156 |
io = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io)); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
157 |
GOTO_IF_MACRO(!io, PHYSFS_ERR_OUT_OF_MEMORY, createNativeIo_failed); |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
158 |
info = (NativeIoInfo *) allocator.Malloc(sizeof (NativeIoInfo)); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
159 |
GOTO_IF_MACRO(!info, PHYSFS_ERR_OUT_OF_MEMORY, createNativeIo_failed); |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
160 |
pathdup = (char *) allocator.Malloc(strlen(path) + 1); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
161 |
GOTO_IF_MACRO(!pathdup, PHYSFS_ERR_OUT_OF_MEMORY, createNativeIo_failed); |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
162 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
163 |
if (mode == 'r') |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
164 |
handle = __PHYSFS_platformOpenRead(path); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
165 |
else if (mode == 'w') |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
166 |
handle = __PHYSFS_platformOpenWrite(path); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
167 |
else if (mode == 'a') |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
168 |
handle = __PHYSFS_platformOpenAppend(path); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
169 |
|
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
170 |
GOTO_IF_MACRO(!handle, ERRPASS, createNativeIo_failed); |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
171 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
172 |
strcpy(pathdup, path); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
173 |
info->handle = handle; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
174 |
info->path = pathdup; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
175 |
info->mode = mode; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
176 |
memcpy(io, &__PHYSFS_nativeIoInterface, sizeof (*io)); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
177 |
io->opaque = info; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
178 |
return io; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
179 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
180 |
createNativeIo_failed: |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
181 |
if (handle != NULL) __PHYSFS_platformClose(handle); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
182 |
if (pathdup != NULL) allocator.Free(pathdup); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
183 |
if (info != NULL) allocator.Free(info); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
184 |
if (io != NULL) allocator.Free(io); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
185 |
return NULL; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
186 |
} /* __PHYSFS_createNativeIo */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
187 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
188 |
|
1120
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
189 |
/* PHYSFS_Io implementation for i/o to a memory buffer... */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
190 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
191 |
typedef struct __PHYSFS_MemoryIoInfo |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
192 |
{ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
193 |
const PHYSFS_uint8 *buf; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
194 |
PHYSFS_uint64 len; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
195 |
PHYSFS_uint64 pos; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
196 |
PHYSFS_Io *parent; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
197 |
volatile PHYSFS_uint32 refcount; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
198 |
void (*destruct)(void *); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
199 |
} MemoryIoInfo; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
200 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
201 |
static PHYSFS_sint64 memoryIo_read(PHYSFS_Io *io, void *buf, PHYSFS_uint64 len) |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
202 |
{ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
203 |
MemoryIoInfo *info = (MemoryIoInfo *) io->opaque; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
204 |
const PHYSFS_uint64 avail = info->len - info->pos; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
205 |
assert(avail <= info->len); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
206 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
207 |
if (avail == 0) |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
208 |
return 0; /* we're at EOF; nothing to do. */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
209 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
210 |
if (len > avail) |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
211 |
len = avail; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
212 |
|
1208
3edcb015089a
Fixed some compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1204
diff
changeset
|
213 |
memcpy(buf, info->buf + info->pos, (size_t) len); |
1120
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
214 |
info->pos += len; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
215 |
return len; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
216 |
} /* memoryIo_read */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
217 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
218 |
static PHYSFS_sint64 memoryIo_write(PHYSFS_Io *io, const void *buffer, |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
219 |
PHYSFS_uint64 len) |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
220 |
{ |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
221 |
BAIL_MACRO(PHYSFS_ERR_OPEN_FOR_READING, -1); |
1120
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
222 |
} /* memoryIo_write */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
223 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
224 |
static int memoryIo_seek(PHYSFS_Io *io, PHYSFS_uint64 offset) |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
225 |
{ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
226 |
MemoryIoInfo *info = (MemoryIoInfo *) io->opaque; |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
227 |
BAIL_IF_MACRO(offset > info->len, PHYSFS_ERR_PAST_EOF, 0); |
1120
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
228 |
info->pos = offset; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
229 |
return 1; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
230 |
} /* memoryIo_seek */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
231 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
232 |
static PHYSFS_sint64 memoryIo_tell(PHYSFS_Io *io) |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
233 |
{ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
234 |
const MemoryIoInfo *info = (MemoryIoInfo *) io->opaque; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
235 |
return (PHYSFS_sint64) info->pos; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
236 |
} /* memoryIo_tell */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
237 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
238 |
static PHYSFS_sint64 memoryIo_length(PHYSFS_Io *io) |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
239 |
{ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
240 |
const MemoryIoInfo *info = (MemoryIoInfo *) io->opaque; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
241 |
return (PHYSFS_sint64) info->len; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
242 |
} /* memoryIo_length */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
243 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
244 |
static PHYSFS_Io *memoryIo_duplicate(PHYSFS_Io *io) |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
245 |
{ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
246 |
MemoryIoInfo *info = (MemoryIoInfo *) io->opaque; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
247 |
MemoryIoInfo *newinfo = NULL; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
248 |
PHYSFS_Io *parent = info->parent; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
249 |
PHYSFS_Io *retval = NULL; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
250 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
251 |
/* avoid deep copies. */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
252 |
assert((!parent) || (!((MemoryIoInfo *) parent->opaque)->parent) ); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
253 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
254 |
/* share the buffer between duplicates. */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
255 |
if (parent != NULL) /* dup the parent, increment its refcount. */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
256 |
return parent->duplicate(parent); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
257 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
258 |
/* we're the parent. */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
259 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
260 |
retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io)); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
261 |
BAIL_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL); |
1120
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
262 |
newinfo = (MemoryIoInfo *) allocator.Malloc(sizeof (MemoryIoInfo)); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
263 |
if (!newinfo) |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
264 |
{ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
265 |
allocator.Free(retval); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
266 |
BAIL_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, NULL); |
1120
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
267 |
} /* if */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
268 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
269 |
/* !!! FIXME: want lockless atomic increment. */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
270 |
__PHYSFS_platformGrabMutex(stateLock); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
271 |
info->refcount++; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
272 |
__PHYSFS_platformReleaseMutex(stateLock); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
273 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
274 |
memset(newinfo, '\0', sizeof (*info)); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
275 |
newinfo->buf = info->buf; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
276 |
newinfo->len = info->len; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
277 |
newinfo->pos = 0; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
278 |
newinfo->parent = io; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
279 |
newinfo->refcount = 0; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
280 |
newinfo->destruct = NULL; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
281 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
282 |
memcpy(retval, io, sizeof (*retval)); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
283 |
retval->opaque = newinfo; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
284 |
return retval; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
285 |
} /* memoryIo_duplicate */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
286 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
287 |
static int memoryIo_flush(PHYSFS_Io *io) { return 1; /* it's read-only. */ } |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
288 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
289 |
static void memoryIo_destroy(PHYSFS_Io *io) |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
290 |
{ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
291 |
MemoryIoInfo *info = (MemoryIoInfo *) io->opaque; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
292 |
PHYSFS_Io *parent = info->parent; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
293 |
int should_die = 0; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
294 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
295 |
if (parent != NULL) |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
296 |
{ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
297 |
assert(info->buf == ((MemoryIoInfo *) info->parent->opaque)->buf); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
298 |
assert(info->len == ((MemoryIoInfo *) info->parent->opaque)->len); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
299 |
assert(info->refcount == 0); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
300 |
assert(info->destruct == NULL); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
301 |
allocator.Free(info); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
302 |
allocator.Free(io); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
303 |
parent->destroy(parent); /* decrements refcount. */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
304 |
return; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
305 |
} /* if */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
306 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
307 |
/* we _are_ the parent. */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
308 |
assert(info->refcount > 0); /* even in a race, we hold a reference. */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
309 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
310 |
/* !!! FIXME: want lockless atomic decrement. */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
311 |
__PHYSFS_platformGrabMutex(stateLock); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
312 |
info->refcount--; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
313 |
should_die = (info->refcount == 0); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
314 |
__PHYSFS_platformReleaseMutex(stateLock); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
315 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
316 |
if (should_die) |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
317 |
{ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
318 |
void (*destruct)(void *) = info->destruct; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
319 |
void *buf = (void *) info->buf; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
320 |
io->opaque = NULL; /* kill this here in case of race. */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
321 |
allocator.Free(info); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
322 |
allocator.Free(io); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
323 |
if (destruct != NULL) |
1191
f02c977477b9
Fixed up some bugs that clang's static analysis reported.
Ryan C. Gordon <icculus@icculus.org>
parents:
1135
diff
changeset
|
324 |
destruct(buf); |
1120
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
325 |
} /* if */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
326 |
} /* memoryIo_destroy */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
327 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
328 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
329 |
static const PHYSFS_Io __PHYSFS_memoryIoInterface = |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
330 |
{ |
1280
bd174b99fa5b
Add binary compatibility to PHYSFS_Io.
Ryan C. Gordon <icculus@icculus.org>
parents:
1279
diff
changeset
|
331 |
CURRENT_PHYSFS_IO_API_VERSION, NULL, |
1120
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
332 |
memoryIo_read, |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
333 |
memoryIo_write, |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
334 |
memoryIo_seek, |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
335 |
memoryIo_tell, |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
336 |
memoryIo_length, |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
337 |
memoryIo_duplicate, |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
338 |
memoryIo_flush, |
1280
bd174b99fa5b
Add binary compatibility to PHYSFS_Io.
Ryan C. Gordon <icculus@icculus.org>
parents:
1279
diff
changeset
|
339 |
memoryIo_destroy |
1120
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
340 |
}; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
341 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
342 |
PHYSFS_Io *__PHYSFS_createMemoryIo(const void *buf, PHYSFS_uint64 len, |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
343 |
void (*destruct)(void *)) |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
344 |
{ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
345 |
PHYSFS_Io *io = NULL; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
346 |
MemoryIoInfo *info = NULL; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
347 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
348 |
io = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io)); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
349 |
GOTO_IF_MACRO(!io, PHYSFS_ERR_OUT_OF_MEMORY, createMemoryIo_failed); |
1120
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
350 |
info = (MemoryIoInfo *) allocator.Malloc(sizeof (MemoryIoInfo)); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
351 |
GOTO_IF_MACRO(!info, PHYSFS_ERR_OUT_OF_MEMORY, createMemoryIo_failed); |
1120
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
352 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
353 |
memset(info, '\0', sizeof (*info)); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
354 |
info->buf = (const PHYSFS_uint8 *) buf; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
355 |
info->len = len; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
356 |
info->pos = 0; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
357 |
info->parent = NULL; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
358 |
info->refcount = 1; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
359 |
info->destruct = destruct; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
360 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
361 |
memcpy(io, &__PHYSFS_memoryIoInterface, sizeof (*io)); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
362 |
io->opaque = info; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
363 |
return io; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
364 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
365 |
createMemoryIo_failed: |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
366 |
if (info != NULL) allocator.Free(info); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
367 |
if (io != NULL) allocator.Free(io); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
368 |
return NULL; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
369 |
} /* __PHYSFS_createMemoryIo */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
370 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
371 |
|
1123
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
372 |
/* PHYSFS_Io implementation for i/o to a PHYSFS_File... */ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
373 |
|
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
374 |
static PHYSFS_sint64 handleIo_read(PHYSFS_Io *io, void *buf, PHYSFS_uint64 len) |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
375 |
{ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
376 |
return PHYSFS_readBytes((PHYSFS_File *) io->opaque, buf, len); |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
377 |
} /* handleIo_read */ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
378 |
|
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
379 |
static PHYSFS_sint64 handleIo_write(PHYSFS_Io *io, const void *buffer, |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
380 |
PHYSFS_uint64 len) |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
381 |
{ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
382 |
return PHYSFS_writeBytes((PHYSFS_File *) io->opaque, buffer, len); |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
383 |
} /* handleIo_write */ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
384 |
|
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
385 |
static int handleIo_seek(PHYSFS_Io *io, PHYSFS_uint64 offset) |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
386 |
{ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
387 |
return PHYSFS_seek((PHYSFS_File *) io->opaque, offset); |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
388 |
} /* handleIo_seek */ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
389 |
|
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
390 |
static PHYSFS_sint64 handleIo_tell(PHYSFS_Io *io) |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
391 |
{ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
392 |
return PHYSFS_tell((PHYSFS_File *) io->opaque); |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
393 |
} /* handleIo_tell */ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
394 |
|
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
395 |
static PHYSFS_sint64 handleIo_length(PHYSFS_Io *io) |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
396 |
{ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
397 |
return PHYSFS_fileLength((PHYSFS_File *) io->opaque); |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
398 |
} /* handleIo_length */ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
399 |
|
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
400 |
static PHYSFS_Io *handleIo_duplicate(PHYSFS_Io *io) |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
401 |
{ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
402 |
/* |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
403 |
* There's no duplicate at the PHYSFS_File level, so we break the |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
404 |
* abstraction. We're allowed to: we're physfs.c! |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
405 |
*/ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
406 |
FileHandle *origfh = (FileHandle *) io->opaque; |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
407 |
FileHandle *newfh = (FileHandle *) allocator.Malloc(sizeof (FileHandle)); |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
408 |
PHYSFS_Io *retval = NULL; |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
409 |
|
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
410 |
GOTO_IF_MACRO(!newfh, PHYSFS_ERR_OUT_OF_MEMORY, handleIo_dupe_failed); |
1123
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
411 |
memset(newfh, '\0', sizeof (*newfh)); |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
412 |
|
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
413 |
retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io)); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
414 |
GOTO_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, handleIo_dupe_failed); |
1123
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
415 |
|
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
416 |
#if 0 /* we don't buffer the duplicate, at least not at the moment. */ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
417 |
if (origfh->buffer != NULL) |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
418 |
{ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
419 |
newfh->buffer = (PHYSFS_uint8 *) allocator.Malloc(origfh->bufsize); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
420 |
if (!newfh->buffer) |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
421 |
GOTO_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, handleIo_dupe_failed); |
1123
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
422 |
newfh->bufsize = origfh->bufsize; |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
423 |
} /* if */ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
424 |
#endif |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
425 |
|
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
426 |
newfh->io = origfh->io->duplicate(origfh->io); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
427 |
GOTO_IF_MACRO(!newfh->io, ERRPASS, handleIo_dupe_failed); |
1123
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
428 |
|
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
429 |
newfh->forReading = origfh->forReading; |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
430 |
newfh->dirHandle = origfh->dirHandle; |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
431 |
|
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
432 |
__PHYSFS_platformGrabMutex(stateLock); |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
433 |
if (newfh->forReading) |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
434 |
{ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
435 |
newfh->next = openReadList; |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
436 |
openReadList = newfh; |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
437 |
} /* if */ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
438 |
else |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
439 |
{ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
440 |
newfh->next = openWriteList; |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
441 |
openWriteList = newfh; |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
442 |
} /* else */ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
443 |
__PHYSFS_platformReleaseMutex(stateLock); |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
444 |
|
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
445 |
memcpy(retval, io, sizeof (PHYSFS_Io)); |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
446 |
retval->opaque = newfh; |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
447 |
return retval; |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
448 |
|
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
449 |
handleIo_dupe_failed: |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
450 |
if (newfh) |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
451 |
{ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
452 |
if (newfh->io != NULL) newfh->io->destroy(newfh->io); |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
453 |
if (newfh->buffer != NULL) allocator.Free(newfh->buffer); |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
454 |
allocator.Free(newfh); |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
455 |
} /* if */ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
456 |
|
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
457 |
return NULL; |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
458 |
} /* handleIo_duplicate */ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
459 |
|
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
460 |
static int handleIo_flush(PHYSFS_Io *io) |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
461 |
{ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
462 |
return PHYSFS_flush((PHYSFS_File *) io->opaque); |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
463 |
} /* handleIo_flush */ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
464 |
|
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
465 |
static void handleIo_destroy(PHYSFS_Io *io) |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
466 |
{ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
467 |
if (io->opaque != NULL) |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
468 |
PHYSFS_close((PHYSFS_File *) io->opaque); |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
469 |
allocator.Free(io); |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
470 |
} /* handleIo_destroy */ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
471 |
|
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
472 |
static const PHYSFS_Io __PHYSFS_handleIoInterface = |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
473 |
{ |
1280
bd174b99fa5b
Add binary compatibility to PHYSFS_Io.
Ryan C. Gordon <icculus@icculus.org>
parents:
1279
diff
changeset
|
474 |
CURRENT_PHYSFS_IO_API_VERSION, NULL, |
1123
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
475 |
handleIo_read, |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
476 |
handleIo_write, |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
477 |
handleIo_seek, |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
478 |
handleIo_tell, |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
479 |
handleIo_length, |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
480 |
handleIo_duplicate, |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
481 |
handleIo_flush, |
1280
bd174b99fa5b
Add binary compatibility to PHYSFS_Io.
Ryan C. Gordon <icculus@icculus.org>
parents:
1279
diff
changeset
|
482 |
handleIo_destroy |
1123
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
483 |
}; |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
484 |
|
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
485 |
static PHYSFS_Io *__PHYSFS_createHandleIo(PHYSFS_File *f) |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
486 |
{ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
487 |
PHYSFS_Io *io = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io)); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
488 |
BAIL_IF_MACRO(!io, PHYSFS_ERR_OUT_OF_MEMORY, NULL); |
1123
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
489 |
memcpy(io, &__PHYSFS_handleIoInterface, sizeof (*io)); |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
490 |
io->opaque = f; |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
491 |
return io; |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
492 |
} /* __PHYSFS_createHandleIo */ |
6fdff9f9758d
Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents:
1122
diff
changeset
|
493 |
|
1120
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
494 |
|
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
495 |
/* functions ... */ |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
496 |
|
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
497 |
typedef struct |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
498 |
{ |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
499 |
char **list; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
500 |
PHYSFS_uint32 size; |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
501 |
PHYSFS_ErrorCode errcode; |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
502 |
} EnumStringListCallbackData; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
503 |
|
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
504 |
static void enumStringListCallback(void *data, const char *str) |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
505 |
{ |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
506 |
void *ptr; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
507 |
char *newstr; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
508 |
EnumStringListCallbackData *pecd = (EnumStringListCallbackData *) data; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
509 |
|
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
510 |
if (pecd->errcode) |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
511 |
return; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
512 |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
513 |
ptr = allocator.Realloc(pecd->list, (pecd->size + 2) * sizeof (char *)); |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
514 |
newstr = (char *) allocator.Malloc(strlen(str) + 1); |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
515 |
if (ptr != NULL) |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
516 |
pecd->list = (char **) ptr; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
517 |
|
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
518 |
if ((ptr == NULL) || (newstr == NULL)) |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
519 |
{ |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
520 |
pecd->errcode = PHYSFS_ERR_OUT_OF_MEMORY; |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
521 |
pecd->list[pecd->size] = NULL; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
522 |
PHYSFS_freeList(pecd->list); |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
523 |
return; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
524 |
} /* if */ |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
525 |
|
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
526 |
strcpy(newstr, str); |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
527 |
pecd->list[pecd->size] = newstr; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
528 |
pecd->size++; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
529 |
} /* enumStringListCallback */ |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
530 |
|
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
531 |
|
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
532 |
static char **doEnumStringList(void (*func)(PHYSFS_StringCallback, void *)) |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
533 |
{ |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
534 |
EnumStringListCallbackData ecd; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
535 |
memset(&ecd, '\0', sizeof (ecd)); |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
536 |
ecd.list = (char **) allocator.Malloc(sizeof (char *)); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
537 |
BAIL_IF_MACRO(!ecd.list, PHYSFS_ERR_OUT_OF_MEMORY, NULL); |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
538 |
func(enumStringListCallback, &ecd); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
539 |
|
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
540 |
if (ecd.errcode) |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
541 |
{ |
1328
a5314f07614a
Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1327
diff
changeset
|
542 |
PHYSFS_setErrorCode(ecd.errcode); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
543 |
return NULL; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
544 |
} /* if */ |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
545 |
|
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
546 |
ecd.list[ecd.size] = NULL; |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
547 |
return ecd.list; |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
548 |
} /* doEnumStringList */ |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
549 |
|
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
550 |
|
1283
8bcc48d243df
Added Zip64 support to the .zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
1281
diff
changeset
|
551 |
static void __PHYSFS_bubble_sort(void *a, size_t lo, size_t hi, |
8bcc48d243df
Added Zip64 support to the .zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
1281
diff
changeset
|
552 |
int (*cmpfn)(void *, size_t, size_t), |
8bcc48d243df
Added Zip64 support to the .zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
1281
diff
changeset
|
553 |
void (*swapfn)(void *, size_t, size_t)) |
462
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
554 |
{ |
1283
8bcc48d243df
Added Zip64 support to the .zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
1281
diff
changeset
|
555 |
size_t i; |
462
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
556 |
int sorted; |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
557 |
|
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
558 |
do |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
559 |
{ |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
560 |
sorted = 1; |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
561 |
for (i = lo; i < hi; i++) |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
562 |
{ |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
563 |
if (cmpfn(a, i, i + 1) > 0) |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
564 |
{ |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
565 |
swapfn(a, i, i + 1); |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
566 |
sorted = 0; |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
567 |
} /* if */ |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
568 |
} /* for */ |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
569 |
} while (!sorted); |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
570 |
} /* __PHYSFS_bubble_sort */ |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
571 |
|
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
572 |
|
1283
8bcc48d243df
Added Zip64 support to the .zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
1281
diff
changeset
|
573 |
static void __PHYSFS_quick_sort(void *a, size_t lo, size_t hi, |
8bcc48d243df
Added Zip64 support to the .zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
1281
diff
changeset
|
574 |
int (*cmpfn)(void *, size_t, size_t), |
8bcc48d243df
Added Zip64 support to the .zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
1281
diff
changeset
|
575 |
void (*swapfn)(void *, size_t, size_t)) |
462
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
576 |
{ |
1283
8bcc48d243df
Added Zip64 support to the .zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
1281
diff
changeset
|
577 |
size_t i; |
8bcc48d243df
Added Zip64 support to the .zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
1281
diff
changeset
|
578 |
size_t j; |
8bcc48d243df
Added Zip64 support to the .zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
1281
diff
changeset
|
579 |
size_t v; |
462
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
580 |
|
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
581 |
if ((hi - lo) <= PHYSFS_QUICKSORT_THRESHOLD) |
462
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
582 |
__PHYSFS_bubble_sort(a, lo, hi, cmpfn, swapfn); |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
583 |
else |
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
584 |
{ |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
585 |
i = (hi + lo) / 2; |
462
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
586 |
|
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
587 |
if (cmpfn(a, lo, i) > 0) swapfn(a, lo, i); |
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
588 |
if (cmpfn(a, lo, hi) > 0) swapfn(a, lo, hi); |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
589 |
if (cmpfn(a, i, hi) > 0) swapfn(a, i, hi); |
462
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
590 |
|
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
591 |
j = hi - 1; |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
592 |
swapfn(a, i, j); |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
593 |
i = lo; |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
594 |
v = j; |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
595 |
while (1) |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
596 |
{ |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
597 |
while(cmpfn(a, ++i, v) < 0) { /* do nothing */ } |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
598 |
while(cmpfn(a, --j, v) > 0) { /* do nothing */ } |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
599 |
if (j < i) |
462
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
600 |
break; |
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
601 |
swapfn(a, i, j); |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
602 |
} /* while */ |
948
923323444178
Valgrind fix: avoid overlapping memcpy() in sorting routines (thanks, JLM!).
Ryan C. Gordon <icculus@icculus.org>
parents:
901
diff
changeset
|
603 |
if (i != (hi-1)) |
923323444178
Valgrind fix: avoid overlapping memcpy() in sorting routines (thanks, JLM!).
Ryan C. Gordon <icculus@icculus.org>
parents:
901
diff
changeset
|
604 |
swapfn(a, i, hi-1); |
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
605 |
__PHYSFS_quick_sort(a, lo, j, cmpfn, swapfn); |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
606 |
__PHYSFS_quick_sort(a, i+1, hi, cmpfn, swapfn); |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
607 |
} /* else */ |
462
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
608 |
} /* __PHYSFS_quick_sort */ |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
609 |
|
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
610 |
|
1283
8bcc48d243df
Added Zip64 support to the .zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
1281
diff
changeset
|
611 |
void __PHYSFS_sort(void *entries, size_t max, |
8bcc48d243df
Added Zip64 support to the .zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
1281
diff
changeset
|
612 |
int (*cmpfn)(void *, size_t, size_t), |
8bcc48d243df
Added Zip64 support to the .zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
1281
diff
changeset
|
613 |
void (*swapfn)(void *, size_t, size_t)) |
462
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
614 |
{ |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
615 |
/* |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
616 |
* Quicksort w/ Bubblesort fallback algorithm inspired by code from here: |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
617 |
* http://www.cs.ubc.ca/spider/harrison/Java/sorting-demo.html |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
618 |
*/ |
1286
662a7e180c48
Don't sort if there's nothing to do (prevents array underflow, too).
Ryan C. Gordon <icculus@icculus.org>
parents:
1283
diff
changeset
|
619 |
if (max > 0) |
662a7e180c48
Don't sort if there's nothing to do (prevents array underflow, too).
Ryan C. Gordon <icculus@icculus.org>
parents:
1283
diff
changeset
|
620 |
__PHYSFS_quick_sort(entries, 0, max - 1, cmpfn, swapfn); |
462
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
621 |
} /* __PHYSFS_sort */ |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
622 |
|
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
623 |
|
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
624 |
static ErrState *findErrorForCurrentThread(void) |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
625 |
{ |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
626 |
ErrState *i; |
1012
f254870dd7dd
Attempt to clean up the thread ID mess in platform_unix ...
Ryan C. Gordon <icculus@icculus.org>
parents:
986
diff
changeset
|
627 |
void *tid; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
628 |
|
272
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
629 |
if (errorLock != NULL) |
193
830c165052a5
Doesn't grab mutex in __PHYSFS_setError() if PHYSFS_init() hasn't been called.
Ryan C. Gordon <icculus@icculus.org>
parents:
186
diff
changeset
|
630 |
__PHYSFS_platformGrabMutex(errorLock); |
830c165052a5
Doesn't grab mutex in __PHYSFS_setError() if PHYSFS_init() hasn't been called.
Ryan C. Gordon <icculus@icculus.org>
parents:
186
diff
changeset
|
631 |
|
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
632 |
if (errorStates != NULL) |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
633 |
{ |
163
fc2b8ee5b420
Approved zeph's comments, fixed a few of my screwups.
Ryan C. Gordon <icculus@icculus.org>
parents:
160
diff
changeset
|
634 |
tid = __PHYSFS_platformGetThreadID(); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
635 |
|
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
636 |
for (i = errorStates; i != NULL; i = i->next) |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
637 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
638 |
if (i->tid == tid) |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
639 |
{ |
272
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
640 |
if (errorLock != NULL) |
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
641 |
__PHYSFS_platformReleaseMutex(errorLock); |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
642 |
return i; |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
643 |
} /* if */ |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
644 |
} /* for */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
645 |
} /* if */ |
193
830c165052a5
Doesn't grab mutex in __PHYSFS_setError() if PHYSFS_init() hasn't been called.
Ryan C. Gordon <icculus@icculus.org>
parents:
186
diff
changeset
|
646 |
|
272
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
647 |
if (errorLock != NULL) |
193
830c165052a5
Doesn't grab mutex in __PHYSFS_setError() if PHYSFS_init() hasn't been called.
Ryan C. Gordon <icculus@icculus.org>
parents:
186
diff
changeset
|
648 |
__PHYSFS_platformReleaseMutex(errorLock); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
649 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
650 |
return NULL; /* no error available. */ |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
651 |
} /* findErrorForCurrentThread */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
652 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
653 |
|
1327
998351d485d9
Cleaned out the "exists" nonsense in the stat() API.
Ryan C. Gordon <icculus@icculus.org>
parents:
1326
diff
changeset
|
654 |
/* this doesn't reset the error state. */ |
998351d485d9
Cleaned out the "exists" nonsense in the stat() API.
Ryan C. Gordon <icculus@icculus.org>
parents:
1326
diff
changeset
|
655 |
static inline PHYSFS_ErrorCode currentErrorCode(void) |
998351d485d9
Cleaned out the "exists" nonsense in the stat() API.
Ryan C. Gordon <icculus@icculus.org>
parents:
1326
diff
changeset
|
656 |
{ |
998351d485d9
Cleaned out the "exists" nonsense in the stat() API.
Ryan C. Gordon <icculus@icculus.org>
parents:
1326
diff
changeset
|
657 |
const ErrState *err = findErrorForCurrentThread(); |
998351d485d9
Cleaned out the "exists" nonsense in the stat() API.
Ryan C. Gordon <icculus@icculus.org>
parents:
1326
diff
changeset
|
658 |
return err ? err->code : PHYSFS_ERR_OK; |
998351d485d9
Cleaned out the "exists" nonsense in the stat() API.
Ryan C. Gordon <icculus@icculus.org>
parents:
1326
diff
changeset
|
659 |
} /* currentErrorCode */ |
998351d485d9
Cleaned out the "exists" nonsense in the stat() API.
Ryan C. Gordon <icculus@icculus.org>
parents:
1326
diff
changeset
|
660 |
|
998351d485d9
Cleaned out the "exists" nonsense in the stat() API.
Ryan C. Gordon <icculus@icculus.org>
parents:
1326
diff
changeset
|
661 |
|
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
662 |
PHYSFS_ErrorCode PHYSFS_getLastErrorCode(void) |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
663 |
{ |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
664 |
ErrState *err = findErrorForCurrentThread(); |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
665 |
const PHYSFS_ErrorCode retval = (err) ? err->code : PHYSFS_ERR_OK; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
666 |
if (err) |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
667 |
err->code = PHYSFS_ERR_OK; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
668 |
return retval; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
669 |
} /* PHYSFS_getLastErrorCode */ |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
670 |
|
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
671 |
|
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
672 |
PHYSFS_DECL const char *PHYSFS_getErrorByCode(PHYSFS_ErrorCode code) |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
673 |
{ |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
674 |
switch (code) |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
675 |
{ |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
676 |
case PHYSFS_ERR_OK: return "no error"; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
677 |
case PHYSFS_ERR_OTHER_ERROR: return "unknown error"; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
678 |
case PHYSFS_ERR_OUT_OF_MEMORY: return "out of memory"; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
679 |
case PHYSFS_ERR_NOT_INITIALIZED: return "not initialized"; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
680 |
case PHYSFS_ERR_IS_INITIALIZED: return "already initialized"; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
681 |
case PHYSFS_ERR_ARGV0_IS_NULL: return "argv[0] is NULL"; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
682 |
case PHYSFS_ERR_UNSUPPORTED: return "unsupported"; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
683 |
case PHYSFS_ERR_PAST_EOF: return "past end of file"; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
684 |
case PHYSFS_ERR_FILES_STILL_OPEN: return "files still open"; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
685 |
case PHYSFS_ERR_INVALID_ARGUMENT: return "invalid argument"; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
686 |
case PHYSFS_ERR_NOT_MOUNTED: return "not mounted"; |
1322
5476917b8ddf
Allow application-supplied archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1315
diff
changeset
|
687 |
case PHYSFS_ERR_NOT_FOUND: return "not found"; |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
688 |
case PHYSFS_ERR_SYMLINK_FORBIDDEN: return "symlinks are forbidden"; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
689 |
case PHYSFS_ERR_NO_WRITE_DIR: return "write directory is not set"; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
690 |
case PHYSFS_ERR_OPEN_FOR_READING: return "file open for reading"; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
691 |
case PHYSFS_ERR_OPEN_FOR_WRITING: return "file open for writing"; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
692 |
case PHYSFS_ERR_NOT_A_FILE: return "not a file"; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
693 |
case PHYSFS_ERR_READ_ONLY: return "read-only filesystem"; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
694 |
case PHYSFS_ERR_CORRUPT: return "corrupted"; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
695 |
case PHYSFS_ERR_SYMLINK_LOOP: return "infinite symbolic link loop"; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
696 |
case PHYSFS_ERR_IO: return "i/o error"; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
697 |
case PHYSFS_ERR_PERMISSION: return "permission denied"; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
698 |
case PHYSFS_ERR_NO_SPACE: return "no space available for writing"; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
699 |
case PHYSFS_ERR_BAD_FILENAME: return "filename is illegal or insecure"; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
700 |
case PHYSFS_ERR_BUSY: return "tried to modify a file the OS needs"; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
701 |
case PHYSFS_ERR_DIR_NOT_EMPTY: return "directory isn't empty"; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
702 |
case PHYSFS_ERR_OS_ERROR: return "OS reported an error"; |
1322
5476917b8ddf
Allow application-supplied archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1315
diff
changeset
|
703 |
case PHYSFS_ERR_DUPLICATE: return "duplicate resource"; |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
704 |
} /* switch */ |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
705 |
|
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
706 |
return NULL; /* don't know this error code. */ |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
707 |
} /* PHYSFS_getErrorByCode */ |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
708 |
|
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
709 |
|
1328
a5314f07614a
Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1327
diff
changeset
|
710 |
void PHYSFS_setErrorCode(PHYSFS_ErrorCode errcode) |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
711 |
{ |
1328
a5314f07614a
Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1327
diff
changeset
|
712 |
ErrState *err; |
a5314f07614a
Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1327
diff
changeset
|
713 |
|
a5314f07614a
Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1327
diff
changeset
|
714 |
if (!errcode) |
a5314f07614a
Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1327
diff
changeset
|
715 |
return; |
a5314f07614a
Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1327
diff
changeset
|
716 |
|
a5314f07614a
Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1327
diff
changeset
|
717 |
err = findErrorForCurrentThread(); |
a5314f07614a
Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1327
diff
changeset
|
718 |
if (err == NULL) |
a5314f07614a
Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1327
diff
changeset
|
719 |
{ |
a5314f07614a
Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1327
diff
changeset
|
720 |
err = (ErrState *) allocator.Malloc(sizeof (ErrState)); |
a5314f07614a
Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1327
diff
changeset
|
721 |
if (err == NULL) |
a5314f07614a
Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1327
diff
changeset
|
722 |
return; /* uhh...? */ |
a5314f07614a
Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1327
diff
changeset
|
723 |
|
a5314f07614a
Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1327
diff
changeset
|
724 |
memset(err, '\0', sizeof (ErrState)); |
a5314f07614a
Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1327
diff
changeset
|
725 |
err->tid = __PHYSFS_platformGetThreadID(); |
a5314f07614a
Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1327
diff
changeset
|
726 |
|
a5314f07614a
Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1327
diff
changeset
|
727 |
if (errorLock != NULL) |
a5314f07614a
Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1327
diff
changeset
|
728 |
__PHYSFS_platformGrabMutex(errorLock); |
a5314f07614a
Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1327
diff
changeset
|
729 |
|
a5314f07614a
Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1327
diff
changeset
|
730 |
err->next = errorStates; |
a5314f07614a
Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1327
diff
changeset
|
731 |
errorStates = err; |
a5314f07614a
Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1327
diff
changeset
|
732 |
|
a5314f07614a
Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1327
diff
changeset
|
733 |
if (errorLock != NULL) |
a5314f07614a
Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1327
diff
changeset
|
734 |
__PHYSFS_platformReleaseMutex(errorLock); |
a5314f07614a
Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1327
diff
changeset
|
735 |
} /* if */ |
a5314f07614a
Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1327
diff
changeset
|
736 |
|
a5314f07614a
Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1327
diff
changeset
|
737 |
err->code = errcode; |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
738 |
} /* PHYSFS_setErrorCode */ |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
739 |
|
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
740 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
741 |
const char *PHYSFS_getLastError(void) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
742 |
{ |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
743 |
const PHYSFS_ErrorCode err = PHYSFS_getLastErrorCode(); |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
744 |
return (err) ? PHYSFS_getErrorByCode(err) : NULL; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
745 |
} /* PHYSFS_getLastError */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
746 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
747 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
748 |
/* MAKE SURE that errorLock is held before calling this! */ |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
749 |
static void freeErrorStates(void) |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
750 |
{ |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
751 |
ErrState *i; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
752 |
ErrState *next; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
753 |
|
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
754 |
for (i = errorStates; i != NULL; i = next) |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
755 |
{ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
756 |
next = i->next; |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
757 |
allocator.Free(i); |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
758 |
} /* for */ |
272
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
759 |
|
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
760 |
errorStates = NULL; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
761 |
} /* freeErrorStates */ |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
762 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
763 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
764 |
void PHYSFS_getLinkedVersion(PHYSFS_Version *ver) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
765 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
766 |
if (ver != NULL) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
767 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
768 |
ver->major = PHYSFS_VER_MAJOR; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
769 |
ver->minor = PHYSFS_VER_MINOR; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
770 |
ver->patch = PHYSFS_VER_PATCH; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
771 |
} /* if */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
772 |
} /* PHYSFS_getLinkedVersion */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
773 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
774 |
|
398
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
775 |
static const char *find_filename_extension(const char *fname) |
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
776 |
{ |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
777 |
const char *retval = NULL; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
778 |
if (fname != NULL) |
398
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
779 |
{ |
1135
3b71a0c08665
Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
1130
diff
changeset
|
780 |
const char *p = strchr(fname, '.'); |
3b71a0c08665
Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
1130
diff
changeset
|
781 |
retval = p; |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
782 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
783 |
while (p != NULL) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
784 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
785 |
p = strchr(p + 1, '.'); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
786 |
if (p != NULL) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
787 |
retval = p; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
788 |
} /* while */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
789 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
790 |
if (retval != NULL) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
791 |
retval++; /* skip '.' */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
792 |
} /* if */ |
398
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
793 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
794 |
return retval; |
398
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
795 |
} /* find_filename_extension */ |
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
796 |
|
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
797 |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
798 |
static DirHandle *tryOpenDir(PHYSFS_Io *io, const PHYSFS_Archiver *funcs, |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
799 |
const char *d, int forWriting) |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
800 |
{ |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
801 |
DirHandle *retval = NULL; |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
802 |
void *opaque = NULL; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
803 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
804 |
if (io != NULL) |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
805 |
BAIL_IF_MACRO(!io->seek(io, 0), ERRPASS, NULL); |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
806 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
807 |
opaque = funcs->openArchive(io, d, forWriting); |
1113
2136d64bd1ad
Removed PHYSFS_Archiver's isArchive() method.
Ryan C. Gordon <icculus@icculus.org>
parents:
1112
diff
changeset
|
808 |
if (opaque != NULL) |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
809 |
{ |
1113
2136d64bd1ad
Removed PHYSFS_Archiver's isArchive() method.
Ryan C. Gordon <icculus@icculus.org>
parents:
1112
diff
changeset
|
810 |
retval = (DirHandle *) allocator.Malloc(sizeof (DirHandle)); |
2136d64bd1ad
Removed PHYSFS_Archiver's isArchive() method.
Ryan C. Gordon <icculus@icculus.org>
parents:
1112
diff
changeset
|
811 |
if (retval == NULL) |
1270
f8d3f58561b1
Renamed PHYSFS_Archiver::dirClose() to PHYSFS_Archiver::closeArchive().
Ryan C. Gordon <icculus@icculus.org>
parents:
1268
diff
changeset
|
812 |
funcs->closeArchive(opaque); |
1113
2136d64bd1ad
Removed PHYSFS_Archiver's isArchive() method.
Ryan C. Gordon <icculus@icculus.org>
parents:
1112
diff
changeset
|
813 |
else |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
814 |
{ |
1113
2136d64bd1ad
Removed PHYSFS_Archiver's isArchive() method.
Ryan C. Gordon <icculus@icculus.org>
parents:
1112
diff
changeset
|
815 |
memset(retval, '\0', sizeof (DirHandle)); |
2136d64bd1ad
Removed PHYSFS_Archiver's isArchive() method.
Ryan C. Gordon <icculus@icculus.org>
parents:
1112
diff
changeset
|
816 |
retval->mountPoint = NULL; |
2136d64bd1ad
Removed PHYSFS_Archiver's isArchive() method.
Ryan C. Gordon <icculus@icculus.org>
parents:
1112
diff
changeset
|
817 |
retval->funcs = funcs; |
2136d64bd1ad
Removed PHYSFS_Archiver's isArchive() method.
Ryan C. Gordon <icculus@icculus.org>
parents:
1112
diff
changeset
|
818 |
retval->opaque = opaque; |
2136d64bd1ad
Removed PHYSFS_Archiver's isArchive() method.
Ryan C. Gordon <icculus@icculus.org>
parents:
1112
diff
changeset
|
819 |
} /* else */ |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
820 |
} /* if */ |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
821 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
822 |
return retval; |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
823 |
} /* tryOpenDir */ |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
824 |
|
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
825 |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
826 |
static DirHandle *openDirectory(PHYSFS_Io *io, const char *d, int forWriting) |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
827 |
{ |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
828 |
DirHandle *retval = NULL; |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
829 |
const PHYSFS_Archiver **i; |
398
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
830 |
const char *ext; |
1353
5ef6aca28421
Fixed resource leak when failing to mount a file that isn't an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
1347
diff
changeset
|
831 |
int created_io = 0; |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
832 |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
833 |
assert((io != NULL) || (d != NULL)); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
834 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
835 |
if (io == NULL) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
836 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
837 |
/* DIR gets first shot (unlike the rest, it doesn't deal with files). */ |
1332
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
838 |
extern const PHYSFS_Archiver __PHYSFS_Archiver_DIR; |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
839 |
retval = tryOpenDir(io, &__PHYSFS_Archiver_DIR, d, forWriting); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
840 |
if (retval != NULL) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
841 |
return retval; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
842 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
843 |
io = __PHYSFS_createNativeIo(d, forWriting ? 'w' : 'r'); |
1239 | 844 |
BAIL_IF_MACRO(!io, ERRPASS, 0); |
1353
5ef6aca28421
Fixed resource leak when failing to mount a file that isn't an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
1347
diff
changeset
|
845 |
created_io = 1; |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
846 |
} /* if */ |
1113
2136d64bd1ad
Removed PHYSFS_Archiver's isArchive() method.
Ryan C. Gordon <icculus@icculus.org>
parents:
1112
diff
changeset
|
847 |
|
398
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
848 |
ext = find_filename_extension(d); |
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
849 |
if (ext != NULL) |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
850 |
{ |
398
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
851 |
/* Look for archivers with matching file extensions first... */ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
852 |
for (i = archivers; (*i != NULL) && (retval == NULL); i++) |
398
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
853 |
{ |
1322
5476917b8ddf
Allow application-supplied archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1315
diff
changeset
|
854 |
if (__PHYSFS_utf8stricmp(ext, (*i)->info.extension) == 0) |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
855 |
retval = tryOpenDir(io, *i, d, forWriting); |
398
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
856 |
} /* for */ |
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
857 |
|
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
858 |
/* failing an exact file extension match, try all the others... */ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
859 |
for (i = archivers; (*i != NULL) && (retval == NULL); i++) |
398
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
860 |
{ |
1322
5476917b8ddf
Allow application-supplied archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1315
diff
changeset
|
861 |
if (__PHYSFS_utf8stricmp(ext, (*i)->info.extension) != 0) |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
862 |
retval = tryOpenDir(io, *i, d, forWriting); |
398
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
863 |
} /* for */ |
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
864 |
} /* if */ |
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
865 |
|
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
866 |
else /* no extension? Try them all. */ |
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
867 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
868 |
for (i = archivers; (*i != NULL) && (retval == NULL); i++) |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
869 |
retval = tryOpenDir(io, *i, d, forWriting); |
398
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
870 |
} /* else */ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
871 |
|
1353
5ef6aca28421
Fixed resource leak when failing to mount a file that isn't an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
1347
diff
changeset
|
872 |
if ((!retval) && (created_io)) |
5ef6aca28421
Fixed resource leak when failing to mount a file that isn't an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
1347
diff
changeset
|
873 |
io->destroy(io); |
5ef6aca28421
Fixed resource leak when failing to mount a file that isn't an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
1347
diff
changeset
|
874 |
|
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
875 |
BAIL_IF_MACRO(!retval, PHYSFS_ERR_UNSUPPORTED, NULL); |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
876 |
return retval; |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
877 |
} /* openDirectory */ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
878 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
879 |
|
683
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
880 |
/* |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
881 |
* Make a platform-independent path string sane. Doesn't actually check the |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
882 |
* file hierarchy, it just cleans up the string. |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
883 |
* (dst) must be a buffer at least as big as (src), as this is where the |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
884 |
* cleaned up string is deposited. |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
885 |
* If there are illegal bits in the path (".." entries, etc) then we |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
886 |
* return zero and (dst) is undefined. Non-zero if the path was sanitized. |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
887 |
*/ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
888 |
static int sanitizePlatformIndependentPath(const char *src, char *dst) |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
889 |
{ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
890 |
char *prev; |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
891 |
char ch; |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
892 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
893 |
while (*src == '/') /* skip initial '/' chars... */ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
894 |
src++; |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
895 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
896 |
prev = dst; |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
897 |
do |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
898 |
{ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
899 |
ch = *(src++); |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
900 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
901 |
if ((ch == ':') || (ch == '\\')) /* illegal chars in a physfs path. */ |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
902 |
BAIL_MACRO(PHYSFS_ERR_BAD_FILENAME, 0); |
683
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
903 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
904 |
if (ch == '/') /* path separator. */ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
905 |
{ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
906 |
*dst = '\0'; /* "." and ".." are illegal pathnames. */ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
907 |
if ((strcmp(prev, ".") == 0) || (strcmp(prev, "..") == 0)) |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
908 |
BAIL_MACRO(PHYSFS_ERR_BAD_FILENAME, 0); |
683
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
909 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
910 |
while (*src == '/') /* chop out doubles... */ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
911 |
src++; |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
912 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
913 |
if (*src == '\0') /* ends with a pathsep? */ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
914 |
break; /* we're done, don't add final pathsep to dst. */ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
915 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
916 |
prev = dst + 1; |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
917 |
} /* if */ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
918 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
919 |
*(dst++) = ch; |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
920 |
} while (ch != '\0'); |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
921 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
922 |
return 1; |
683
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
923 |
} /* sanitizePlatformIndependentPath */ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
924 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
925 |
|
687
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
926 |
/* |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
927 |
* Figure out if (fname) is part of (h)'s mountpoint. (fname) must be an |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
928 |
* output from sanitizePlatformIndependentPath(), so that it is in a known |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
929 |
* state. |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
930 |
* |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
931 |
* This only finds legitimate segments of a mountpoint. If the mountpoint is |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
932 |
* "/a/b/c" and (fname) is "/a/b/c", "/", or "/a/b/c/d", then the results are |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
933 |
* all zero. "/a/b" will succeed, though. |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
934 |
*/ |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
935 |
static int partOfMountPoint(DirHandle *h, char *fname) |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
936 |
{ |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
937 |
/* !!! FIXME: This code feels gross. */ |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
938 |
int rc; |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
939 |
size_t len, mntpntlen; |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
940 |
|
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
941 |
if (h->mountPoint == NULL) |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
942 |
return 0; |
687
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
943 |
else if (*fname == '\0') |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
944 |
return 1; |
687
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
945 |
|
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
946 |
len = strlen(fname); |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
947 |
mntpntlen = strlen(h->mountPoint); |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
948 |
if (len > mntpntlen) /* can't be a subset of mountpoint. */ |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
949 |
return 0; |
687
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
950 |
|
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
951 |
/* if true, must be not a match or a complete match, but not a subset. */ |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
952 |
if ((len + 1) == mntpntlen) |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
953 |
return 0; |
687
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
954 |
|
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
955 |
rc = strncmp(fname, h->mountPoint, len); /* !!! FIXME: case insensitive? */ |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
956 |
if (rc != 0) |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
957 |
return 0; /* not a match. */ |
687
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
958 |
|
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
959 |
/* make sure /a/b matches /a/b/ and not /a/bc ... */ |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
960 |
return h->mountPoint[len] == '/'; |
687
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
961 |
} /* partOfMountPoint */ |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
962 |
|
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
963 |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
964 |
static DirHandle *createDirHandle(PHYSFS_Io *io, const char *newDir, |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
965 |
const char *mountPoint, int forWriting) |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
966 |
{ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
967 |
DirHandle *dirHandle = NULL; |
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
968 |
char *tmpmntpnt = NULL; |
683
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
969 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
970 |
if (mountPoint != NULL) |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
971 |
{ |
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
972 |
const size_t len = strlen(mountPoint) + 1; |
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
973 |
tmpmntpnt = (char *) __PHYSFS_smallAlloc(len); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
974 |
GOTO_IF_MACRO(!tmpmntpnt, PHYSFS_ERR_OUT_OF_MEMORY, badDirHandle); |
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
975 |
if (!sanitizePlatformIndependentPath(mountPoint, tmpmntpnt)) |
683
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
976 |
goto badDirHandle; |
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
977 |
mountPoint = tmpmntpnt; /* sanitized version. */ |
683
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
978 |
} /* if */ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
979 |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
980 |
dirHandle = openDirectory(io, newDir, forWriting); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
981 |
GOTO_IF_MACRO(!dirHandle, ERRPASS, badDirHandle); |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
982 |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
983 |
if (newDir == NULL) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
984 |
dirHandle->dirName = NULL; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
985 |
else |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
986 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
987 |
dirHandle->dirName = (char *) allocator.Malloc(strlen(newDir) + 1); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
988 |
if (!dirHandle->dirName) |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
989 |
GOTO_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, badDirHandle); |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
990 |
strcpy(dirHandle->dirName, newDir); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
991 |
} /* else */ |
679
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
992 |
|
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
993 |
if ((mountPoint != NULL) && (*mountPoint != '\0')) |
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
994 |
{ |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
995 |
dirHandle->mountPoint = (char *)allocator.Malloc(strlen(mountPoint)+2); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
996 |
if (!dirHandle->mountPoint) |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
997 |
GOTO_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, badDirHandle); |
679
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
998 |
strcpy(dirHandle->mountPoint, mountPoint); |
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
999 |
strcat(dirHandle->mountPoint, "/"); |
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
1000 |
} /* if */ |
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
1001 |
|
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
1002 |
__PHYSFS_smallFree(tmpmntpnt); |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
1003 |
return dirHandle; |
679
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
1004 |
|
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
1005 |
badDirHandle: |
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
1006 |
if (dirHandle != NULL) |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1007 |
{ |
1270
f8d3f58561b1
Renamed PHYSFS_Archiver::dirClose() to PHYSFS_Archiver::closeArchive().
Ryan C. Gordon <icculus@icculus.org>
parents:
1268
diff
changeset
|
1008 |
dirHandle->funcs->closeArchive(dirHandle->opaque); |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
1009 |
allocator.Free(dirHandle->dirName); |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
1010 |
allocator.Free(dirHandle->mountPoint); |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
1011 |
allocator.Free(dirHandle); |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1012 |
} /* if */ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1013 |
|
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
1014 |
__PHYSFS_smallFree(tmpmntpnt); |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
1015 |
return NULL; |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
1016 |
} /* createDirHandle */ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1017 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1018 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1019 |
/* MAKE SURE you've got the stateLock held before calling this! */ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
1020 |
static int freeDirHandle(DirHandle *dh, FileHandle *openList) |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1021 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
1022 |
FileHandle *i; |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1023 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
1024 |
if (dh == NULL) |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
1025 |
return 1; |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1026 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1027 |
for (i = openList; i != NULL; i = i->next) |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
1028 |
BAIL_IF_MACRO(i->dirHandle == dh, PHYSFS_ERR_FILES_STILL_OPEN, 0); |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
758
diff
changeset
|
1029 |
|
1270
f8d3f58561b1
Renamed PHYSFS_Archiver::dirClose() to PHYSFS_Archiver::closeArchive().
Ryan C. Gordon <icculus@icculus.org>
parents:
1268
diff
changeset
|
1030 |
dh->funcs->closeArchive(dh->opaque); |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
1031 |
allocator.Free(dh->dirName); |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
1032 |
allocator.Free(dh->mountPoint); |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
1033 |
allocator.Free(dh); |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
1034 |
return 1; |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
1035 |
} /* freeDirHandle */ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1036 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1037 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1038 |
static char *calculateBaseDir(const char *argv0) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1039 |
{ |
1225
671d4ea47c13
Make __PHYSFS_platformDirSeparator into a single char.
Ryan C. Gordon <icculus@icculus.org>
parents:
1224
diff
changeset
|
1040 |
const char dirsep = __PHYSFS_platformDirSeparator; |
848
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
1041 |
char *retval = NULL; |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
1042 |
char *ptr = NULL; |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
1043 |
|
848
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
1044 |
/* Give the platform layer first shot at this. */ |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
1045 |
retval = __PHYSFS_platformCalcBaseDir(argv0); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
1046 |
if (retval != NULL) |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
1047 |
return retval; |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
1048 |
|
848
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
1049 |
/* We need argv0 to go on. */ |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
1050 |
BAIL_IF_MACRO(argv0 == NULL, PHYSFS_ERR_ARGV0_IS_NULL, NULL); |
839
cbb9d603ca71
PHYSFS_init() should fail if argv0 is NULL and we can't do without it.
Ryan C. Gordon <icculus@icculus.org>
parents:
828
diff
changeset
|
1051 |
|
1225
671d4ea47c13
Make __PHYSFS_platformDirSeparator into a single char.
Ryan C. Gordon <icculus@icculus.org>
parents:
1224
diff
changeset
|
1052 |
ptr = strrchr(argv0, dirsep); |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
1053 |
if (ptr != NULL) |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
1054 |
{ |
1264
03715ba4603d
Make sure base dir always has a dirsep at the end of it.
Ryan C. Gordon <icculus@icculus.org>
parents:
1258
diff
changeset
|
1055 |
const size_t size = ((size_t) (ptr - argv0)) + 1; |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
1056 |
retval = (char *) allocator.Malloc(size + 1); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
1057 |
BAIL_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL); |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
1058 |
memcpy(retval, argv0, size); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
1059 |
retval[size] = '\0'; |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
1060 |
return retval; |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
1061 |
} /* if */ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
1062 |
|
848
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
1063 |
/* argv0 wasn't helpful. */ |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1239
diff
changeset
|
1064 |
BAIL_MACRO(PHYSFS_ERR_INVALID_ARGUMENT, NULL); |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1065 |
} /* calculateBaseDir */ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1066 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1067 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1068 |
static int initializeMutexes(void) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1069 |
{ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1070 |
errorLock = __PHYSFS_platformCreateMutex(); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1071 |
if (errorLock == NULL) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1072 |
goto initializeMutexes_failed; |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1073 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1074 |
stateLock = __PHYSFS_platformCreateMutex(); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1075 |
if (stateLock == NULL) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1076 |
goto initializeMutexes_failed; |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1077 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
1078 |
return 1; /* success. */ |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1079 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1080 |
initializeMutexes_failed: |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1081 |
if (errorLock != NULL) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1082 |
__PHYSFS_platformDestroyMutex(errorLock); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1083 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1084 |
if (stateLock != NULL) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1085 |
__PHYSFS_platformDestroyMutex(stateLock); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1086 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1087 |
errorLock = stateLock = NULL; |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
1088 |
return 0; /* failed. */ |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1089 |
} /* initializeMutexes */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1090 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1091 |
|
1322
5476917b8ddf
Allow application-supplied archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1315
diff
changeset
|
1092 |
static int doRegisterArchiver(const PHYSFS_Archiver *_archiver); |
644
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
634
diff
changeset
|
1093 |
|
1277
f6996bfaec19
Made archiver list dynamic, in preparation for external archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1270
diff
changeset
|
1094 |
static int initStaticArchivers(void) |
f6996bfaec19
Made archiver list dynamic, in preparation for external archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1270
diff
changeset
|
1095 |
{ |
1332
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1096 |
#define REGISTER_STATIC_ARCHIVER(arc) { \ |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1097 |
extern const PHYSFS_Archiver __PHYSFS_Archiver_##arc; \ |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1098 |
if (!doRegisterArchiver(&__PHYSFS_Archiver_##arc)) { \ |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1099 |
return 0; \ |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1100 |
} \ |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1101 |
} |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1102 |
|
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1103 |
#if PHYSFS_SUPPORTS_ZIP |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1104 |
REGISTER_STATIC_ARCHIVER(ZIP); |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1105 |
#endif |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1106 |
#if PHYSFS_SUPPORTS_7Z |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1107 |
REGISTER_STATIC_ARCHIVER(LZMA); |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1108 |
#endif |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1109 |
#if PHYSFS_SUPPORTS_GRP |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1110 |
REGISTER_STATIC_ARCHIVER(GRP); |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1111 |
#endif |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1112 |
#if PHYSFS_SUPPORTS_QPAK |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1113 |
REGISTER_STATIC_ARCHIVER(QPAK); |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1114 |
#endif |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1115 |
#if PHYSFS_SUPPORTS_HOG |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1116 |
REGISTER_STATIC_ARCHIVER(HOG); |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1117 |
#endif |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1118 |
#if PHYSFS_SUPPORTS_MVL |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1119 |
REGISTER_STATIC_ARCHIVER(MVL); |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1120 |
#endif |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1121 |
#if PHYSFS_SUPPORTS_WAD |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1122 |
REGISTER_STATIC_ARCHIVER(WAD); |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1123 |
#endif |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1124 |
#if PHYSFS_SUPPORTS_SLB |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1125 |
REGISTER_STATIC_ARCHIVER(SLB); |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1126 |
#endif |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1127 |
#if PHYSFS_SUPPORTS_ISO9660 |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1128 |
REGISTER_STATIC_ARCHIVER(ISO9660); |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1129 |
#endif |
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1130 |
|
e0dbcd5e50b9
Get rid of array of static archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1329
diff
changeset
|
1131 |
#undef REGISTER_STATIC_ARCHIVER |
1277
f6996bfaec19
Made archiver list dynamic, in preparation for external archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1270
diff
changeset
|
1132 |
|
f6996bfaec19
Made archiver list dynamic, in preparation for external archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1270
diff
changeset
|
1133 |
return 1; |
f6996bfaec19
Made archiver list dynamic, in preparation for external archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1270
diff
changeset
|
1134 |
} /* initStaticArchivers */ |
f6996bfaec19
Made archiver list dynamic, in preparation for external archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1270
diff
changeset
|
1135 |
|
f6996bfaec19
Made archiver list dynamic, in preparation for external archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1270
diff
changeset
|
1136 |
|
1322
5476917b8ddf
Allow application-supplied archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1315
diff
changeset
|
1137 |
static void setDefaultAllocator(void); |
1278
570b476e0230
Better cleanup if PHYSFS_init() fails halfway through.
Ryan C. Gordon <icculus@icculus.org>
parents:
1277
diff
changeset
|
1138 |
static int doDeinit(void); |