author | Ryan C. Gordon <icculus@icculus.org> |
Sun, 11 Mar 2007 09:44:21 +0000 | |
changeset 808 | 7656f86a9a2c |
parent 793 | c75c9498c001 |
child 809 | 116b8fe30371 |
permissions | -rw-r--r-- |
501 | 1 |
/* |
2 |
* Skeleton platform-dependent 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 |
#include <stdio.h> |
|
10 |
#include <windows.h> |
|
11 |
||
12 |
#define __PHYSICSFS_INTERNAL__ |
|
13 |
#include "physfs_internal.h" |
|
14 |
||
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
15 |
#define INVALID_FILE_ATTRIBUTES 0xFFFFFFFF |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
16 |
#define INVALID_SET_FILE_POINTER 0xFFFFFFFF |
501 | 17 |
typedef struct |
18 |
{ |
|
19 |
HANDLE handle; |
|
20 |
int readonly; |
|
21 |
} winCEfile; |
|
22 |
||
23 |
||
24 |
const char *__PHYSFS_platformDirSeparator = "\\"; |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
25 |
static char *userDir = NULL; |
501 | 26 |
|
27 |
/* |
|
28 |
* Figure out what the last failing Win32 API call was, and |
|
29 |
* generate a human-readable string for the error message. |
|
30 |
* |
|
31 |
* The return value is a static buffer that is overwritten with |
|
32 |
* each call to this function. |
|
33 |
*/ |
|
34 |
static const char *win32strerror(void) |
|
35 |
{ |
|
36 |
static TCHAR msgbuf[255]; |
|
37 |
TCHAR *ptr = msgbuf; |
|
38 |
||
39 |
FormatMessage( |
|
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
40 |
FORMAT_MESSAGE_FROM_SYSTEM | |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
41 |
FORMAT_MESSAGE_IGNORE_INSERTS, |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
42 |
NULL, |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
43 |
GetLastError(), |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
44 |
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */ |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
45 |
msgbuf, |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
46 |
sizeof (msgbuf) / sizeof (TCHAR), |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
47 |
NULL |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
48 |
); |
501 | 49 |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
50 |
/* chop off newlines. */ |
501 | 51 |
for (ptr = msgbuf; *ptr; ptr++) |
52 |
{ |
|
53 |
if ((*ptr == '\n') || (*ptr == '\r')) |
|
54 |
{ |
|
55 |
*ptr = ' '; |
|
56 |
break; |
|
57 |
} /* if */ |
|
58 |
} /* for */ |
|
59 |
||
60 |
return((const char *) msgbuf); |
|
61 |
} /* win32strerror */ |
|
62 |
||
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
63 |
#define UTF8_TO_UNICODE_STACK_MACRO(w_assignto, str) { \ |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
64 |
if (str == NULL) \ |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
65 |
w_assignto = NULL; \ |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
66 |
else { \ |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
67 |
const PHYSFS_uint64 len = (PHYSFS_uint64) ((strlen(str) * 4) + 1); \ |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
68 |
w_assignto = (char *) alloca(len); \ |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
69 |
PHYSFS_uc2fromutf8(str, (PHYSFS_uint16 *) w_assignto, len); \ |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
70 |
} \ |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
71 |
} \ |
501 | 72 |
|
73 |
||
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
74 |
static char *getExePath() |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
75 |
{ |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
76 |
DWORD buflen; |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
77 |
int success = 0; |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
78 |
TCHAR *ptr = NULL; |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
79 |
TCHAR *retval = (TCHAR*) allocator.Malloc(sizeof (TCHAR) * (MAX_PATH + 1)); |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
80 |
char *charretval; |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
81 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
82 |
|
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
83 |
retval[0] = _T('\0'); |
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
84 |
/* !!! FIXME: don't preallocate here? */ |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
85 |
buflen = GetModuleFileName(NULL, retval, MAX_PATH + 1); |
792
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
86 |
if (buflen <= 0) |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
87 |
__PHYSFS_setError(win32strerror()); |
792
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
88 |
else |
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
89 |
{ |
792
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
90 |
retval[buflen] = '\0'; /* does API always null-terminate this? */ |
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
91 |
ptr = retval+buflen; |
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
92 |
while( ptr != retval ) |
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
93 |
{ |
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
94 |
if( *ptr != _T('\\') ) |
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
95 |
*ptr-- = _T('\0'); |
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
96 |
else |
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
97 |
break; |
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
98 |
} /* while */ |
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
99 |
success = 1; |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
100 |
} /* else */ |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
101 |
|
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
102 |
if (!success) |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
103 |
{ |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
104 |
allocator.Free(retval); |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
105 |
return(NULL); /* physfs error message will be set, above. */ |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
106 |
} /* if */ |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
107 |
|
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
108 |
buflen = (buflen * 4) + 1; |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
109 |
charretval = (char *) allocator.Malloc(buflen); |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
110 |
if (charretval != NULL) |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
111 |
PHYSFS_utf8fromucs2((const PHYSFS_uint16 *) retval, charretval, buflen); |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
112 |
allocator.Free(retval); |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
113 |
return(charretval); /* w00t. */ |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
114 |
} /* getExePath */ |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
115 |
|
792
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
116 |
|
501 | 117 |
int __PHYSFS_platformInit(void) |
118 |
{ |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
119 |
userDir = getExePath(); |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
120 |
BAIL_IF_MACRO(userDir == NULL, NULL, 0); /* failed? */ |
501 | 121 |
return(1); /* always succeed. */ |
122 |
} /* __PHYSFS_platformInit */ |
|
123 |
||
124 |
||
125 |
int __PHYSFS_platformDeinit(void) |
|
126 |
{ |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
127 |
allocator.Free(userDir); |
501 | 128 |
return(1); /* always succeed. */ |
129 |
} /* __PHYSFS_platformDeinit */ |
|
130 |
||
131 |
||
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
651
diff
changeset
|
132 |
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data) |
501 | 133 |
{ |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
651
diff
changeset
|
134 |
/* no-op on this platform. */ |
501 | 135 |
} /* __PHYSFS_platformDetectAvailableCDs */ |
136 |
||
137 |
||
138 |
char *__PHYSFS_platformCalcBaseDir(const char *argv0) |
|
139 |
{ |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
140 |
return(getExePath()); |
501 | 141 |
} /* __PHYSFS_platformCalcBaseDir */ |
142 |
||
143 |
||
144 |
char *__PHYSFS_platformGetUserName(void) |
|
145 |
{ |
|
146 |
BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL); |
|
147 |
} /* __PHYSFS_platformGetUserName */ |
|
148 |
||
149 |
||
150 |
char *__PHYSFS_platformGetUserDir(void) |
|
151 |
{ |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
152 |
return userDir; |
501 | 153 |
BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL); |
154 |
} /* __PHYSFS_platformGetUserDir */ |
|
155 |
||
156 |
||
157 |
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void) |
|
158 |
{ |
|
159 |
return(1); /* single threaded. */ |
|
160 |
} /* __PHYSFS_platformGetThreadID */ |
|
161 |
||
162 |
||
163 |
int __PHYSFS_platformStricmp(const char *x, const char *y) |
|
164 |
{ |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
165 |
return(_stricmp(x, y)); |
596
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
578
diff
changeset
|
166 |
} /* __PHYSFS_platformStricmp */ |
501 | 167 |
|
596
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
578
diff
changeset
|
168 |
|
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
578
diff
changeset
|
169 |
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:
578
diff
changeset
|
170 |
{ |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
578
diff
changeset
|
171 |
return(_strnicmp(x, y, (int) len)); |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
578
diff
changeset
|
172 |
} /* __PHYSFS_platformStrnicmp */ |
501 | 173 |
|
174 |
||
175 |
int __PHYSFS_platformExists(const char *fname) |
|
176 |
{ |
|
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
177 |
int retval = 0; |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
178 |
wchar_t *w_fname = NULL; |
501 | 179 |
|
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
180 |
UTF8_TO_UNICODE_STACK_MACRO(w_fname, fname); |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
181 |
if (w_fname != NULL) |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
182 |
retval = (GetFileAttributes(w_fname) != INVALID_FILE_ATTRIBUTES); |
501 | 183 |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
184 |
return(retval); |
501 | 185 |
} /* __PHYSFS_platformExists */ |
186 |
||
187 |
||
188 |
int __PHYSFS_platformIsSymLink(const char *fname) |
|
189 |
{ |
|
190 |
BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0); |
|
191 |
} /* __PHYSFS_platformIsSymlink */ |
|
192 |
||
193 |
||
194 |
int __PHYSFS_platformIsDirectory(const char *fname) |
|
195 |
{ |
|
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
196 |
int retval = 0; |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
197 |
wchar_t *w_fname = NULL; |
501 | 198 |
|
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
199 |
UTF8_TO_UNICODE_STACK_MACRO(w_fname, fname); |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
200 |
if (w_fname != NULL) |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
201 |
retval = ((GetFileAttributes(w_fname) & FILE_ATTRIBUTE_DIRECTORY) != 0); |
501 | 202 |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
203 |
return(retval); |
501 | 204 |
} /* __PHYSFS_platformIsDirectory */ |
205 |
||
206 |
||
207 |
char *__PHYSFS_platformCvtToDependent(const char *prepend, |
|
208 |
const char *dirName, |
|
209 |
const char *append) |
|
210 |
{ |
|
211 |
int len = ((prepend) ? strlen(prepend) : 0) + |
|
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
212 |
((append) ? strlen(append) : 0) + |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
213 |
strlen(dirName) + 1; |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
214 |
char *retval = (char *) allocator.Malloc(len); |
501 | 215 |
char *p; |
216 |
||
217 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
|
218 |
||
219 |
if (prepend) |
|
220 |
strcpy(retval, prepend); |
|
221 |
else |
|
222 |
retval[0] = '\0'; |
|
223 |
||
224 |
strcat(retval, dirName); |
|
225 |
||
226 |
if (append) |
|
227 |
strcat(retval, append); |
|
228 |
||
229 |
for (p = strchr(retval, '/'); p != NULL; p = strchr(p + 1, '/')) |
|
230 |
*p = '\\'; |
|
231 |
||
232 |
return(retval); |
|
233 |
} /* __PHYSFS_platformCvtToDependent */ |
|
234 |
||
235 |
||
236 |
void __PHYSFS_platformTimeslice(void) |
|
237 |
{ |
|
238 |
Sleep(10); |
|
239 |
} /* __PHYSFS_platformTimeslice */ |
|
240 |
||
241 |
||
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
242 |
static int doEnumCallback(const wchar_t *w_fname) |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
243 |
{ |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
244 |
const PHYSFS_uint64 len = (PHYSFS_uint64) ((wcslen(w_fname) * 4) + 1); |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
245 |
char *str = (char *) alloca(len); |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
246 |
PHYSFS_utf8fromucs2((const PHYSFS_uint16 *) w_fname, str, len); |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
247 |
callback(callbackdata, origdir, str); |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
248 |
return 1; |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
249 |
} /* doEnumCallback */ |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
250 |
|
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
251 |
|
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
651
diff
changeset
|
252 |
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:
651
diff
changeset
|
253 |
int omitSymLinks, |
754
e7cd7411eadf
API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents:
747
diff
changeset
|
254 |
PHYSFS_EnumFilesCallback callback, |
e7cd7411eadf
API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents:
747
diff
changeset
|
255 |
const char *origdir, |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
651
diff
changeset
|
256 |
void *callbackdata) |
501 | 257 |
{ |
258 |
HANDLE dir; |
|
259 |
WIN32_FIND_DATA ent; |
|
260 |
char *SearchPath; |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
261 |
wchar_t *w_SearchPath; |
501 | 262 |
size_t len = strlen(dirname); |
263 |
||
264 |
/* Allocate a new string for path, maybe '\\', "*", and NULL terminator */ |
|
265 |
SearchPath = (char *) alloca(len + 3); |
|
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
266 |
BAIL_IF_MACRO(SearchPath == NULL, ERR_OUT_OF_MEMORY, NULL); |
501 | 267 |
|
268 |
/* Copy current dirname */ |
|
269 |
strcpy(SearchPath, dirname); |
|
270 |
||
271 |
/* if there's no '\\' at the end of the path, stick one in there. */ |
|
272 |
if (SearchPath[len - 1] != '\\') |
|
273 |
{ |
|
274 |
SearchPath[len++] = '\\'; |
|
275 |
SearchPath[len] = '\0'; |
|
276 |
} /* if */ |
|
277 |
||
278 |
/* Append the "*" to the end of the string */ |
|
279 |
strcat(SearchPath, "*"); |
|
280 |
||
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
281 |
UTF8_TO_UNICODE_STACK_MACRO(w_SearchPath, SearchPath); |
501 | 282 |
dir = FindFirstFile(w_SearchPath, &ent); |
283 |
||
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
651
diff
changeset
|
284 |
if (dir == INVALID_HANDLE_VALUE) |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
651
diff
changeset
|
285 |
return; |
501 | 286 |
|
287 |
do |
|
288 |
{ |
|
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
289 |
const char *str = NULL; |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
651
diff
changeset
|
290 |
|
501 | 291 |
if (wcscmp(ent.cFileName, L".") == 0) |
292 |
continue; |
|
293 |
||
294 |
if (wcscmp(ent.cFileName, L"..") == 0) |
|
295 |
continue; |
|
296 |
||
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
297 |
if (!doEnumCallback(ent.cFileName)) |
501 | 298 |
break; |
299 |
} while (FindNextFile(dir, &ent) != 0); |
|
300 |
||
301 |
FindClose(dir); |
|
302 |
} /* __PHYSFS_platformEnumerateFiles */ |
|
303 |
||
304 |
||
305 |
char *__PHYSFS_platformCurrentDir(void) |
|
306 |
{ |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
307 |
return("\\"); |
501 | 308 |
} /* __PHYSFS_platformCurrentDir */ |
309 |
||
310 |
||
311 |
char *__PHYSFS_platformRealPath(const char *path) |
|
312 |
{ |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
313 |
char *retval = (char *) allocator.Malloc(strlen(path) + 1); |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
314 |
strcpy(retval,path); |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
315 |
return(retval); |
501 | 316 |
} /* __PHYSFS_platformRealPath */ |
317 |
||
318 |
||
319 |
int __PHYSFS_platformMkDir(const char *path) |
|
320 |
{ |
|
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
321 |
wchar_t *w_path = NULL; |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
322 |
UTF8_TO_UNICODE_STACK_MACRO(w_path, path); |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
323 |
return ( (w_path != NULL) && (CreateDirectory(w_path, NULL)) ); |
501 | 324 |
} /* __PHYSFS_platformMkDir */ |
325 |
||
326 |
||
327 |
static void *doOpen(const char *fname, DWORD mode, DWORD creation, int rdonly) |
|
328 |
{ |
|
329 |
HANDLE fileHandle; |
|
330 |
winCEfile *retval; |
|
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
331 |
wchar_t *w_fname = NULL; |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
332 |
|
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
333 |
UTF8_TO_UNICODE_STACK_MACRO(w_fname, fname); |
501 | 334 |
|
335 |
fileHandle = CreateFile(w_fname, mode, FILE_SHARE_READ, NULL, |
|
336 |
creation, FILE_ATTRIBUTE_NORMAL, NULL); |
|
337 |
||
338 |
BAIL_IF_MACRO(fileHandle == INVALID_HANDLE_VALUE, win32strerror(), NULL); |
|
339 |
||
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
340 |
retval = (winCEfile *) allocator.Malloc(sizeof (winCEfile)); |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
341 |
if (retval == NULL) |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
342 |
{ |
792
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
343 |
CloseHandle(fileHandle); |
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
344 |
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
345 |
} /* if */ |
501 | 346 |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
347 |
retval->readonly = rdonly; |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
348 |
retval->handle = fileHandle; |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
349 |
return(retval); |
501 | 350 |
} /* doOpen */ |
351 |
||
352 |
||
353 |
void *__PHYSFS_platformOpenRead(const char *filename) |
|
354 |
{ |
|
355 |
return(doOpen(filename, GENERIC_READ, OPEN_EXISTING, 1)); |
|
356 |
} /* __PHYSFS_platformOpenRead */ |
|
357 |
||
358 |
||
359 |
void *__PHYSFS_platformOpenWrite(const char *filename) |
|
360 |
{ |
|
361 |
return(doOpen(filename, GENERIC_WRITE, CREATE_ALWAYS, 0)); |
|
362 |
} /* __PHYSFS_platformOpenWrite */ |
|
363 |
||
364 |
||
365 |
void *__PHYSFS_platformOpenAppend(const char *filename) |
|
366 |
{ |
|
367 |
void *retval = doOpen(filename, GENERIC_WRITE, OPEN_ALWAYS, 0); |
|
368 |
if (retval != NULL) |
|
369 |
{ |
|
370 |
HANDLE h = ((winCEfile *) retval)->handle; |
|
371 |
if (SetFilePointer(h, 0, NULL, FILE_END) == INVALID_SET_FILE_POINTER) |
|
372 |
{ |
|
373 |
const char *err = win32strerror(); |
|
374 |
CloseHandle(h); |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
375 |
allocator.Free(retval); |
501 | 376 |
BAIL_MACRO(err, NULL); |
377 |
} /* if */ |
|
378 |
} /* if */ |
|
379 |
||
380 |
return(retval); |
|
381 |
||
382 |
} /* __PHYSFS_platformOpenAppend */ |
|
383 |
||
384 |
||
385 |
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer, |
|
386 |
PHYSFS_uint32 size, PHYSFS_uint32 count) |
|
387 |
{ |
|
651
cbe4ea4c7e8e
Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
388 |
HANDLE Handle = ((winCEfile *) opaque)->handle; |
501 | 389 |
DWORD CountOfBytesRead; |
390 |
PHYSFS_sint64 retval; |
|
391 |
||
392 |
/* Read data from the file */ |
|
393 |
/*!!! - uint32 might be a greater # than DWORD */ |
|
651
cbe4ea4c7e8e
Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
394 |
if (!ReadFile(Handle, buffer, count * size, &CountOfBytesRead, NULL)) |
501 | 395 |
{ |
651
cbe4ea4c7e8e
Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
396 |
retval = -1; |
501 | 397 |
} /* if */ |
398 |
else |
|
399 |
{ |
|
400 |
/* Return the number of "objects" read. */ |
|
401 |
/* !!! - What if not the right amount of bytes was read to make an object? */ |
|
402 |
retval = CountOfBytesRead / size; |
|
403 |
} /* else */ |
|
404 |
||
405 |
return(retval); |
|
406 |
||
407 |
} /* __PHYSFS_platformRead */ |
|
408 |
||
409 |
||
410 |
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer, |
|
411 |
PHYSFS_uint32 size, PHYSFS_uint32 count) |
|
412 |
{ |
|
651
cbe4ea4c7e8e
Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
413 |
HANDLE Handle = ((winCEfile *) opaque)->handle; |
501 | 414 |
DWORD CountOfBytesWritten; |
415 |
PHYSFS_sint64 retval; |
|
416 |
||
417 |
/* Read data from the file */ |
|
418 |
/*!!! - uint32 might be a greater # than DWORD */ |
|
651
cbe4ea4c7e8e
Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
419 |
if (!WriteFile(Handle, buffer, count * size, &CountOfBytesWritten, NULL)) |
501 | 420 |
{ |
651
cbe4ea4c7e8e
Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
421 |
retval = -1; |
501 | 422 |
} /* if */ |
423 |
else |
|
424 |
{ |
|
425 |
/* Return the number of "objects" read. */ |
|
426 |
/*!!! - What if not the right number of bytes was written? */ |
|
427 |
retval = CountOfBytesWritten / size; |
|
428 |
} /* else */ |
|
429 |
||
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
430 |
return(retval); |
501 | 431 |
|
432 |
} /* __PHYSFS_platformWrite */ |
|
433 |
||
434 |
||
435 |
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos) |
|
436 |
{ |
|
651
cbe4ea4c7e8e
Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
437 |
HANDLE Handle = ((winCEfile *) opaque)->handle; |
501 | 438 |
DWORD HighOrderPos; |
439 |
DWORD rc; |
|
440 |
||
441 |
/* Get the high order 32-bits of the position */ |
|
442 |
//HighOrderPos = HIGHORDER_UINT64(pos); |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
443 |
HighOrderPos = (unsigned long)(pos>>32); |
501 | 444 |
|
445 |
/*!!! SetFilePointer needs a signed 64-bit value. */ |
|
446 |
/* Move pointer "pos" count from start of file */ |
|
651
cbe4ea4c7e8e
Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
447 |
rc = SetFilePointer(Handle, (unsigned long)(pos&0x00000000ffffffff), |
501 | 448 |
&HighOrderPos, FILE_BEGIN); |
449 |
||
450 |
if ((rc == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR)) |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
451 |
{ |
501 | 452 |
BAIL_MACRO(win32strerror(), 0); |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
453 |
} |
501 | 454 |
|
455 |
return(1); /* No error occured */ |
|
456 |
} /* __PHYSFS_platformSeek */ |
|
457 |
||
458 |
||
459 |
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque) |
|
460 |
{ |
|
651
cbe4ea4c7e8e
Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
461 |
HANDLE Handle = ((winCEfile *) opaque)->handle; |
501 | 462 |
DWORD HighPos = 0; |
463 |
DWORD LowPos; |
|
464 |
PHYSFS_sint64 retval; |
|
465 |
||
466 |
/* Get current position */ |
|
651
cbe4ea4c7e8e
Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
467 |
LowPos = SetFilePointer(Handle, 0, &HighPos, FILE_CURRENT); |
501 | 468 |
if ((LowPos == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR)) |
469 |
{ |
|
470 |
BAIL_MACRO(win32strerror(), 0); |
|
471 |
} /* if */ |
|
472 |
else |
|
473 |
{ |
|
474 |
/* Combine the high/low order to create the 64-bit position value */ |
|
475 |
retval = (((PHYSFS_uint64) HighPos) << 32) | LowPos; |
|
476 |
//assert(retval >= 0); |
|
477 |
} /* else */ |
|
478 |
||
479 |
return(retval); |
|
480 |
} /* __PHYSFS_platformTell */ |
|
481 |
||
482 |
||
483 |
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque) |
|
484 |
{ |
|
651
cbe4ea4c7e8e
Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
485 |
HANDLE Handle = ((winCEfile *) opaque)->handle; |
501 | 486 |
DWORD SizeHigh; |
487 |
DWORD SizeLow; |
|
488 |
PHYSFS_sint64 retval; |
|
489 |
||
651
cbe4ea4c7e8e
Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
490 |
SizeLow = GetFileSize(Handle, &SizeHigh); |
501 | 491 |
if ((SizeLow == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR)) |
492 |
{ |
|
493 |
BAIL_MACRO(win32strerror(), -1); |
|
494 |
} /* if */ |
|
495 |
else |
|
496 |
{ |
|
497 |
/* Combine the high/low order to create the 64-bit position value */ |
|
498 |
retval = (((PHYSFS_uint64) SizeHigh) << 32) | SizeLow; |
|
499 |
//assert(retval >= 0); |
|
500 |
} /* else */ |
|
501 |
||
502 |
return(retval); |
|
503 |
} /* __PHYSFS_platformFileLength */ |
|
504 |
||
505 |
||
506 |
int __PHYSFS_platformEOF(void *opaque) |
|
507 |
{ |
|
508 |
PHYSFS_sint64 FilePosition; |
|
509 |
int retval = 0; |
|
510 |
||
511 |
/* Get the current position in the file */ |
|
512 |
if ((FilePosition = __PHYSFS_platformTell(opaque)) != 0) |
|
513 |
{ |
|
514 |
/* Non-zero if EOF is equal to the file length */ |
|
515 |
retval = FilePosition == __PHYSFS_platformFileLength(opaque); |
|
516 |
} /* if */ |
|
517 |
||
518 |
return(retval); |
|
519 |
} /* __PHYSFS_platformEOF */ |
|
520 |
||
521 |
||
522 |
int __PHYSFS_platformFlush(void *opaque) |
|
523 |
{ |
|
524 |
winCEfile *fh = ((winCEfile *) opaque); |
|
525 |
if (!fh->readonly) |
|
526 |
BAIL_IF_MACRO(!FlushFileBuffers(fh->handle), win32strerror(), 0); |
|
527 |
||
528 |
return(1); |
|
529 |
} /* __PHYSFS_platformFlush */ |
|
530 |
||
531 |
||
532 |
int __PHYSFS_platformClose(void *opaque) |
|
533 |
{ |
|
651
cbe4ea4c7e8e
Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
534 |
HANDLE Handle = ((winCEfile *) opaque)->handle; |
cbe4ea4c7e8e
Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
535 |
BAIL_IF_MACRO(!CloseHandle(Handle), win32strerror(), 0); |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
536 |
allocator.Free(opaque); |
501 | 537 |
return(1); |
538 |
} /* __PHYSFS_platformClose */ |
|
539 |
||
540 |
||
541 |
int __PHYSFS_platformDelete(const char *path) |
|
542 |
{ |
|
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
543 |
wchar_t *w_path = NULL; |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
544 |
UTF8_TO_UNICODE_STACK_MACRO(w_path, path); |
501 | 545 |
|
546 |
/* If filename is a folder */ |
|
547 |
if (GetFileAttributes(w_path) == FILE_ATTRIBUTE_DIRECTORY) |
|
548 |
{ |
|
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
549 |
int retval = !RemoveDirectory(w_path); |
501 | 550 |
BAIL_IF_MACRO(retval, win32strerror(), 0); |
551 |
} /* if */ |
|
552 |
else |
|
553 |
{ |
|
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
554 |
int retval = !DeleteFile(w_path); |
501 | 555 |
BAIL_IF_MACRO(retval, win32strerror(), 0); |
556 |
} /* else */ |
|
557 |
||
558 |
return(1); /* if you got here, it worked. */ |
|
559 |
} /* __PHYSFS_platformDelete */ |
|
560 |
||
561 |
||
562 |
void *__PHYSFS_platformCreateMutex(void) |
|
563 |
{ |
|
564 |
return((void *) CreateMutex(NULL, FALSE, NULL)); |
|
565 |
} /* __PHYSFS_platformCreateMutex */ |
|
566 |
||
567 |
||
568 |
void __PHYSFS_platformDestroyMutex(void *mutex) |
|
569 |
{ |
|
570 |
CloseHandle((HANDLE) mutex); |
|
571 |
} /* __PHYSFS_platformDestroyMutex */ |
|
572 |
||
573 |
||
574 |
int __PHYSFS_platformGrabMutex(void *mutex) |
|
575 |
{ |
|
576 |
return(WaitForSingleObject((HANDLE) mutex, INFINITE) != WAIT_FAILED); |
|
577 |
} /* __PHYSFS_platformGrabMutex */ |
|
578 |
||
579 |
||
580 |
void __PHYSFS_platformReleaseMutex(void *mutex) |
|
581 |
{ |
|
582 |
ReleaseMutex((HANDLE) mutex); |
|
583 |
} /* __PHYSFS_platformReleaseMutex */ |
|
584 |
||
585 |
||
586 |
PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname) |
|
587 |
{ |
|
588 |
BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1); |
|
589 |
} /* __PHYSFS_platformGetLastModTime */ |
|
590 |
||
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
591 |
|
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
592 |
/* !!! FIXME: Don't use C runtime for allocators? */ |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
593 |
int __PHYSFS_platformAllocatorInit(void) |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
594 |
{ |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
595 |
return(1); /* always succeeds. */ |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
596 |
} /* __PHYSFS_platformAllocatorInit */ |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
597 |
|
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
598 |
|
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
599 |
void __PHYSFS_platformAllocatorDeinit(void) |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
600 |
{ |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
601 |
/* no-op */ |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
602 |
} /* __PHYSFS_platformAllocatorInit */ |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
603 |
|
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
604 |
|
747
3da194b12f43
Don't use size_t in physfs.h, since it relies on C runtime headers.
Ryan C. Gordon <icculus@icculus.org>
parents:
691
diff
changeset
|
605 |
void *__PHYSFS_platformAllocatorMalloc(PHYSFS_uint64 s) |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
606 |
{ |
763
efadd9cdb6a4
Cleaned up overflow checks in platform memory allocators (thanks to Nicolas
Ryan C. Gordon <icculus@icculus.org>
parents:
754
diff
changeset
|
607 |
BAIL_IF_MACRO(__PHYSFS_ui64FitsAddressSpace(s), ERR_OUT_OF_MEMORY, NULL); |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
608 |
#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:
691
diff
changeset
|
609 |
return(malloc((size_t) s)); |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
610 |
} /* __PHYSFS_platformMalloc */ |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
611 |
|
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
612 |
|
747
3da194b12f43
Don't use size_t in physfs.h, since it relies on C runtime headers.
Ryan C. Gordon <icculus@icculus.org>
parents:
691
diff
changeset
|
613 |
void *__PHYSFS_platformAllocatorRealloc(void *ptr, PHYSFS_uint64 s) |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
614 |
{ |
763
efadd9cdb6a4
Cleaned up overflow checks in platform memory allocators (thanks to Nicolas
Ryan C. Gordon <icculus@icculus.org>
parents:
754
diff
changeset
|
615 |
BAIL_IF_MACRO(__PHYSFS_ui64FitsAddressSpace(s), ERR_OUT_OF_MEMORY, NULL); |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
616 |
#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:
691
diff
changeset
|
617 |
return(realloc(ptr, (size_t) s)); |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
618 |
} /* __PHYSFS_platformRealloc */ |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
619 |
|
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
620 |
|
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
621 |
void __PHYSFS_platformAllocatorFree(void *ptr) |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
622 |
{ |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
623 |
#undef free |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
624 |
free(ptr); |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
625 |
} /* __PHYSFS_platformAllocatorFree */ |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
626 |
|
673
983fb6750fdd
Fixed incorrect comment.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
627 |
/* end of pocketpc.c ... */ |
501 | 628 |