author | Ryan C. Gordon <icculus@icculus.org> |
Sun, 05 Nov 2006 11:10:14 +0000 | |
changeset 785 | 1ea0f6549eb2 |
parent 763 | efadd9cdb6a4 |
child 808 | 7656f86a9a2c |
permissions | -rw-r--r-- |
404 | 1 |
/* |
2 |
* OS/2 support routines for PhysicsFS. |
|
3 |
* |
|
4 |
* Please see the file LICENSE in the source's root directory. |
|
5 |
* |
|
6 |
* This file written by Ryan C. Gordon. |
|
7 |
*/ |
|
8 |
||
9 |
#if HAVE_CONFIG_H |
|
10 |
# include <config.h> |
|
11 |
#endif |
|
12 |
||
13 |
#if (defined OS2) |
|
14 |
||
15 |
#define INCL_DOSSEMAPHORES |
|
16 |
#define INCL_DOSDATETIME |
|
17 |
#define INCL_DOSFILEMGR |
|
18 |
#define INCL_DOSMODULEMGR |
|
19 |
#define INCL_DOSERRORS |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
20 |
#define INCL_DOSPROCESS |
404 | 21 |
#define INCL_DOSDEVICES |
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
22 |
#define INCL_DOSDEVIOCTL |
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
23 |
#define INCL_DOSMISC |
404 | 24 |
#include <os2.h> |
25 |
||
599
44af228dd59a
Patched to compile on OS/2.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
26 |
#include <stdio.h> |
404 | 27 |
#include <stdlib.h> |
28 |
#include <errno.h> |
|
29 |
#include <string.h> |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
30 |
#include <time.h> |
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
31 |
#include <ctype.h> |
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
32 |
|
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
33 |
#define __PHYSICSFS_INTERNAL__ |
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
34 |
#include "physfs_internal.h" |
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
35 |
|
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
36 |
const char *__PHYSFS_platformDirSeparator = "\\"; |
404 | 37 |
|
38 |
||
427
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
39 |
static const char *get_os2_error_string(APIRET rc) |
404 | 40 |
{ |
427
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
41 |
switch (rc) |
404 | 42 |
{ |
427
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
43 |
case NO_ERROR: return(NULL); /* not an error. */ |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
44 |
case ERROR_INTERRUPT: return(NULL); /* not an error. */ |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
45 |
case ERROR_TIMEOUT: return(NULL); /* not an error. */ |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
46 |
case ERROR_NOT_ENOUGH_MEMORY: return(ERR_OUT_OF_MEMORY); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
47 |
case ERROR_FILE_NOT_FOUND: return(ERR_NO_SUCH_FILE); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
48 |
case ERROR_PATH_NOT_FOUND: return(ERR_NO_SUCH_PATH); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
49 |
case ERROR_ACCESS_DENIED: return(ERR_ACCESS_DENIED); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
50 |
case ERROR_NOT_DOS_DISK: return(ERR_NOT_A_DOS_DISK); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
51 |
case ERROR_SHARING_VIOLATION: return(ERR_SHARING_VIOLATION); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
52 |
case ERROR_CANNOT_MAKE: return(ERR_CANNOT_MAKE); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
53 |
case ERROR_DEVICE_IN_USE: return(ERR_DEV_IN_USE); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
54 |
case ERROR_OPEN_FAILED: return(ERR_OPEN_FAILED); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
55 |
case ERROR_DISK_FULL: return(ERR_DISK_FULL); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
56 |
case ERROR_PIPE_BUSY: return(ERR_PIPE_BUSY); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
57 |
case ERROR_SHARING_BUFFER_EXCEEDED: return(ERR_SHARING_BUF_EXCEEDED); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
58 |
case ERROR_FILENAME_EXCED_RANGE: return(ERR_BAD_FILENAME); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
59 |
case ERROR_META_EXPANSION_TOO_LONG: return(ERR_BAD_FILENAME); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
60 |
case ERROR_TOO_MANY_HANDLES: return(ERR_TOO_MANY_HANDLES); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
61 |
case ERROR_TOO_MANY_OPEN_FILES: return(ERR_TOO_MANY_HANDLES); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
62 |
case ERROR_NO_MORE_SEARCH_HANDLES: return(ERR_TOO_MANY_HANDLES); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
63 |
case ERROR_SEEK_ON_DEVICE: return(ERR_SEEK_ERROR); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
64 |
case ERROR_NEGATIVE_SEEK: return(ERR_SEEK_OUT_OF_RANGE); |
599
44af228dd59a
Patched to compile on OS/2.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
65 |
/*!!! FIXME: Where did this go? case ERROR_DEL_CURRENT_DIRECTORY: return(ERR_DEL_CWD);*/ |
427
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
66 |
case ERROR_WRITE_PROTECT: return(ERR_WRITE_PROTECT_ERROR); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
67 |
case ERROR_WRITE_FAULT: return(ERR_WRITE_FAULT); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
68 |
case ERROR_LOCK_VIOLATION: return(ERR_LOCK_VIOLATION); |
599
44af228dd59a
Patched to compile on OS/2.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
69 |
case ERROR_GEN_FAILURE: return(ERR_GEN_FAILURE); |
427
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
70 |
case ERROR_UNCERTAIN_MEDIA: return(ERR_UNCERTAIN_MEDIA); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
71 |
case ERROR_PROTECTION_VIOLATION: return(ERR_PROT_VIOLATION); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
72 |
case ERROR_BROKEN_PIPE: return(ERR_BROKEN_PIPE); |
404 | 73 |
|
74 |
case ERROR_INVALID_PARAMETER: |
|
75 |
case ERROR_INVALID_NAME: |
|
76 |
case ERROR_INVALID_DRIVE: |
|
77 |
case ERROR_INVALID_HANDLE: |
|
78 |
case ERROR_INVALID_FUNCTION: |
|
79 |
case ERROR_INVALID_LEVEL: |
|
80 |
case ERROR_INVALID_CATEGORY: |
|
81 |
case ERROR_DUPLICATE_NAME: |
|
82 |
case ERROR_BUFFER_OVERFLOW: |
|
83 |
case ERROR_BAD_LENGTH: |
|
84 |
case ERROR_BAD_DRIVER_LEVEL: |
|
85 |
case ERROR_DIRECT_ACCESS_HANDLE: |
|
427
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
86 |
case ERROR_NOT_OWNER: |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
87 |
return(ERR_PHYSFS_BAD_OS_CALL); |
404 | 88 |
|
427
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
89 |
default: return(ERR_OS2_GENERIC); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
90 |
} /* switch */ |
404 | 91 |
|
427
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
92 |
return(NULL); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
93 |
} /* get_os2_error_string */ |
404 | 94 |
|
95 |
||
427
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
96 |
static APIRET os2err(APIRET retval) |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
97 |
{ |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
98 |
char buf[128]; |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
99 |
const char *err = get_os2_error_string(retval); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
100 |
if (err == ERR_OS2_GENERIC) |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
101 |
{ |
599
44af228dd59a
Patched to compile on OS/2.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
102 |
snprintf(buf, sizeof (buf), ERR_OS2_GENERIC, (int) retval); |
427
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
103 |
err = buf; |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
104 |
} /* if */ |
404 | 105 |
|
106 |
if (err != NULL) |
|
107 |
__PHYSFS_setError(err); |
|
108 |
||
599
44af228dd59a
Patched to compile on OS/2.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
109 |
return(retval); |
404 | 110 |
} /* os2err */ |
111 |
||
112 |
||
420
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
113 |
/* (be gentle, this function isn't very robust.) */ |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
114 |
static void cvt_path_to_correct_case(char *buf) |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
115 |
{ |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
116 |
char *fname = buf + 3; /* point to first element. */ |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
117 |
char *ptr = strchr(fname, '\\'); /* find end of first element. */ |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
118 |
|
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
119 |
buf[0] = toupper(buf[0]); /* capitalize drive letter. */ |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
120 |
|
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
121 |
/* |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
122 |
* Go through each path element, and enumerate its parent dir until |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
123 |
* a case-insensitive match is found. If one is (and it SHOULD be) |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
124 |
* then overwrite the original element with the correct case. |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
125 |
* If there's an error, or the path has vanished for some reason, it |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
126 |
* won't hurt to have the original case, so we just keep going. |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
127 |
*/ |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
128 |
while (fname != NULL) |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
129 |
{ |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
130 |
char spec[CCHMAXPATH]; |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
131 |
FILEFINDBUF3 fb; |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
132 |
HDIR hdir = HDIR_CREATE; |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
133 |
ULONG count = 1; |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
134 |
APIRET rc; |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
135 |
|
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
136 |
*(fname - 1) = '\0'; /* isolate parent dir string. */ |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
137 |
|
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
138 |
strcpy(spec, buf); /* copy isolated parent dir... */ |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
139 |
strcat(spec, "\\*.*"); /* ...and add wildcard search spec. */ |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
140 |
|
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
141 |
if (ptr != NULL) /* isolate element to find (fname is the start). */ |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
142 |
*ptr = '\0'; |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
143 |
|
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
144 |
rc = DosFindFirst(spec, &hdir, FILE_DIRECTORY, |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
145 |
&fb, sizeof (fb), &count, FIL_STANDARD); |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
146 |
if (rc == NO_ERROR) |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
147 |
{ |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
148 |
while (count == 1) /* while still entries to enumerate... */ |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
149 |
{ |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
150 |
if (__PHYSFS_platformStricmp(fb.achName, fname) == 0) |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
151 |
{ |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
152 |
strcpy(fname, fb.achName); |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
153 |
break; /* there it is. Overwrite and stop searching. */ |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
154 |
} /* if */ |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
155 |
|
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
156 |
DosFindNext(hdir, &fb, sizeof (fb), &count); |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
157 |
} /* while */ |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
158 |
DosFindClose(hdir); |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
159 |
} /* if */ |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
160 |
|
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
161 |
*(fname - 1) = '\\'; /* unisolate parent dir. */ |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
162 |
fname = ptr; /* point to next element. */ |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
163 |
if (ptr != NULL) |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
164 |
{ |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
165 |
*ptr = '\\'; /* unisolate element. */ |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
166 |
ptr = strchr(++fname, '\\'); /* find next element. */ |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
167 |
} /* if */ |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
168 |
} /* while */ |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
169 |
} /* cvt_file_to_correct_case */ |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
170 |
|
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
171 |
|
404 | 172 |
static char *baseDir = NULL; |
173 |
||
174 |
int __PHYSFS_platformInit(void) |
|
175 |
{ |
|
176 |
char buf[CCHMAXPATH]; |
|
177 |
APIRET rc; |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
178 |
PTIB ptib; |
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
179 |
PPIB ppib; |
411
4907a4f94872
Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents:
407
diff
changeset
|
180 |
PHYSFS_sint32 len; |
404 | 181 |
|
182 |
assert(baseDir == NULL); |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
183 |
BAIL_IF_MACRO(os2err(DosGetInfoBlocks(&ptib, &ppib)) != NO_ERROR, NULL, 0); |
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
184 |
rc = DosQueryModuleName(ppib->pib_hmte, sizeof (buf), (PCHAR) buf); |
404 | 185 |
BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, 0); |
186 |
||
411
4907a4f94872
Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents:
407
diff
changeset
|
187 |
/* chop off filename, leave path. */ |
4907a4f94872
Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents:
407
diff
changeset
|
188 |
for (len = strlen(buf) - 1; len >= 0; len--) |
4907a4f94872
Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents:
407
diff
changeset
|
189 |
{ |
4907a4f94872
Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents:
407
diff
changeset
|
190 |
if (buf[len] == '\\') |
4907a4f94872
Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents:
407
diff
changeset
|
191 |
{ |
412 | 192 |
buf[len] = '\0'; |
411
4907a4f94872
Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents:
407
diff
changeset
|
193 |
break; |
4907a4f94872
Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents:
407
diff
changeset
|
194 |
} /* if */ |
4907a4f94872
Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents:
407
diff
changeset
|
195 |
} /* for */ |
4907a4f94872
Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents:
407
diff
changeset
|
196 |
|
416
eadb08626c80
Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents:
412
diff
changeset
|
197 |
assert(len > 0); /* should have been a "x:\\" on the front on string. */ |
411
4907a4f94872
Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents:
407
diff
changeset
|
198 |
|
420
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
199 |
/* The string is capitalized! Figure out the REAL case... */ |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
200 |
cvt_path_to_correct_case(buf); |
8869f1432112
Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents:
416
diff
changeset
|
201 |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
202 |
baseDir = (char *) allocator.Malloc(len + 1); |
404 | 203 |
BAIL_IF_MACRO(baseDir == NULL, ERR_OUT_OF_MEMORY, 0); |
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
204 |
strcpy(baseDir, buf); |
404 | 205 |
return(1); /* success. */ |
206 |
} /* __PHYSFS_platformInit */ |
|
207 |
||
208 |
||
209 |
int __PHYSFS_platformDeinit(void) |
|
210 |
{ |
|
211 |
assert(baseDir != NULL); |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
212 |
allocator.Free(baseDir); |
404 | 213 |
baseDir = NULL; |
214 |
return(1); /* success. */ |
|
215 |
} /* __PHYSFS_platformDeinit */ |
|
216 |
||
217 |
||
218 |
static int disc_is_inserted(ULONG drive) |
|
219 |
{ |
|
220 |
int rc; |
|
221 |
char buf[20]; |
|
222 |
DosError(FERR_DISABLEHARDERR | FERR_DISABLEEXCEPTION); |
|
223 |
rc = DosQueryFSInfo(drive + 1, FSIL_VOLSER, buf, sizeof (buf)); |
|
224 |
DosError(FERR_ENABLEHARDERR | FERR_ENABLEEXCEPTION); |
|
225 |
return(rc == NO_ERROR); |
|
226 |
} /* is_cdrom_inserted */ |
|
227 |
||
228 |
||
416
eadb08626c80
Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents:
412
diff
changeset
|
229 |
/* looks like "CD01" in ASCII (littleendian)...used for an ioctl. */ |
eadb08626c80
Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents:
412
diff
changeset
|
230 |
#define CD01 0x31304443 |
eadb08626c80
Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents:
412
diff
changeset
|
231 |
|
404 | 232 |
static int is_cdrom_drive(ULONG drive) |
233 |
{ |
|
416
eadb08626c80
Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents:
412
diff
changeset
|
234 |
PHYSFS_uint32 param, data; |
404 | 235 |
ULONG ul1, ul2; |
236 |
APIRET rc; |
|
416
eadb08626c80
Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents:
412
diff
changeset
|
237 |
HFILE hfile = NULLHANDLE; |
eadb08626c80
Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents:
412
diff
changeset
|
238 |
char drivename[3] = { 'A' + drive, ':', '\0' }; |
404 | 239 |
|
416
eadb08626c80
Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents:
412
diff
changeset
|
240 |
rc = DosOpen(drivename, &hfile, &ul1, 0, 0, |
eadb08626c80
Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents:
412
diff
changeset
|
241 |
OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW, |
eadb08626c80
Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents:
412
diff
changeset
|
242 |
OPEN_FLAGS_DASD | OPEN_FLAGS_FAIL_ON_ERROR | |
eadb08626c80
Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents:
412
diff
changeset
|
243 |
OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYNONE, NULL); |
eadb08626c80
Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents:
412
diff
changeset
|
244 |
BAIL_IF_MACRO(rc != NO_ERROR, NULL, 0); |
404 | 245 |
|
416
eadb08626c80
Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents:
412
diff
changeset
|
246 |
data = 0; |
eadb08626c80
Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents:
412
diff
changeset
|
247 |
param = PHYSFS_swapULE32(CD01); |
eadb08626c80
Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents:
412
diff
changeset
|
248 |
ul1 = ul2 = sizeof (PHYSFS_uint32); |
eadb08626c80
Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents:
412
diff
changeset
|
249 |
rc = DosDevIOCtl(hfile, IOCTL_CDROMDISK, CDROMDISK_GETDRIVER, |
eadb08626c80
Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents:
412
diff
changeset
|
250 |
¶m, sizeof (param), &ul1, &data, sizeof (data), &ul2); |
eadb08626c80
Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents:
412
diff
changeset
|
251 |
|
eadb08626c80
Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents:
412
diff
changeset
|
252 |
DosClose(hfile); |
eadb08626c80
Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents:
412
diff
changeset
|
253 |
return((rc == NO_ERROR) && (PHYSFS_swapULE32(data) == CD01)); |
404 | 254 |
} /* is_cdrom_drive */ |
255 |
||
256 |
||
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
599
diff
changeset
|
257 |
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data) |
404 | 258 |
{ |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
599
diff
changeset
|
259 |
ULONG dummy = 0; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
599
diff
changeset
|
260 |
ULONG drivemap = 0; |
404 | 261 |
ULONG i, bit; |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
599
diff
changeset
|
262 |
APIRET rc = DosQueryCurrentDisk(&dummy, &drivemap); |
714
03c2e2ee0905
Patched to compile on OS/2 again.
Ryan C. Gordon <icculus@icculus.org>
parents:
691
diff
changeset
|
263 |
if (os2err(rc) != NO_ERROR) |
03c2e2ee0905
Patched to compile on OS/2 again.
Ryan C. Gordon <icculus@icculus.org>
parents:
691
diff
changeset
|
264 |
return; |
404 | 265 |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
266 |
for (i = 0, bit = 1; i < 26; i++, bit <<= 1) |
404 | 267 |
{ |
268 |
if (drivemap & bit) /* this logical drive exists. */ |
|
269 |
{ |
|
270 |
if ((is_cdrom_drive(i)) && (disc_is_inserted(i))) |
|
271 |
{ |
|
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
599
diff
changeset
|
272 |
char drive[4] = "x:\\"; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
599
diff
changeset
|
273 |
drive[0] = ('A' + i); |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
599
diff
changeset
|
274 |
cb(data, drive); |
404 | 275 |
} /* if */ |
276 |
} /* if */ |
|
277 |
} /* for */ |
|
278 |
} /* __PHYSFS_platformDetectAvailableCDs */ |
|
279 |
||
280 |
||
281 |
char *__PHYSFS_platformCalcBaseDir(const char *argv0) |
|
282 |
{ |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
283 |
char *retval = (char *) allocator.Malloc(strlen(baseDir) + 1); |
404 | 284 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
285 |
strcpy(retval, baseDir); /* calculated at init time. */ |
|
286 |
return(retval); |
|
287 |
} /* __PHYSFS_platformCalcBaseDir */ |
|
288 |
||
289 |
||
290 |
char *__PHYSFS_platformGetUserName(void) |
|
291 |
{ |
|
292 |
return(NULL); /* (*shrug*) */ |
|
293 |
} /* __PHYSFS_platformGetUserName */ |
|
294 |
||
295 |
||
296 |
char *__PHYSFS_platformGetUserDir(void) |
|
297 |
{ |
|
298 |
return(__PHYSFS_platformCalcBaseDir(NULL)); |
|
299 |
} /* __PHYSFS_platformGetUserDir */ |
|
300 |
||
301 |
||
302 |
int __PHYSFS_platformStricmp(const char *x, const char *y) |
|
303 |
{ |
|
304 |
int ux, uy; |
|
305 |
||
306 |
do |
|
307 |
{ |
|
308 |
ux = toupper((int) *x); |
|
309 |
uy = toupper((int) *y); |
|
310 |
if (ux > uy) |
|
311 |
return(1); |
|
312 |
else if (ux < uy) |
|
313 |
return(-1); |
|
314 |
x++; |
|
315 |
y++; |
|
316 |
} while ((ux) && (uy)); |
|
317 |
||
318 |
return(0); |
|
319 |
} /* __PHYSFS_platformStricmp */ |
|
320 |
||
321 |
||
596
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
322 |
int __PHYSFS_platformStrnicmp(const char *x, const char *y, PHYSFS_uint32 len) |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
323 |
{ |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
324 |
int ux, uy; |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
325 |
|
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
326 |
if (!len) |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
327 |
return(0); |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
328 |
|
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
329 |
do |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
330 |
{ |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
331 |
ux = toupper((int) *x); |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
332 |
uy = toupper((int) *y); |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
333 |
if (ux > uy) |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
334 |
return(1); |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
335 |
else if (ux < uy) |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
336 |
return(-1); |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
337 |
x++; |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
338 |
y++; |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
339 |
len--; |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
340 |
} while ((ux) && (uy) && (len)); |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
341 |
|
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
342 |
return(0); |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
343 |
} /* __PHYSFS_platformStrnicmp */ |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
344 |
|
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
345 |
|
404 | 346 |
int __PHYSFS_platformExists(const char *fname) |
347 |
{ |
|
348 |
FILESTATUS3 fs; |
|
349 |
APIRET rc = DosQueryPathInfo(fname, FIL_STANDARD, &fs, sizeof (fs)); |
|
350 |
return(os2err(rc) == NO_ERROR); |
|
351 |
} /* __PHYSFS_platformExists */ |
|
352 |
||
353 |
||
354 |
int __PHYSFS_platformIsSymLink(const char *fname) |
|
355 |
{ |
|
356 |
return(0); /* no symlinks in OS/2. */ |
|
357 |
} /* __PHYSFS_platformIsSymlink */ |
|
358 |
||
359 |
||
360 |
int __PHYSFS_platformIsDirectory(const char *fname) |
|
361 |
{ |
|
362 |
FILESTATUS3 fs; |
|
363 |
APIRET rc = DosQueryPathInfo(fname, FIL_STANDARD, &fs, sizeof (fs)); |
|
364 |
BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, 0) |
|
365 |
return((fs.attrFile & FILE_DIRECTORY) != 0); |
|
366 |
} /* __PHYSFS_platformIsDirectory */ |
|
367 |
||
368 |
||
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
369 |
/* !!! FIXME: can we lose the malloc here? */ |
404 | 370 |
char *__PHYSFS_platformCvtToDependent(const char *prepend, |
371 |
const char *dirName, |
|
372 |
const char *append) |
|
373 |
{ |
|
374 |
int len = ((prepend) ? strlen(prepend) : 0) + |
|
375 |
((append) ? strlen(append) : 0) + |
|
376 |
strlen(dirName) + 1; |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
377 |
char *retval = allocator.Malloc(len); |
404 | 378 |
char *p; |
379 |
||
380 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
|
381 |
||
382 |
if (prepend) |
|
383 |
strcpy(retval, prepend); |
|
384 |
else |
|
385 |
retval[0] = '\0'; |
|
386 |
||
387 |
strcat(retval, dirName); |
|
388 |
||
389 |
if (append) |
|
390 |
strcat(retval, append); |
|
391 |
||
392 |
for (p = strchr(retval, '/'); p != NULL; p = strchr(p + 1, '/')) |
|
393 |
*p = '\\'; |
|
394 |
||
395 |
return(retval); |
|
396 |
} /* __PHYSFS_platformCvtToDependent */ |
|
397 |
||
398 |
||
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
599
diff
changeset
|
399 |
void __PHYSFS_platformEnumerateFiles(const char *dirname, |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
599
diff
changeset
|
400 |
int omitSymLinks, |
754
e7cd7411eadf
API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents:
747
diff
changeset
|
401 |
PHYSFS_EnumFilesCallback callback, |
e7cd7411eadf
API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents:
747
diff
changeset
|
402 |
const char *origdir, |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
599
diff
changeset
|
403 |
void *callbackdata) |
404 | 404 |
{ |
405 |
char spec[CCHMAXPATH]; |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
406 |
FILEFINDBUF3 fb; |
404 | 407 |
HDIR hdir = HDIR_CREATE; |
408 |
ULONG count = 1; |
|
409 |
APIRET rc; |
|
410 |
||
714
03c2e2ee0905
Patched to compile on OS/2 again.
Ryan C. Gordon <icculus@icculus.org>
parents:
691
diff
changeset
|
411 |
if (strlen(dirname) > sizeof (spec) - 5) |
03c2e2ee0905
Patched to compile on OS/2 again.
Ryan C. Gordon <icculus@icculus.org>
parents:
691
diff
changeset
|
412 |
{ |
03c2e2ee0905
Patched to compile on OS/2 again.
Ryan C. Gordon <icculus@icculus.org>
parents:
691
diff
changeset
|
413 |
__PHYSFS_setError(ERR_BAD_FILENAME); |
03c2e2ee0905
Patched to compile on OS/2 again.
Ryan C. Gordon <icculus@icculus.org>
parents:
691
diff
changeset
|
414 |
return; |
03c2e2ee0905
Patched to compile on OS/2 again.
Ryan C. Gordon <icculus@icculus.org>
parents:
691
diff
changeset
|
415 |
} /* if */ |
03c2e2ee0905
Patched to compile on OS/2 again.
Ryan C. Gordon <icculus@icculus.org>
parents:
691
diff
changeset
|
416 |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
417 |
strcpy(spec, dirname); |
416
eadb08626c80
Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents:
412
diff
changeset
|
418 |
strcat(spec, (spec[strlen(spec) - 1] != '\\') ? "\\*.*" : "*.*"); |
404 | 419 |
|
420 |
rc = DosFindFirst(spec, &hdir, |
|
421 |
FILE_DIRECTORY | FILE_ARCHIVED | |
|
422 |
FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM, |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
423 |
&fb, sizeof (fb), &count, FIL_STANDARD); |
714
03c2e2ee0905
Patched to compile on OS/2 again.
Ryan C. Gordon <icculus@icculus.org>
parents:
691
diff
changeset
|
424 |
|
03c2e2ee0905
Patched to compile on OS/2 again.
Ryan C. Gordon <icculus@icculus.org>
parents:
691
diff
changeset
|
425 |
if (os2err(rc) != NO_ERROR) |
03c2e2ee0905
Patched to compile on OS/2 again.
Ryan C. Gordon <icculus@icculus.org>
parents:
691
diff
changeset
|
426 |
return; |
03c2e2ee0905
Patched to compile on OS/2 again.
Ryan C. Gordon <icculus@icculus.org>
parents:
691
diff
changeset
|
427 |
|
404 | 428 |
while (count == 1) |
429 |
{ |
|
416
eadb08626c80
Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents:
412
diff
changeset
|
430 |
if ((strcmp(fb.achName, ".") != 0) && (strcmp(fb.achName, "..") != 0)) |
754
e7cd7411eadf
API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents:
747
diff
changeset
|
431 |
callback(callbackdata, origdir, fb.achName); |
404 | 432 |
|
433 |
DosFindNext(hdir, &fb, sizeof (fb), &count); |
|
434 |
} /* while */ |
|
435 |
||
436 |
DosFindClose(hdir); |
|
437 |
} /* __PHYSFS_platformEnumerateFiles */ |
|
438 |
||
439 |
||
440 |
char *__PHYSFS_platformCurrentDir(void) |
|
441 |
{ |
|
442 |
char *retval; |
|
443 |
ULONG currentDisk; |
|
444 |
ULONG dummy; |
|
445 |
ULONG pathSize = 0; |
|
446 |
APIRET rc; |
|
447 |
BYTE byte; |
|
448 |
||
449 |
rc = DosQueryCurrentDisk(¤tDisk, &dummy); |
|
450 |
BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, NULL); |
|
451 |
||
452 |
/* The first call just tells us how much space we need for the string. */ |
|
453 |
rc = DosQueryCurrentDir(currentDisk, &byte, &pathSize); |
|
454 |
pathSize++; /* Add space for null terminator. */ |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
455 |
retval = (char *) allocator.Malloc(pathSize + 3); /* plus "x:\\" */ |
404 | 456 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
457 |
||
458 |
/* Actually get the string this time. */ |
|
459 |
rc = DosQueryCurrentDir(currentDisk, (PBYTE) (retval + 3), &pathSize); |
|
460 |
if (os2err(rc) != NO_ERROR) |
|
461 |
{ |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
462 |
allocator.Free(retval); |
404 | 463 |
return(NULL); |
464 |
} /* if */ |
|
465 |
||
466 |
retval[0] = ('A' + (currentDisk - 1)); |
|
467 |
retval[1] = ':'; |
|
468 |
retval[2] = '\\'; |
|
469 |
return(retval); |
|
470 |
} /* __PHYSFS_platformCurrentDir */ |
|
471 |
||
472 |
||
473 |
char *__PHYSFS_platformRealPath(const char *path) |
|
474 |
{ |
|
475 |
char buf[CCHMAXPATH]; |
|
476 |
char *retval; |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
477 |
APIRET rc = DosQueryPathInfo(path, FIL_QUERYFULLNAME, buf, sizeof (buf)); |
404 | 478 |
BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, NULL); |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
479 |
retval = (char *) allocator.Malloc(strlen(buf) + 1); |
404 | 480 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
481 |
strcpy(retval, buf); |
|
482 |
return(retval); |
|
483 |
} /* __PHYSFS_platformRealPath */ |
|
484 |
||
485 |
||
486 |
int __PHYSFS_platformMkDir(const char *path) |
|
487 |
{ |
|
488 |
return(os2err(DosCreateDir(path, NULL)) == NO_ERROR); |
|
489 |
} /* __PHYSFS_platformMkDir */ |
|
490 |
||
491 |
||
492 |
void *__PHYSFS_platformOpenRead(const char *filename) |
|
493 |
{ |
|
494 |
ULONG actionTaken = 0; |
|
495 |
HFILE hfile = NULLHANDLE; |
|
496 |
||
497 |
/* |
|
498 |
* File must be opened SHARE_DENYWRITE and ACCESS_READONLY, otherwise |
|
499 |
* DosQueryFileInfo() will fail if we try to get a file length, etc. |
|
500 |
*/ |
|
501 |
os2err(DosOpen(filename, &hfile, &actionTaken, 0, FILE_NORMAL, |
|
502 |
OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW, |
|
503 |
OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NO_LOCALITY | |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
504 |
OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYWRITE | |
404 | 505 |
OPEN_ACCESS_READONLY, NULL)); |
506 |
||
507 |
return((void *) hfile); |
|
508 |
} /* __PHYSFS_platformOpenRead */ |
|
509 |
||
510 |
||
511 |
void *__PHYSFS_platformOpenWrite(const char *filename) |
|
512 |
{ |
|
513 |
ULONG actionTaken = 0; |
|
514 |
HFILE hfile = NULLHANDLE; |
|
515 |
||
516 |
/* |
|
517 |
* File must be opened SHARE_DENYWRITE and ACCESS_READWRITE, otherwise |
|
518 |
* DosQueryFileInfo() will fail if we try to get a file length, etc. |
|
519 |
*/ |
|
520 |
os2err(DosOpen(filename, &hfile, &actionTaken, 0, FILE_NORMAL, |
|
521 |
OPEN_ACTION_REPLACE_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW, |
|
522 |
OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NO_LOCALITY | |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
523 |
OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYWRITE | |
404 | 524 |
OPEN_ACCESS_READWRITE, NULL)); |
525 |
||
526 |
return((void *) hfile); |
|
527 |
} /* __PHYSFS_platformOpenWrite */ |
|
528 |
||
529 |
||
530 |
void *__PHYSFS_platformOpenAppend(const char *filename) |
|
531 |
{ |
|
532 |
ULONG dummy = 0; |
|
533 |
HFILE hfile = NULLHANDLE; |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
534 |
APIRET rc; |
404 | 535 |
|
536 |
/* |
|
537 |
* File must be opened SHARE_DENYWRITE and ACCESS_READWRITE, otherwise |
|
538 |
* DosQueryFileInfo() will fail if we try to get a file length, etc. |
|
539 |
*/ |
|
540 |
rc = os2err(DosOpen(filename, &hfile, &dummy, 0, FILE_NORMAL, |
|
541 |
OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW, |
|
542 |
OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NO_LOCALITY | |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
543 |
OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYWRITE | |
404 | 544 |
OPEN_ACCESS_READWRITE, NULL)); |
545 |
||
546 |
if (rc == NO_ERROR) |
|
547 |
{ |
|
548 |
if (os2err(DosSetFilePtr(hfile, 0, FILE_END, &dummy)) != NO_ERROR) |
|
549 |
{ |
|
550 |
DosClose(hfile); |
|
551 |
hfile = NULLHANDLE; |
|
552 |
} /* if */ |
|
553 |
} /* if */ |
|
554 |
||
555 |
return((void *) hfile); |
|
556 |
} /* __PHYSFS_platformOpenAppend */ |
|
557 |
||
558 |
||
559 |
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer, |
|
560 |
PHYSFS_uint32 size, PHYSFS_uint32 count) |
|
561 |
{ |
|
562 |
HFILE hfile = (HFILE) opaque; |
|
563 |
PHYSFS_sint64 retval; |
|
564 |
ULONG br; |
|
565 |
||
566 |
for (retval = 0; retval < count; retval++) |
|
567 |
{ |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
568 |
os2err(DosRead(hfile, buffer, size, &br)); |
404 | 569 |
if (br < size) |
570 |
{ |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
571 |
DosSetFilePtr(hfile, -br, FILE_CURRENT, &br); /* try to cleanup. */ |
404 | 572 |
return(retval); |
573 |
} /* if */ |
|
574 |
||
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
575 |
buffer = (void *) ( ((char *) buffer) + size ); |
404 | 576 |
} /* for */ |
577 |
||
578 |
return(retval); |
|
579 |
} /* __PHYSFS_platformRead */ |
|
580 |
||
581 |
||
582 |
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer, |
|
583 |
PHYSFS_uint32 size, PHYSFS_uint32 count) |
|
584 |
{ |
|
585 |
HFILE hfile = (HFILE) opaque; |
|
586 |
PHYSFS_sint64 retval; |
|
587 |
ULONG bw; |
|
588 |
||
589 |
for (retval = 0; retval < count; retval++) |
|
590 |
{ |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
591 |
os2err(DosWrite(hfile, buffer, size, &bw)); |
404 | 592 |
if (bw < size) |
593 |
{ |
|
594 |
DosSetFilePtr(hfile, -bw, FILE_CURRENT, &bw); /* try to cleanup. */ |
|
595 |
return(retval); |
|
596 |
} /* if */ |
|
597 |
||
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
598 |
buffer = (void *) ( ((char *) buffer) + size ); |
404 | 599 |
} /* for */ |
600 |
||
601 |
return(retval); |
|
602 |
} /* __PHYSFS_platformWrite */ |
|
603 |
||
604 |
||
605 |
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos) |
|
606 |
{ |
|
607 |
ULONG dummy; |
|
608 |
HFILE hfile = (HFILE) opaque; |
|
609 |
LONG dist = (LONG) pos; |
|
610 |
||
611 |
/* hooray for 32-bit filesystem limits! :) */ |
|
612 |
BAIL_IF_MACRO((PHYSFS_uint64) dist != pos, ERR_SEEK_OUT_OF_RANGE, 0); |
|
613 |
||
614 |
return(os2err(DosSetFilePtr(hfile, dist, FILE_BEGIN, &dummy)) == NO_ERROR); |
|
615 |
} /* __PHYSFS_platformSeek */ |
|
616 |
||
617 |
||
618 |
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque) |
|
619 |
{ |
|
620 |
ULONG pos; |
|
621 |
HFILE hfile = (HFILE) opaque; |
|
622 |
APIRET rc = os2err(DosSetFilePtr(hfile, 0, FILE_CURRENT, &pos)); |
|
623 |
BAIL_IF_MACRO(rc != NO_ERROR, NULL, -1); |
|
624 |
return((PHYSFS_sint64) pos); |
|
625 |
} /* __PHYSFS_platformTell */ |
|
626 |
||
627 |
||
628 |
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque) |
|
629 |
{ |
|
630 |
FILESTATUS3 fs; |
|
631 |
HFILE hfile = (HFILE) opaque; |
|
632 |
APIRET rc = DosQueryFileInfo(hfile, FIL_STANDARD, &fs, sizeof (fs)); |
|
633 |
BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, -1); |
|
634 |
return((PHYSFS_sint64) fs.cbFile); |
|
635 |
} /* __PHYSFS_platformFileLength */ |
|
636 |
||
637 |
||
638 |
int __PHYSFS_platformEOF(void *opaque) |
|
639 |
{ |
|
640 |
PHYSFS_sint64 len, pos; |
|
641 |
||
642 |
len = __PHYSFS_platformFileLength(opaque); |
|
643 |
BAIL_IF_MACRO(len == -1, NULL, 1); /* (*shrug*) */ |
|
644 |
pos = __PHYSFS_platformTell(opaque); |
|
645 |
BAIL_IF_MACRO(pos == -1, NULL, 1); /* (*shrug*) */ |
|
646 |
||
647 |
return(pos >= len); |
|
648 |
} /* __PHYSFS_platformEOF */ |
|
649 |
||
650 |
||
651 |
int __PHYSFS_platformFlush(void *opaque) |
|
652 |
{ |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
653 |
return(os2err(DosResetBuffer((HFILE) opaque) == NO_ERROR)); |
404 | 654 |
} /* __PHYSFS_platformFlush */ |
655 |
||
656 |
||
657 |
int __PHYSFS_platformClose(void *opaque) |
|
658 |
{ |
|
659 |
return(os2err(DosClose((HFILE) opaque) == NO_ERROR)); |
|
660 |
} /* __PHYSFS_platformClose */ |
|
661 |
||
662 |
||
663 |
int __PHYSFS_platformDelete(const char *path) |
|
664 |
{ |
|
665 |
if (__PHYSFS_platformIsDirectory(path)) |
|
666 |
return(os2err(DosDeleteDir(path)) == NO_ERROR); |
|
667 |
||
668 |
return(os2err(DosDelete(path) == NO_ERROR)); |
|
669 |
} /* __PHYSFS_platformDelete */ |
|
670 |
||
671 |
||
672 |
PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname) |
|
673 |
{ |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
674 |
PHYSFS_sint64 retval; |
404 | 675 |
struct tm tm; |
676 |
FILESTATUS3 fs; |
|
677 |
APIRET rc = DosQueryPathInfo(fname, FIL_STANDARD, &fs, sizeof (fs)); |
|
678 |
BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, -1); |
|
679 |
||
680 |
/* Convert to a format that mktime() can grok... */ |
|
681 |
tm.tm_sec = ((PHYSFS_uint32) fs.ftimeLastWrite.twosecs) * 2; |
|
682 |
tm.tm_min = fs.ftimeLastWrite.minutes; |
|
683 |
tm.tm_hour = fs.ftimeLastWrite.hours; |
|
684 |
tm.tm_mday = fs.fdateLastWrite.day; |
|
685 |
tm.tm_mon = fs.fdateLastWrite.month; |
|
686 |
tm.tm_year = ((PHYSFS_uint32) fs.fdateLastWrite.year) + 80; |
|
687 |
tm.tm_wday = -1 /*st_localtz.wDayOfWeek*/; |
|
688 |
tm.tm_yday = -1; |
|
689 |
tm.tm_isdst = -1; |
|
690 |
||
691 |
/* Convert to a format PhysicsFS can grok... */ |
|
692 |
retval = (PHYSFS_sint64) mktime(&tm); |
|
693 |
BAIL_IF_MACRO(retval == -1, strerror(errno), -1); |
|
694 |
return(retval); |
|
695 |
} /* __PHYSFS_platformGetLastModTime */ |
|
696 |
||
697 |
||
698 |
/* Much like my college days, try to sleep for 10 milliseconds at a time... */ |
|
699 |
void __PHYSFS_platformTimeslice(void) |
|
700 |
{ |
|
701 |
DosSleep(10); |
|
702 |
} /* __PHYSFS_platformTimeslice(void) */ |
|
703 |
||
704 |
||
705 |
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void) |
|
706 |
{ |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
707 |
PTIB ptib; |
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
708 |
PPIB ppib; |
404 | 709 |
|
710 |
/* |
|
711 |
* Allegedly, this API never fails, but we'll punt and return a |
|
712 |
* default value (zero might as well do) if it does. |
|
713 |
*/ |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
714 |
BAIL_IF_MACRO(os2err(DosGetInfoBlocks(&ptib, &ppib)) != NO_ERROR, 0, 0); |
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
715 |
return((PHYSFS_uint64) ptib->tib_ordinal); |
404 | 716 |
} /* __PHYSFS_platformGetThreadID */ |
717 |
||
718 |
||
719 |
void *__PHYSFS_platformCreateMutex(void) |
|
720 |
{ |
|
721 |
HMTX hmtx = NULLHANDLE; |
|
722 |
os2err(DosCreateMutexSem(NULL, &hmtx, 0, 0)); |
|
723 |
return((void *) hmtx); |
|
724 |
} /* __PHYSFS_platformCreateMutex */ |
|
725 |
||
726 |
||
727 |
void __PHYSFS_platformDestroyMutex(void *mutex) |
|
728 |
{ |
|
729 |
DosCloseMutexSem((HMTX) mutex); |
|
730 |
} /* __PHYSFS_platformDestroyMutex */ |
|
731 |
||
732 |
||
733 |
int __PHYSFS_platformGrabMutex(void *mutex) |
|
734 |
{ |
|
735 |
/* Do _NOT_ call os2err() (which sets the physfs error msg) in here! */ |
|
736 |
return(DosRequestMutexSem((HMTX) mutex, SEM_INDEFINITE_WAIT) == NO_ERROR); |
|
737 |
} /* __PHYSFS_platformGrabMutex */ |
|
738 |
||
739 |
||
740 |
void __PHYSFS_platformReleaseMutex(void *mutex) |
|
741 |
{ |
|
742 |
DosReleaseMutexSem((HMTX) mutex); |
|
743 |
} /* __PHYSFS_platformReleaseMutex */ |
|
744 |
||
717
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
745 |
|
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
746 |
int __PHYSFS_platformAllocatorInit(void) |
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
747 |
{ |
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
748 |
return(1); /* always succeeds. */ |
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
749 |
} /* __PHYSFS_platformAllocatorInit */ |
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
750 |
|
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
751 |
|
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
752 |
void __PHYSFS_platformAllocatorDeinit(void) |
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
753 |
{ |
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
754 |
/* no-op */ |
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
755 |
} /* __PHYSFS_platformAllocatorInit */ |
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
756 |
|
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
757 |
|
747
3da194b12f43
Don't use size_t in physfs.h, since it relies on C runtime headers.
Ryan C. Gordon <icculus@icculus.org>
parents:
717
diff
changeset
|
758 |
void *__PHYSFS_platformAllocatorMalloc(PHYSFS_uint64 s) |
717
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
759 |
{ |
763
efadd9cdb6a4
Cleaned up overflow checks in platform memory allocators (thanks to Nicolas
Ryan C. Gordon <icculus@icculus.org>
parents:
754
diff
changeset
|
760 |
BAIL_IF_MACRO(__PHYSFS_ui64FitsAddressSpace(s), ERR_OUT_OF_MEMORY, NULL); |
717
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
761 |
#undef malloc |
747
3da194b12f43
Don't use size_t in physfs.h, since it relies on C runtime headers.
Ryan C. Gordon <icculus@icculus.org>
parents:
717
diff
changeset
|
762 |
return(malloc((size_t) s)); |
717
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
763 |
} /* __PHYSFS_platformMalloc */ |
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
764 |
|
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
765 |
|
747
3da194b12f43
Don't use size_t in physfs.h, since it relies on C runtime headers.
Ryan C. Gordon <icculus@icculus.org>
parents:
717
diff
changeset
|
766 |
void *__PHYSFS_platformAllocatorRealloc(void *ptr, PHYSFS_uint64 s) |
717
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
767 |
{ |
763
efadd9cdb6a4
Cleaned up overflow checks in platform memory allocators (thanks to Nicolas
Ryan C. Gordon <icculus@icculus.org>
parents:
754
diff
changeset
|
768 |
BAIL_IF_MACRO(__PHYSFS_ui64FitsAddressSpace(s), ERR_OUT_OF_MEMORY, NULL); |
717
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
769 |
#undef realloc |
747
3da194b12f43
Don't use size_t in physfs.h, since it relies on C runtime headers.
Ryan C. Gordon <icculus@icculus.org>
parents:
717
diff
changeset
|
770 |
return(realloc(ptr, (size_t) s)); |
717
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
771 |
} /* __PHYSFS_platformRealloc */ |
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
772 |
|
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
773 |
|
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
774 |
void __PHYSFS_platformAllocatorFree(void *ptr) |
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
775 |
{ |
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
776 |
#undef free |
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
777 |
free(ptr); |
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
778 |
} /* __PHYSFS_platformAllocatorFree */ |
ae8bc9888553
More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
714
diff
changeset
|
779 |
|
404 | 780 |
#endif /* defined OS2 */ |
781 |
||
782 |
/* end of os2.c ... */ |
|
783 |