platform_pocketpc.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. /*
  2. * PocketPC support routines for PhysicsFS.
  3. *
  4. * Please see the file LICENSE.txt in the source's root directory.
  5. *
  6. * This file written by Ryan C. Gordon.
  7. */
  8. #define __PHYSICSFS_INTERNAL__
  9. #include "physfs_platforms.h"
  10. #ifdef PHYSFS_PLATFORM_POCKETPC
  11. #include <windows.h>
  12. #include "physfs_internal.h"
  13. #define INVALID_FILE_ATTRIBUTES 0xFFFFFFFF
  14. #define INVALID_SET_FILE_POINTER 0xFFFFFFFF
  15. typedef struct
  16. {
  17. HANDLE handle;
  18. int readonly;
  19. } winCEfile;
  20. const char *__PHYSFS_platformDirSeparator = "\\";
  21. static char *userDir = NULL;
  22. /*
  23. * Figure out what the last failing Win32 API call was, and
  24. * generate a human-readable string for the error message.
  25. *
  26. * The return value is a static buffer that is overwritten with
  27. * each call to this function.
  28. */
  29. static const char *win32strerror(void)
  30. {
  31. static TCHAR msgbuf[255];
  32. TCHAR *ptr = msgbuf;
  33. FormatMessage(
  34. FORMAT_MESSAGE_FROM_SYSTEM |
  35. FORMAT_MESSAGE_IGNORE_INSERTS,
  36. NULL,
  37. GetLastError(),
  38. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
  39. msgbuf,
  40. sizeof (msgbuf) / sizeof (TCHAR),
  41. NULL
  42. );
  43. /* chop off newlines. */
  44. for (ptr = msgbuf; *ptr; ptr++)
  45. {
  46. if ((*ptr == '\n') || (*ptr == '\r'))
  47. {
  48. *ptr = ' ';
  49. break;
  50. } /* if */
  51. } /* for */
  52. return ((const char *) msgbuf);
  53. } /* win32strerror */
  54. /* !!! FIXME: need to check all of these for NULLs. */
  55. #define UTF8_TO_UNICODE_STACK_MACRO(w_assignto, str) { \
  56. if (str == NULL) \
  57. w_assignto = NULL; \
  58. else { \
  59. const PHYSFS_uint64 len = (PHYSFS_uint64) ((strlen(str) * 4) + 1); \
  60. w_assignto = (char *) __PHYSFS_smallAlloc(len); \
  61. PHYSFS_uc2fromutf8(str, (PHYSFS_uint16 *) w_assignto, len); \
  62. } \
  63. } \
  64. static char *getExePath()
  65. {
  66. DWORD buflen;
  67. int success = 0;
  68. TCHAR *ptr = NULL;
  69. TCHAR *retval = (TCHAR*) allocator.Malloc(sizeof (TCHAR) * (MAX_PATH + 1));
  70. char *charretval;
  71. BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
  72. retval[0] = _T('\0');
  73. /* !!! FIXME: don't preallocate here? */
  74. /* !!! FIXME: use smallAlloc? */
  75. buflen = GetModuleFileName(NULL, retval, MAX_PATH + 1);
  76. if (buflen <= 0)
  77. __PHYSFS_setError(win32strerror());
  78. else
  79. {
  80. retval[buflen] = '\0'; /* does API always null-terminate this? */
  81. ptr = retval+buflen;
  82. while( ptr != retval )
  83. {
  84. if( *ptr != _T('\\') )
  85. *ptr-- = _T('\0');
  86. else
  87. break;
  88. } /* while */
  89. success = 1;
  90. } /* else */
  91. if (!success)
  92. {
  93. allocator.Free(retval);
  94. return NULL; /* physfs error message will be set, above. */
  95. } /* if */
  96. buflen = (buflen * 4) + 1;
  97. charretval = (char *) allocator.Malloc(buflen);
  98. if (charretval != NULL)
  99. PHYSFS_utf8fromucs2((const PHYSFS_uint16 *) retval, charretval, buflen);
  100. allocator.Free(retval);
  101. return charretval; /* w00t. */
  102. } /* getExePath */
  103. int __PHYSFS_platformInit(void)
  104. {
  105. userDir = getExePath();
  106. BAIL_IF_MACRO(userDir == NULL, NULL, 0); /* failed? */
  107. return 1; /* always succeed. */
  108. } /* __PHYSFS_platformInit */
  109. int __PHYSFS_platformDeinit(void)
  110. {
  111. allocator.Free(userDir);
  112. return 1; /* always succeed. */
  113. } /* __PHYSFS_platformDeinit */
  114. void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
  115. {
  116. /* no-op on this platform. */
  117. } /* __PHYSFS_platformDetectAvailableCDs */
  118. char *__PHYSFS_platformCalcBaseDir(const char *argv0)
  119. {
  120. return getExePath();
  121. } /* __PHYSFS_platformCalcBaseDir */
  122. char *__PHYSFS_platformGetUserName(void)
  123. {
  124. BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
  125. } /* __PHYSFS_platformGetUserName */
  126. char *__PHYSFS_platformGetUserDir(void)
  127. {
  128. return userDir;
  129. BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
  130. } /* __PHYSFS_platformGetUserDir */
  131. void *__PHYSFS_platformGetThreadID(void)
  132. {
  133. return ((void *)1); /* single threaded. */ /* !!! FIXME: is this true? */
  134. } /* __PHYSFS_platformGetThreadID */
  135. char *__PHYSFS_platformCvtToDependent(const char *prepend,
  136. const char *dirName,
  137. const char *append)
  138. {
  139. int len = ((prepend) ? strlen(prepend) : 0) +
  140. ((append) ? strlen(append) : 0) +
  141. strlen(dirName) + 1;
  142. char *retval = (char *) allocator.Malloc(len);
  143. char *p;
  144. BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
  145. if (prepend)
  146. strcpy(retval, prepend);
  147. else
  148. retval[0] = '\0';
  149. strcat(retval, dirName);
  150. if (append)
  151. strcat(retval, append);
  152. for (p = strchr(retval, '/'); p != NULL; p = strchr(p + 1, '/'))
  153. *p = '\\';
  154. return retval;
  155. } /* __PHYSFS_platformCvtToDependent */
  156. static int doEnumCallback(const wchar_t *w_fname)
  157. {
  158. const PHYSFS_uint64 len = (PHYSFS_uint64) ((wcslen(w_fname) * 4) + 1);
  159. char *str = (char *) __PHYSFS_smallAlloc(len);
  160. PHYSFS_utf8fromucs2((const PHYSFS_uint16 *) w_fname, str, len);
  161. callback(callbackdata, origdir, str);
  162. __PHYSFS_smallFree(str);
  163. return 1;
  164. } /* doEnumCallback */
  165. void __PHYSFS_platformEnumerateFiles(const char *dirname,
  166. int omitSymLinks,
  167. PHYSFS_EnumFilesCallback callback,
  168. const char *origdir,
  169. void *callbackdata)
  170. {
  171. HANDLE dir;
  172. WIN32_FIND_DATA ent;
  173. char *SearchPath;
  174. wchar_t *w_SearchPath;
  175. size_t len = strlen(dirname);
  176. /* Allocate a new string for path, maybe '\\', "*", and NULL terminator */
  177. SearchPath = (char *) __PHYSFS_smallAlloc(len + 3);
  178. BAIL_IF_MACRO(SearchPath == NULL, ERR_OUT_OF_MEMORY, NULL);
  179. /* Copy current dirname */
  180. strcpy(SearchPath, dirname);
  181. /* if there's no '\\' at the end of the path, stick one in there. */
  182. if (SearchPath[len - 1] != '\\')
  183. {
  184. SearchPath[len++] = '\\';
  185. SearchPath[len] = '\0';
  186. } /* if */
  187. /* Append the "*" to the end of the string */
  188. strcat(SearchPath, "*");
  189. UTF8_TO_UNICODE_STACK_MACRO(w_SearchPath, SearchPath);
  190. __PHYSFS_smallFree(SearchPath);
  191. dir = FindFirstFile(w_SearchPath, &ent);
  192. __PHYSFS_smallFree(w_SearchPath);
  193. if (dir == INVALID_HANDLE_VALUE)
  194. return;
  195. do
  196. {
  197. const char *str = NULL;
  198. if (wcscmp(ent.cFileName, L".") == 0)
  199. continue;
  200. if (wcscmp(ent.cFileName, L"..") == 0)
  201. continue;
  202. if (!doEnumCallback(ent.cFileName))
  203. break;
  204. } while (FindNextFile(dir, &ent) != 0);
  205. FindClose(dir);
  206. } /* __PHYSFS_platformEnumerateFiles */
  207. char *__PHYSFS_platformCurrentDir(void)
  208. {
  209. return "\\";
  210. } /* __PHYSFS_platformCurrentDir */
  211. char *__PHYSFS_platformRealPath(const char *path)
  212. {
  213. char *retval = (char *) allocator.Malloc(strlen(path) + 1);
  214. strcpy(retval,path);
  215. return retval;
  216. } /* __PHYSFS_platformRealPath */
  217. int __PHYSFS_platformMkDir(const char *path)
  218. {
  219. int retval = 0;
  220. wchar_t *w_path = NULL;
  221. UTF8_TO_UNICODE_STACK_MACRO(w_path, path);
  222. if (w_path != NULL)
  223. {
  224. retval = CreateDirectory(w_path, NULL);
  225. __PHYSFS_smallFree(w_fname);
  226. } /* if */
  227. return retval;
  228. } /* __PHYSFS_platformMkDir */
  229. static void *doOpen(const char *fname, DWORD mode, DWORD creation, int rdonly)
  230. {
  231. HANDLE fileHandle;
  232. winCEfile *retval;
  233. wchar_t *w_fname = NULL;
  234. UTF8_TO_UNICODE_STACK_MACRO(w_fname, fname);
  235. fileHandle = CreateFile(w_fname, mode, FILE_SHARE_READ | FILE_SHARE_WRITE,
  236. NULL, creation, FILE_ATTRIBUTE_NORMAL, NULL);
  237. __PHYSFS_smallFree(w_fname);
  238. BAIL_IF_MACRO(fileHandle == INVALID_HANDLE_VALUE, win32strerror(), NULL);
  239. retval = (winCEfile *) allocator.Malloc(sizeof (winCEfile));
  240. if (retval == NULL)
  241. {
  242. CloseHandle(fileHandle);
  243. BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
  244. } /* if */
  245. retval->readonly = rdonly;
  246. retval->handle = fileHandle;
  247. return retval;
  248. } /* doOpen */
  249. void *__PHYSFS_platformOpenRead(const char *filename)
  250. {
  251. return doOpen(filename, GENERIC_READ, OPEN_EXISTING, 1);
  252. } /* __PHYSFS_platformOpenRead */
  253. void *__PHYSFS_platformOpenWrite(const char *filename)
  254. {
  255. return doOpen(filename, GENERIC_WRITE, CREATE_ALWAYS, 0);
  256. } /* __PHYSFS_platformOpenWrite */
  257. void *__PHYSFS_platformOpenAppend(const char *filename)
  258. {
  259. void *retval = doOpen(filename, GENERIC_WRITE, OPEN_ALWAYS, 0);
  260. if (retval != NULL)
  261. {
  262. HANDLE h = ((winCEfile *) retval)->handle;
  263. if (SetFilePointer(h, 0, NULL, FILE_END) == INVALID_SET_FILE_POINTER)
  264. {
  265. const char *err = win32strerror();
  266. CloseHandle(h);
  267. allocator.Free(retval);
  268. BAIL_MACRO(err, NULL);
  269. } /* if */
  270. } /* if */
  271. return retval;
  272. } /* __PHYSFS_platformOpenAppend */
  273. PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buf, PHYSFS_uint64 len)
  274. {
  275. HANDLE Handle = ((winCEfile *) opaque)->handle;
  276. DWORD CountOfBytesRead = 0;
  277. BAIL_IF_MACRO(!__PHYSFS_ui64FitsAddressSpace(len),ERR_INVALID_ARGUMENT,-1);
  278. if (!ReadFile(Handle, buf, (DWORD) len, &CountOfBytesRead, NULL))
  279. return -1; /* !!! FIXME: set an error string? */
  280. return (PHYSFS_sint64) CountOfBytesRead;
  281. } /* __PHYSFS_platformRead */
  282. PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
  283. PHYSFS_uint64 len)
  284. {
  285. HANDLE Handle = ((winCEfile *) opaque)->handle;
  286. DWORD CountOfBytesWritten = 0;
  287. BAIL_IF_MACRO(!__PHYSFS_ui64FitsAddressSpace(len),ERR_INVALID_ARGUMENT,-1);
  288. if (!WriteFile(Handle, buffer, (DWORD) len, &CountOfBytesWritten, NULL))
  289. return -1;
  290. return PHYSFS_sint64) CountOfBytesWritten;
  291. } /* __PHYSFS_platformWrite */
  292. int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
  293. {
  294. HANDLE Handle = ((winCEfile *) opaque)->handle;
  295. DWORD HighOrderPos;
  296. DWORD rc;
  297. /* Get the high order 32-bits of the position */
  298. /*HighOrderPos = HIGHORDER_UINT64(pos);*/
  299. HighOrderPos = (unsigned long)(pos>>32);
  300. /*!!! SetFilePointer needs a signed 64-bit value. */
  301. /* Move pointer "pos" count from start of file */
  302. rc = SetFilePointer(Handle, (unsigned long)(pos&0x00000000ffffffff),
  303. &HighOrderPos, FILE_BEGIN);
  304. if ((rc == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
  305. {
  306. BAIL_MACRO(win32strerror(), 0);
  307. }
  308. return 1; /* No error occured */
  309. } /* __PHYSFS_platformSeek */
  310. PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
  311. {
  312. HANDLE Handle = ((winCEfile *) opaque)->handle;
  313. DWORD HighPos = 0;
  314. DWORD LowPos;
  315. PHYSFS_sint64 retval;
  316. /* Get current position */
  317. LowPos = SetFilePointer(Handle, 0, &HighPos, FILE_CURRENT);
  318. if ((LowPos == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
  319. {
  320. BAIL_MACRO(win32strerror(), 0);
  321. } /* if */
  322. else
  323. {
  324. /* Combine the high/low order to create the 64-bit position value */
  325. retval = (((PHYSFS_uint64) HighPos) << 32) | LowPos;
  326. /*assert(retval >= 0);*/
  327. } /* else */
  328. return retval;
  329. } /* __PHYSFS_platformTell */
  330. PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
  331. {
  332. HANDLE Handle = ((winCEfile *) opaque)->handle;
  333. DWORD SizeHigh;
  334. DWORD SizeLow;
  335. PHYSFS_sint64 retval;
  336. SizeLow = GetFileSize(Handle, &SizeHigh);
  337. if ((SizeLow == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
  338. {
  339. BAIL_MACRO(win32strerror(), -1);
  340. } /* if */
  341. else
  342. {
  343. /* Combine the high/low order to create the 64-bit position value */
  344. retval = (((PHYSFS_uint64) SizeHigh) << 32) | SizeLow;
  345. /*assert(retval >= 0);*/
  346. } /* else */
  347. return retval;
  348. } /* __PHYSFS_platformFileLength */
  349. int __PHYSFS_platformEOF(void *opaque)
  350. {
  351. PHYSFS_sint64 FilePosition;
  352. int retval = 0;
  353. /* Get the current position in the file */
  354. if ((FilePosition = __PHYSFS_platformTell(opaque)) != 0)
  355. {
  356. /* Non-zero if EOF is equal to the file length */
  357. retval = FilePosition == __PHYSFS_platformFileLength(opaque);
  358. } /* if */
  359. return retval;
  360. } /* __PHYSFS_platformEOF */
  361. int __PHYSFS_platformFlush(void *opaque)
  362. {
  363. winCEfile *fh = ((winCEfile *) opaque);
  364. if (!fh->readonly)
  365. BAIL_IF_MACRO(!FlushFileBuffers(fh->handle), win32strerror(), 0);
  366. return 1;
  367. } /* __PHYSFS_platformFlush */
  368. void __PHYSFS_platformClose(void *opaque)
  369. {
  370. HANDLE Handle = ((winCEfile *) opaque)->handle;
  371. (void) CloseHandle(Handle); /* ignore errors. You should have flushed! */
  372. allocator.Free(opaque);
  373. } /* __PHYSFS_platformClose */
  374. int __PHYSFS_platformDelete(const char *path)
  375. {
  376. wchar_t *w_path = NULL;
  377. UTF8_TO_UNICODE_STACK_MACRO(w_path, path);
  378. /* If filename is a folder */
  379. if (GetFileAttributes(w_path) == FILE_ATTRIBUTE_DIRECTORY)
  380. {
  381. int retval = !RemoveDirectory(w_path);
  382. __PHYSFS_smallFree(w_path);
  383. BAIL_IF_MACRO(retval, win32strerror(), 0);
  384. } /* if */
  385. else
  386. {
  387. int retval = !DeleteFile(w_path);
  388. __PHYSFS_smallFree(w_path);
  389. BAIL_IF_MACRO(retval, win32strerror(), 0);
  390. } /* else */
  391. return 1; /* if you got here, it worked. */
  392. } /* __PHYSFS_platformDelete */
  393. /* Shamelessly copied from platform_windows.c */
  394. static PHYSFS_sint64 FileTimeToPhysfsTime(const FILETIME *ft)
  395. {
  396. SYSTEMTIME st_utc;
  397. SYSTEMTIME st_localtz;
  398. TIME_ZONE_INFORMATION tzi;
  399. DWORD tzid;
  400. PHYSFS_sint64 retval;
  401. struct tm tm;
  402. BAIL_IF_MACRO(!FileTimeToSystemTime(ft, &st_utc), winApiStrError(), -1);
  403. tzid = GetTimeZoneInformation(&tzi);
  404. BAIL_IF_MACRO(tzid == TIME_ZONE_ID_INVALID, winApiStrError(), -1);
  405. /* (This API is unsupported and fails on non-NT systems. */
  406. if (!SystemTimeToTzSpecificLocalTime(&tzi, &st_utc, &st_localtz))
  407. {
  408. /* do it by hand. Grumble... */
  409. ULARGE_INTEGER ui64;
  410. FILETIME new_ft;
  411. ui64.LowPart = ft->dwLowDateTime;
  412. ui64.HighPart = ft->dwHighDateTime;
  413. if (tzid == TIME_ZONE_ID_STANDARD)
  414. tzi.Bias += tzi.StandardBias;
  415. else if (tzid == TIME_ZONE_ID_DAYLIGHT)
  416. tzi.Bias += tzi.DaylightBias;
  417. /* convert from minutes to 100-nanosecond increments... */
  418. ui64.QuadPart -= (((LONGLONG) tzi.Bias) * (600000000));
  419. /* Move it back into a FILETIME structure... */
  420. new_ft.dwLowDateTime = ui64.LowPart;
  421. new_ft.dwHighDateTime = ui64.HighPart;
  422. /* Convert to something human-readable... */
  423. if (!FileTimeToSystemTime(&new_ft, &st_localtz))
  424. BAIL_MACRO(winApiStrError(), -1);
  425. } /* if */
  426. /* Convert to a format that mktime() can grok... */
  427. tm.tm_sec = st_localtz.wSecond;
  428. tm.tm_min = st_localtz.wMinute;
  429. tm.tm_hour = st_localtz.wHour;
  430. tm.tm_mday = st_localtz.wDay;
  431. tm.tm_mon = st_localtz.wMonth - 1;
  432. tm.tm_year = st_localtz.wYear - 1900;
  433. tm.tm_wday = -1 /*st_localtz.wDayOfWeek*/;
  434. tm.tm_yday = -1;
  435. tm.tm_isdst = -1;
  436. /* Convert to a format PhysicsFS can grok... */
  437. retval = (PHYSFS_sint64) mktime(&tm);
  438. BAIL_IF_MACRO(retval == -1, strerror(errno), -1);
  439. return retval;
  440. } /* FileTimeToPhysfsTime */
  441. int __PHYSFS_platformStat(const char *filename, int *exists, PHYSFS_Stat *stat)
  442. {
  443. WIN32_FIND_DATA winstat;
  444. const HANDLE searchhandle = FindFirstFile(filename, &winstat);
  445. if (searchhandle == INVALID_HANDLE_VALUE) /* call failed? */
  446. {
  447. /* !!! FIXME: FindFirstFile() doesn't set errno. Use GetLastError()?. */
  448. if (errno == ERROR_FILE_NOT_FOUND)
  449. {
  450. *exists = 0;
  451. return 0;
  452. } /* if */
  453. BAIL_MACRO(win32strerror, 0);
  454. } /* if */
  455. FindClose(searchhandle); /* close handle, not needed anymore */
  456. *exists = 1;
  457. if(winstat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  458. stat->filetype = PHYSFS_FILETYPE_DIRECTORY;
  459. else if (winstat.dwFileAttributes & (FILE_ATTRIBUTE_OFFLINE | FILE_ATTRIBUTE_ROMMODULE))
  460. stat->filetype = PHYSFS_FILETYPE_OTHER;
  461. else
  462. stat->filetype = PHYSFS_FILETYPE_OTHER; /* !!! FIXME: _REGULAR? */
  463. if (stat->filetype == PHYSFS_FILETYPE_REGULAR)
  464. stat->filesize = (((PHYSFS_uint64) winstat.nFileSizeHigh) << 32) | winstat.nFileSizeLow;
  465. stat->modtime = FileTimeToPhysfsTime(&winstat.ftLastWriteTime);
  466. stat->accesstime = FileTimeToPhysfsTime(&winstat.ftLastAccessTime);
  467. stat->createtime = FileTimeToPhysfsTime(&winstat.ftCreationTime);
  468. stat->readonly = ((winstat.dwFileAttributes & (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_INROM)) != 0);
  469. return 1;
  470. } /* __PHYSFS_platformStat */
  471. /*
  472. * !!! FIXME: why aren't we using Critical Sections instead of Mutexes?
  473. * !!! FIXME: mutexes on Windows are for cross-process sync. CritSects are
  474. * !!! FIXME: mutexes for threads in a single process and are faster.
  475. */
  476. void *__PHYSFS_platformCreateMutex(void)
  477. {
  478. return ((void *) CreateMutex(NULL, FALSE, NULL));
  479. } /* __PHYSFS_platformCreateMutex */
  480. void __PHYSFS_platformDestroyMutex(void *mutex)
  481. {
  482. CloseHandle((HANDLE) mutex);
  483. } /* __PHYSFS_platformDestroyMutex */
  484. int __PHYSFS_platformGrabMutex(void *mutex)
  485. {
  486. return (WaitForSingleObject((HANDLE) mutex, INFINITE) != WAIT_FAILED);
  487. } /* __PHYSFS_platformGrabMutex */
  488. void __PHYSFS_platformReleaseMutex(void *mutex)
  489. {
  490. ReleaseMutex((HANDLE) mutex);
  491. } /* __PHYSFS_platformReleaseMutex */
  492. /* !!! FIXME: Don't use C runtime for allocators? */
  493. int __PHYSFS_platformSetDefaultAllocator(PHYSFS_Allocator *a)
  494. {
  495. return 0; /* just use malloc() and friends. */
  496. } /* __PHYSFS_platformSetDefaultAllocator */
  497. #endif /* PHYSFS_PLATFORM_POCKETPC */
  498. /* end of pocketpc.c ... */