Skip to content

Latest commit

 

History

History
689 lines (530 loc) · 16.6 KB

pocketpc.c

File metadata and controls

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