author | Ryan C. Gordon <icculus@icculus.org> |
Sun, 13 Mar 2005 09:16:26 +0000 | |
changeset 680 | 413803699662 |
parent 657 | dad3b5c307a9 |
child 691 | 71d9affe0d8a |
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 |
|
411
4907a4f94872
Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents:
407
diff
changeset
|
202 |
baseDir = (char *) 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); |
|
212 |
free(baseDir); |
|
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); |
404 | 263 |
BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, retval); |
264 |
||
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
265 |
for (i = 0, bit = 1; i < 26; i++, bit <<= 1) |
404 | 266 |
{ |
267 |
if (drivemap & bit) /* this logical drive exists. */ |
|
268 |
{ |
|
269 |
if ((is_cdrom_drive(i)) && (disc_is_inserted(i))) |
|
270 |
{ |
|
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
599
diff
changeset
|
271 |
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
|
272 |
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
|
273 |
cb(data, drive); |
404 | 274 |
} /* if */ |
275 |
} /* if */ |
|
276 |
} /* for */ |
|
277 |
} /* __PHYSFS_platformDetectAvailableCDs */ |
|
278 |
||
279 |
||
280 |
char *__PHYSFS_platformCalcBaseDir(const char *argv0) |
|
281 |
{ |
|
282 |
char *retval = (char *) malloc(strlen(baseDir) + 1); |
|
283 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
|
284 |
strcpy(retval, baseDir); /* calculated at init time. */ |
|
285 |
return(retval); |
|
286 |
} /* __PHYSFS_platformCalcBaseDir */ |
|
287 |
||
288 |
||
289 |
char *__PHYSFS_platformGetUserName(void) |
|
290 |
{ |
|
291 |
return(NULL); /* (*shrug*) */ |
|
292 |
} /* __PHYSFS_platformGetUserName */ |
|
293 |
||
294 |
||
295 |
char *__PHYSFS_platformGetUserDir(void) |
|
296 |
{ |
|
297 |
return(__PHYSFS_platformCalcBaseDir(NULL)); |
|
298 |
} /* __PHYSFS_platformGetUserDir */ |
|
299 |
||
300 |
||
301 |
int __PHYSFS_platformStricmp(const char *x, const char *y) |
|
302 |
{ |
|
303 |
int ux, uy; |
|
304 |
||
305 |
do |
|
306 |
{ |
|
307 |
ux = toupper((int) *x); |
|
308 |
uy = toupper((int) *y); |
|
309 |
if (ux > uy) |
|
310 |
return(1); |
|
311 |
else if (ux < uy) |
|
312 |
return(-1); |
|
313 |
x++; |
|
314 |
y++; |
|
315 |
} while ((ux) && (uy)); |
|
316 |
||
317 |
return(0); |
|
318 |
} /* __PHYSFS_platformStricmp */ |
|
319 |
||
320 |
||
596
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
321 |
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
|
322 |
{ |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
323 |
int ux, uy; |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
324 |
|
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
325 |
if (!len) |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
326 |
return(0); |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
327 |
|
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
328 |
do |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
329 |
{ |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
330 |
ux = toupper((int) *x); |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
331 |
uy = toupper((int) *y); |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
332 |
if (ux > uy) |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
333 |
return(1); |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
334 |
else if (ux < uy) |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
335 |
return(-1); |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
336 |
x++; |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
337 |
y++; |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
338 |
len--; |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
339 |
} while ((ux) && (uy) && (len)); |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
340 |
|
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
341 |
return(0); |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
342 |
} /* __PHYSFS_platformStrnicmp */ |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
343 |
|
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
344 |
|
404 | 345 |
int __PHYSFS_platformExists(const char *fname) |
346 |
{ |
|
347 |
FILESTATUS3 fs; |
|
348 |
APIRET rc = DosQueryPathInfo(fname, FIL_STANDARD, &fs, sizeof (fs)); |
|
349 |
return(os2err(rc) == NO_ERROR); |
|
350 |
} /* __PHYSFS_platformExists */ |
|
351 |
||
352 |
||
353 |
int __PHYSFS_platformIsSymLink(const char *fname) |
|
354 |
{ |
|
355 |
return(0); /* no symlinks in OS/2. */ |
|
356 |
} /* __PHYSFS_platformIsSymlink */ |
|
357 |
||
358 |
||
359 |
int __PHYSFS_platformIsDirectory(const char *fname) |
|
360 |
{ |
|
361 |
FILESTATUS3 fs; |
|
362 |
APIRET rc = DosQueryPathInfo(fname, FIL_STANDARD, &fs, sizeof (fs)); |
|
363 |
BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, 0) |
|
364 |
return((fs.attrFile & FILE_DIRECTORY) != 0); |
|
365 |
} /* __PHYSFS_platformIsDirectory */ |
|
366 |
||
367 |
||
368 |
char *__PHYSFS_platformCvtToDependent(const char *prepend, |
|
369 |
const char *dirName, |
|
370 |
const char *append) |
|
371 |
{ |
|
372 |
int len = ((prepend) ? strlen(prepend) : 0) + |
|
373 |
((append) ? strlen(append) : 0) + |
|
374 |
strlen(dirName) + 1; |
|
375 |
char *retval = malloc(len); |
|
376 |
char *p; |
|
377 |
||
378 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
|
379 |
||
380 |
if (prepend) |
|
381 |
strcpy(retval, prepend); |
|
382 |
else |
|
383 |
retval[0] = '\0'; |
|
384 |
||
385 |
strcat(retval, dirName); |
|
386 |
||
387 |
if (append) |
|
388 |
strcat(retval, append); |
|
389 |
||
390 |
for (p = strchr(retval, '/'); p != NULL; p = strchr(p + 1, '/')) |
|
391 |
*p = '\\'; |
|
392 |
||
393 |
return(retval); |
|
394 |
} /* __PHYSFS_platformCvtToDependent */ |
|
395 |
||
396 |
||
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
599
diff
changeset
|
397 |
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
|
398 |
int omitSymLinks, |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
599
diff
changeset
|
399 |
PHYSFS_StringCallback callback, |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
599
diff
changeset
|
400 |
void *callbackdata) |
404 | 401 |
{ |
402 |
char spec[CCHMAXPATH]; |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
403 |
FILEFINDBUF3 fb; |
404 | 404 |
HDIR hdir = HDIR_CREATE; |
405 |
ULONG count = 1; |
|
406 |
APIRET rc; |
|
407 |
||
423
524e087944b4
Minor error string correction.
Ryan C. Gordon <icculus@icculus.org>
parents:
420
diff
changeset
|
408 |
BAIL_IF_MACRO(strlen(dirname) > sizeof (spec) - 5, ERR_BAD_FILENAME, NULL); |
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
409 |
strcpy(spec, dirname); |
416
eadb08626c80
Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents:
412
diff
changeset
|
410 |
strcat(spec, (spec[strlen(spec) - 1] != '\\') ? "\\*.*" : "*.*"); |
404 | 411 |
|
412 |
rc = DosFindFirst(spec, &hdir, |
|
413 |
FILE_DIRECTORY | FILE_ARCHIVED | |
|
414 |
FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM, |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
415 |
&fb, sizeof (fb), &count, FIL_STANDARD); |
404 | 416 |
BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, 0); |
417 |
while (count == 1) |
|
418 |
{ |
|
416
eadb08626c80
Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents:
412
diff
changeset
|
419 |
if ((strcmp(fb.achName, ".") != 0) && (strcmp(fb.achName, "..") != 0)) |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
599
diff
changeset
|
420 |
callback(callbackdata, fb.achName); |
404 | 421 |
|
422 |
DosFindNext(hdir, &fb, sizeof (fb), &count); |
|
423 |
} /* while */ |
|
424 |
||
425 |
DosFindClose(hdir); |
|
426 |
} /* __PHYSFS_platformEnumerateFiles */ |
|
427 |
||
428 |
||
429 |
char *__PHYSFS_platformCurrentDir(void) |
|
430 |
{ |
|
431 |
char *retval; |
|
432 |
ULONG currentDisk; |
|
433 |
ULONG dummy; |
|
434 |
ULONG pathSize = 0; |
|
435 |
APIRET rc; |
|
436 |
BYTE byte; |
|
437 |
||
438 |
rc = DosQueryCurrentDisk(¤tDisk, &dummy); |
|
439 |
BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, NULL); |
|
440 |
||
441 |
/* The first call just tells us how much space we need for the string. */ |
|
442 |
rc = DosQueryCurrentDir(currentDisk, &byte, &pathSize); |
|
443 |
pathSize++; /* Add space for null terminator. */ |
|
444 |
retval = (char *) malloc(pathSize + 3); /* plus "x:\\" */ |
|
445 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
|
446 |
||
447 |
/* Actually get the string this time. */ |
|
448 |
rc = DosQueryCurrentDir(currentDisk, (PBYTE) (retval + 3), &pathSize); |
|
449 |
if (os2err(rc) != NO_ERROR) |
|
450 |
{ |
|
451 |
free(retval); |
|
452 |
return(NULL); |
|
453 |
} /* if */ |
|
454 |
||
455 |
retval[0] = ('A' + (currentDisk - 1)); |
|
456 |
retval[1] = ':'; |
|
457 |
retval[2] = '\\'; |
|
458 |
return(retval); |
|
459 |
} /* __PHYSFS_platformCurrentDir */ |
|
460 |
||
461 |
||
462 |
char *__PHYSFS_platformRealPath(const char *path) |
|
463 |
{ |
|
464 |
char buf[CCHMAXPATH]; |
|
465 |
char *retval; |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
466 |
APIRET rc = DosQueryPathInfo(path, FIL_QUERYFULLNAME, buf, sizeof (buf)); |
404 | 467 |
BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, NULL); |
468 |
retval = (char *) malloc(strlen(buf) + 1); |
|
469 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
|
470 |
strcpy(retval, buf); |
|
471 |
return(retval); |
|
472 |
} /* __PHYSFS_platformRealPath */ |
|
473 |
||
474 |
||
475 |
int __PHYSFS_platformMkDir(const char *path) |
|
476 |
{ |
|
477 |
return(os2err(DosCreateDir(path, NULL)) == NO_ERROR); |
|
478 |
} /* __PHYSFS_platformMkDir */ |
|
479 |
||
480 |
||
481 |
void *__PHYSFS_platformOpenRead(const char *filename) |
|
482 |
{ |
|
483 |
ULONG actionTaken = 0; |
|
484 |
HFILE hfile = NULLHANDLE; |
|
485 |
||
486 |
/* |
|
487 |
* File must be opened SHARE_DENYWRITE and ACCESS_READONLY, otherwise |
|
488 |
* DosQueryFileInfo() will fail if we try to get a file length, etc. |
|
489 |
*/ |
|
490 |
os2err(DosOpen(filename, &hfile, &actionTaken, 0, FILE_NORMAL, |
|
491 |
OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW, |
|
492 |
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
|
493 |
OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYWRITE | |
404 | 494 |
OPEN_ACCESS_READONLY, NULL)); |
495 |
||
496 |
return((void *) hfile); |
|
497 |
} /* __PHYSFS_platformOpenRead */ |
|
498 |
||
499 |
||
500 |
void *__PHYSFS_platformOpenWrite(const char *filename) |
|
501 |
{ |
|
502 |
ULONG actionTaken = 0; |
|
503 |
HFILE hfile = NULLHANDLE; |
|
504 |
||
505 |
/* |
|
506 |
* File must be opened SHARE_DENYWRITE and ACCESS_READWRITE, otherwise |
|
507 |
* DosQueryFileInfo() will fail if we try to get a file length, etc. |
|
508 |
*/ |
|
509 |
os2err(DosOpen(filename, &hfile, &actionTaken, 0, FILE_NORMAL, |
|
510 |
OPEN_ACTION_REPLACE_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW, |
|
511 |
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
|
512 |
OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYWRITE | |
404 | 513 |
OPEN_ACCESS_READWRITE, NULL)); |
514 |
||
515 |
return((void *) hfile); |
|
516 |
} /* __PHYSFS_platformOpenWrite */ |
|
517 |
||
518 |
||
519 |
void *__PHYSFS_platformOpenAppend(const char *filename) |
|
520 |
{ |
|
521 |
ULONG dummy = 0; |
|
522 |
HFILE hfile = NULLHANDLE; |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
523 |
APIRET rc; |
404 | 524 |
|
525 |
/* |
|
526 |
* File must be opened SHARE_DENYWRITE and ACCESS_READWRITE, otherwise |
|
527 |
* DosQueryFileInfo() will fail if we try to get a file length, etc. |
|
528 |
*/ |
|
529 |
rc = os2err(DosOpen(filename, &hfile, &dummy, 0, FILE_NORMAL, |
|
530 |
OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW, |
|
531 |
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
|
532 |
OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYWRITE | |
404 | 533 |
OPEN_ACCESS_READWRITE, NULL)); |
534 |
||
535 |
if (rc == NO_ERROR) |
|
536 |
{ |
|
537 |
if (os2err(DosSetFilePtr(hfile, 0, FILE_END, &dummy)) != NO_ERROR) |
|
538 |
{ |
|
539 |
DosClose(hfile); |
|
540 |
hfile = NULLHANDLE; |
|
541 |
} /* if */ |
|
542 |
} /* if */ |
|
543 |
||
544 |
return((void *) hfile); |
|
545 |
} /* __PHYSFS_platformOpenAppend */ |
|
546 |
||
547 |
||
548 |
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer, |
|
549 |
PHYSFS_uint32 size, PHYSFS_uint32 count) |
|
550 |
{ |
|
551 |
HFILE hfile = (HFILE) opaque; |
|
552 |
PHYSFS_sint64 retval; |
|
553 |
ULONG br; |
|
554 |
||
555 |
for (retval = 0; retval < count; retval++) |
|
556 |
{ |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
557 |
os2err(DosRead(hfile, buffer, size, &br)); |
404 | 558 |
if (br < size) |
559 |
{ |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
560 |
DosSetFilePtr(hfile, -br, FILE_CURRENT, &br); /* try to cleanup. */ |
404 | 561 |
return(retval); |
562 |
} /* if */ |
|
563 |
||
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
564 |
buffer = (void *) ( ((char *) buffer) + size ); |
404 | 565 |
} /* for */ |
566 |
||
567 |
return(retval); |
|
568 |
} /* __PHYSFS_platformRead */ |
|
569 |
||
570 |
||
571 |
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer, |
|
572 |
PHYSFS_uint32 size, PHYSFS_uint32 count) |
|
573 |
{ |
|
574 |
HFILE hfile = (HFILE) opaque; |
|
575 |
PHYSFS_sint64 retval; |
|
576 |
ULONG bw; |
|
577 |
||
578 |
for (retval = 0; retval < count; retval++) |
|
579 |
{ |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
580 |
os2err(DosWrite(hfile, buffer, size, &bw)); |
404 | 581 |
if (bw < size) |
582 |
{ |
|
583 |
DosSetFilePtr(hfile, -bw, FILE_CURRENT, &bw); /* try to cleanup. */ |
|
584 |
return(retval); |
|
585 |
} /* if */ |
|
586 |
||
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
587 |
buffer = (void *) ( ((char *) buffer) + size ); |
404 | 588 |
} /* for */ |
589 |
||
590 |
return(retval); |
|
591 |
} /* __PHYSFS_platformWrite */ |
|
592 |
||
593 |
||
594 |
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos) |
|
595 |
{ |
|
596 |
ULONG dummy; |
|
597 |
HFILE hfile = (HFILE) opaque; |
|
598 |
LONG dist = (LONG) pos; |
|
599 |
||
600 |
/* hooray for 32-bit filesystem limits! :) */ |
|
601 |
BAIL_IF_MACRO((PHYSFS_uint64) dist != pos, ERR_SEEK_OUT_OF_RANGE, 0); |
|
602 |
||
603 |
return(os2err(DosSetFilePtr(hfile, dist, FILE_BEGIN, &dummy)) == NO_ERROR); |
|
604 |
} /* __PHYSFS_platformSeek */ |
|
605 |
||
606 |
||
607 |
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque) |
|
608 |
{ |
|
609 |
ULONG pos; |
|
610 |
HFILE hfile = (HFILE) opaque; |
|
611 |
APIRET rc = os2err(DosSetFilePtr(hfile, 0, FILE_CURRENT, &pos)); |
|
612 |
BAIL_IF_MACRO(rc != NO_ERROR, NULL, -1); |
|
613 |
return((PHYSFS_sint64) pos); |
|
614 |
} /* __PHYSFS_platformTell */ |
|
615 |
||
616 |
||
617 |
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque) |
|
618 |
{ |
|
619 |
FILESTATUS3 fs; |
|
620 |
HFILE hfile = (HFILE) opaque; |
|
621 |
APIRET rc = DosQueryFileInfo(hfile, FIL_STANDARD, &fs, sizeof (fs)); |
|
622 |
BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, -1); |
|
623 |
return((PHYSFS_sint64) fs.cbFile); |
|
624 |
} /* __PHYSFS_platformFileLength */ |
|
625 |
||
626 |
||
627 |
int __PHYSFS_platformEOF(void *opaque) |
|
628 |
{ |
|
629 |
PHYSFS_sint64 len, pos; |
|
630 |
||
631 |
len = __PHYSFS_platformFileLength(opaque); |
|
632 |
BAIL_IF_MACRO(len == -1, NULL, 1); /* (*shrug*) */ |
|
633 |
pos = __PHYSFS_platformTell(opaque); |
|
634 |
BAIL_IF_MACRO(pos == -1, NULL, 1); /* (*shrug*) */ |
|
635 |
||
636 |
return(pos >= len); |
|
637 |
} /* __PHYSFS_platformEOF */ |
|
638 |
||
639 |
||
640 |
int __PHYSFS_platformFlush(void *opaque) |
|
641 |
{ |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
642 |
return(os2err(DosResetBuffer((HFILE) opaque) == NO_ERROR)); |
404 | 643 |
} /* __PHYSFS_platformFlush */ |
644 |
||
645 |
||
646 |
int __PHYSFS_platformClose(void *opaque) |
|
647 |
{ |
|
648 |
return(os2err(DosClose((HFILE) opaque) == NO_ERROR)); |
|
649 |
} /* __PHYSFS_platformClose */ |
|
650 |
||
651 |
||
652 |
int __PHYSFS_platformDelete(const char *path) |
|
653 |
{ |
|
654 |
if (__PHYSFS_platformIsDirectory(path)) |
|
655 |
return(os2err(DosDeleteDir(path)) == NO_ERROR); |
|
656 |
||
657 |
return(os2err(DosDelete(path) == NO_ERROR)); |
|
658 |
} /* __PHYSFS_platformDelete */ |
|
659 |
||
660 |
||
661 |
PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname) |
|
662 |
{ |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
663 |
PHYSFS_sint64 retval; |
404 | 664 |
struct tm tm; |
665 |
FILESTATUS3 fs; |
|
666 |
APIRET rc = DosQueryPathInfo(fname, FIL_STANDARD, &fs, sizeof (fs)); |
|
667 |
BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, -1); |
|
668 |
||
669 |
/* Convert to a format that mktime() can grok... */ |
|
670 |
tm.tm_sec = ((PHYSFS_uint32) fs.ftimeLastWrite.twosecs) * 2; |
|
671 |
tm.tm_min = fs.ftimeLastWrite.minutes; |
|
672 |
tm.tm_hour = fs.ftimeLastWrite.hours; |
|
673 |
tm.tm_mday = fs.fdateLastWrite.day; |
|
674 |
tm.tm_mon = fs.fdateLastWrite.month; |
|
675 |
tm.tm_year = ((PHYSFS_uint32) fs.fdateLastWrite.year) + 80; |
|
676 |
tm.tm_wday = -1 /*st_localtz.wDayOfWeek*/; |
|
677 |
tm.tm_yday = -1; |
|
678 |
tm.tm_isdst = -1; |
|
679 |
||
680 |
/* Convert to a format PhysicsFS can grok... */ |
|
681 |
retval = (PHYSFS_sint64) mktime(&tm); |
|
682 |
BAIL_IF_MACRO(retval == -1, strerror(errno), -1); |
|
683 |
return(retval); |
|
684 |
} /* __PHYSFS_platformGetLastModTime */ |
|
685 |
||
686 |
||
687 |
/* Much like my college days, try to sleep for 10 milliseconds at a time... */ |
|
688 |
void __PHYSFS_platformTimeslice(void) |
|
689 |
{ |
|
690 |
DosSleep(10); |
|
691 |
} /* __PHYSFS_platformTimeslice(void) */ |
|
692 |
||
693 |
||
694 |
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void) |
|
695 |
{ |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
696 |
PTIB ptib; |
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
697 |
PPIB ppib; |
404 | 698 |
|
699 |
/* |
|
700 |
* Allegedly, this API never fails, but we'll punt and return a |
|
701 |
* default value (zero might as well do) if it does. |
|
702 |
*/ |
|
407
81646aa3f6f8
Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents:
404
diff
changeset
|
703 |
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
|
704 |
return((PHYSFS_uint64) ptib->tib_ordinal); |
404 | 705 |
} /* __PHYSFS_platformGetThreadID */ |
706 |
||
707 |
||
708 |
void *__PHYSFS_platformCreateMutex(void) |
|
709 |
{ |
|
710 |
HMTX hmtx = NULLHANDLE; |
|
711 |
os2err(DosCreateMutexSem(NULL, &hmtx, 0, 0)); |
|
712 |
return((void *) hmtx); |
|
713 |
} /* __PHYSFS_platformCreateMutex */ |
|
714 |
||
715 |
||
716 |
void __PHYSFS_platformDestroyMutex(void *mutex) |
|
717 |
{ |
|
718 |
DosCloseMutexSem((HMTX) mutex); |
|
719 |
} /* __PHYSFS_platformDestroyMutex */ |
|
720 |
||
721 |
||
722 |
int __PHYSFS_platformGrabMutex(void *mutex) |
|
723 |
{ |
|
724 |
/* Do _NOT_ call os2err() (which sets the physfs error msg) in here! */ |
|
725 |
return(DosRequestMutexSem((HMTX) mutex, SEM_INDEFINITE_WAIT) == NO_ERROR); |
|
726 |
} /* __PHYSFS_platformGrabMutex */ |
|
727 |
||
728 |
||
729 |
void __PHYSFS_platformReleaseMutex(void *mutex) |
|
730 |
{ |
|
731 |
DosReleaseMutexSem((HMTX) mutex); |
|
732 |
} /* __PHYSFS_platformReleaseMutex */ |
|
733 |
||
734 |
#endif /* defined OS2 */ |
|
735 |
||
736 |
/* end of os2.c ... */ |
|
737 |