platform_pocketpc.c 19 KB

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