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