physfs.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406
  1. /**
  2. * PhysicsFS; a portable, flexible file i/o abstraction.
  3. *
  4. * Documentation is in physfs.h. It's verbose, honest. :)
  5. *
  6. * Please see the file LICENSE in the source's root directory.
  7. *
  8. * This file written by Ryan C. Gordon.
  9. */
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <fcntl.h>
  14. #include <errno.h>
  15. #include <assert.h>
  16. #include "physfs.h"
  17. #define __PHYSICSFS_INTERNAL__
  18. #include "physfs_internal.h"
  19. typedef struct __PHYSFS_ERRMSGTYPE__
  20. {
  21. PHYSFS_uint64 tid;
  22. int errorAvailable;
  23. char errorString[80];
  24. struct __PHYSFS_ERRMSGTYPE__ *next;
  25. } ErrMsg;
  26. typedef struct __PHYSFS_DIRINFO__
  27. {
  28. char *dirName;
  29. DirHandle *dirHandle;
  30. struct __PHYSFS_DIRINFO__ *next;
  31. } PhysDirInfo;
  32. typedef struct __PHYSFS_FILEHANDLELIST__
  33. {
  34. PHYSFS_file handle;
  35. struct __PHYSFS_FILEHANDLELIST__ *next;
  36. } FileHandleList;
  37. /* The various i/o drivers... */
  38. #if (defined PHYSFS_SUPPORTS_ZIP)
  39. extern const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_ZIP;
  40. extern const DirFunctions __PHYSFS_DirFunctions_ZIP;
  41. #endif
  42. #if (defined PHYSFS_SUPPORTS_GRP)
  43. extern const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_GRP;
  44. extern const DirFunctions __PHYSFS_DirFunctions_GRP;
  45. #endif
  46. extern const DirFunctions __PHYSFS_DirFunctions_DIR;
  47. static const PHYSFS_ArchiveInfo *supported_types[] =
  48. {
  49. #if (defined PHYSFS_SUPPORTS_ZIP)
  50. &__PHYSFS_ArchiveInfo_ZIP,
  51. #endif
  52. #if (defined PHYSFS_SUPPORTS_GRP)
  53. &__PHYSFS_ArchiveInfo_GRP,
  54. #endif
  55. NULL
  56. };
  57. static const DirFunctions *dirFunctions[] =
  58. {
  59. #if (defined PHYSFS_SUPPORTS_ZIP)
  60. &__PHYSFS_DirFunctions_ZIP,
  61. #endif
  62. #if (defined PHYSFS_SUPPORTS_GRP)
  63. &__PHYSFS_DirFunctions_GRP,
  64. #endif
  65. &__PHYSFS_DirFunctions_DIR,
  66. NULL
  67. };
  68. /* General PhysicsFS state ... */
  69. static int initialized = 0;
  70. static ErrMsg *errorMessages = NULL;
  71. static PhysDirInfo *searchPath = NULL;
  72. static PhysDirInfo *writeDir = NULL;
  73. static FileHandleList *openWriteList = NULL;
  74. static FileHandleList *openReadList = NULL;
  75. static char *baseDir = NULL;
  76. static char *userDir = NULL;
  77. static int allowSymLinks = 0;
  78. /* mutexes ... */
  79. static void *errorLock = NULL; /* protects error message list. */
  80. static void *stateLock = NULL; /* protects other PhysFS static state. */
  81. /* functions ... */
  82. static ErrMsg *findErrorForCurrentThread(void)
  83. {
  84. ErrMsg *i;
  85. PHYSFS_uint64 tid;
  86. __PHYSFS_platformGrabMutex(errorLock);
  87. if (errorMessages != NULL)
  88. {
  89. tid = __PHYSFS_platformGetThreadID();
  90. for (i = errorMessages; i != NULL; i = i->next)
  91. {
  92. if (i->tid == tid)
  93. {
  94. __PHYSFS_platformReleaseMutex(errorLock);
  95. return(i);
  96. } /* if */
  97. } /* for */
  98. } /* if */
  99. __PHYSFS_platformReleaseMutex(errorLock);
  100. return(NULL); /* no error available. */
  101. } /* findErrorForCurrentThread */
  102. void __PHYSFS_setError(const char *str)
  103. {
  104. ErrMsg *err;
  105. if (str == NULL)
  106. return;
  107. err = findErrorForCurrentThread();
  108. if (err == NULL)
  109. {
  110. err = (ErrMsg *) malloc(sizeof (ErrMsg));
  111. if (err == NULL)
  112. return; /* uhh...? */
  113. memset((void *) err, '\0', sizeof (ErrMsg));
  114. err->tid = __PHYSFS_platformGetThreadID();
  115. __PHYSFS_platformGrabMutex(errorLock);
  116. err->next = errorMessages;
  117. errorMessages = err;
  118. __PHYSFS_platformReleaseMutex(errorLock);
  119. } /* if */
  120. err->errorAvailable = 1;
  121. strncpy(err->errorString, str, sizeof (err->errorString));
  122. err->errorString[sizeof (err->errorString) - 1] = '\0';
  123. } /* __PHYSFS_setError */
  124. const char *PHYSFS_getLastError(void)
  125. {
  126. ErrMsg *err = findErrorForCurrentThread();
  127. if ((err == NULL) || (!err->errorAvailable))
  128. return(NULL);
  129. err->errorAvailable = 0;
  130. return(err->errorString);
  131. } /* PHYSFS_getLastError */
  132. /* MAKE SURE that errorLock is held before calling this! */
  133. static void freeErrorMessages(void)
  134. {
  135. ErrMsg *i;
  136. ErrMsg *next;
  137. for (i = errorMessages; i != NULL; i = next)
  138. {
  139. next = i->next;
  140. free(i);
  141. } /* for */
  142. } /* freeErrorMessages */
  143. void PHYSFS_getLinkedVersion(PHYSFS_Version *ver)
  144. {
  145. if (ver != NULL)
  146. {
  147. ver->major = PHYSFS_VER_MAJOR;
  148. ver->minor = PHYSFS_VER_MINOR;
  149. ver->patch = PHYSFS_VER_PATCH;
  150. } /* if */
  151. } /* PHYSFS_getLinkedVersion */
  152. static DirHandle *openDirectory(const char *d, int forWriting)
  153. {
  154. const DirFunctions **i;
  155. BAIL_IF_MACRO(!__PHYSFS_platformExists(d), ERR_NO_SUCH_FILE, NULL);
  156. for (i = dirFunctions; *i != NULL; i++)
  157. {
  158. if ((*i)->isArchive(d, forWriting))
  159. return( (*i)->openArchive(d, forWriting) );
  160. } /* for */
  161. __PHYSFS_setError(ERR_UNSUPPORTED_ARCHIVE);
  162. return(NULL);
  163. } /* openDirectory */
  164. static PhysDirInfo *buildDirInfo(const char *newDir, int forWriting)
  165. {
  166. DirHandle *dirHandle = NULL;
  167. PhysDirInfo *di = NULL;
  168. BAIL_IF_MACRO(newDir == NULL, ERR_INVALID_ARGUMENT, 0);
  169. dirHandle = openDirectory(newDir, forWriting);
  170. BAIL_IF_MACRO(dirHandle == NULL, NULL, 0);
  171. di = (PhysDirInfo *) malloc(sizeof (PhysDirInfo));
  172. if (di == NULL)
  173. {
  174. dirHandle->funcs->dirClose(dirHandle);
  175. BAIL_IF_MACRO(di == NULL, ERR_OUT_OF_MEMORY, 0);
  176. } /* if */
  177. di->dirName = (char *) malloc(strlen(newDir) + 1);
  178. if (di->dirName == NULL)
  179. {
  180. free(di);
  181. dirHandle->funcs->dirClose(dirHandle);
  182. BAIL_MACRO(ERR_OUT_OF_MEMORY, 0);
  183. } /* if */
  184. di->next = NULL;
  185. di->dirHandle = dirHandle;
  186. strcpy(di->dirName, newDir);
  187. return(di);
  188. } /* buildDirInfo */
  189. /* MAKE SURE you've got the stateLock held before calling this! */
  190. static int freeDirInfo(PhysDirInfo *di, FileHandleList *openList)
  191. {
  192. FileHandleList *i;
  193. if (di == NULL)
  194. return(1);
  195. for (i = openList; i != NULL; i = i->next)
  196. {
  197. const DirHandle *h = ((FileHandle *) &(i->handle.opaque))->dirHandle;
  198. BAIL_IF_MACRO(h == di->dirHandle, ERR_FILES_STILL_OPEN, 0);
  199. } /* for */
  200. di->dirHandle->funcs->dirClose(di->dirHandle);
  201. free(di->dirName);
  202. free(di);
  203. return(1);
  204. } /* freeDirInfo */
  205. static char *calculateUserDir(void)
  206. {
  207. char *retval = NULL;
  208. const char *str = NULL;
  209. str = __PHYSFS_platformGetUserDir();
  210. if (str != NULL)
  211. retval = (char *) str;
  212. else
  213. {
  214. const char *dirsep = PHYSFS_getDirSeparator();
  215. const char *uname = __PHYSFS_platformGetUserName();
  216. str = (uname != NULL) ? uname : "default";
  217. retval = (char *) malloc(strlen(baseDir) + strlen(str) +
  218. strlen(dirsep) + 6);
  219. if (retval == NULL)
  220. __PHYSFS_setError(ERR_OUT_OF_MEMORY);
  221. else
  222. sprintf(retval, "%susers%s%s", baseDir, dirsep, str);
  223. if (uname != NULL)
  224. free((void *) uname);
  225. } /* else */
  226. return(retval);
  227. } /* calculateUserDir */
  228. static int appendDirSep(char **dir)
  229. {
  230. const char *dirsep = PHYSFS_getDirSeparator();
  231. char *ptr;
  232. if (strcmp((*dir + strlen(*dir)) - strlen(dirsep), dirsep) == 0)
  233. return(1);
  234. ptr = realloc(*dir, strlen(*dir) + strlen(dirsep) + 1);
  235. if (!ptr)
  236. {
  237. free(*dir);
  238. return(0);
  239. } /* if */
  240. strcat(ptr, dirsep);
  241. *dir = ptr;
  242. return(1);
  243. } /* appendDirSep */
  244. static char *calculateBaseDir(const char *argv0)
  245. {
  246. const char *dirsep = PHYSFS_getDirSeparator();
  247. char *retval;
  248. char *ptr;
  249. /*
  250. * See if the platform driver wants to handle this for us...
  251. */
  252. retval = __PHYSFS_platformCalcBaseDir(argv0);
  253. if (retval != NULL)
  254. return(retval);
  255. /*
  256. * Determine if there's a path on argv0. If there is, that's the base dir.
  257. */
  258. ptr = strstr(argv0, dirsep);
  259. if (ptr != NULL)
  260. {
  261. char *p = ptr;
  262. size_t size;
  263. while (p != NULL)
  264. {
  265. ptr = p;
  266. p = strstr(p + 1, dirsep);
  267. } /* while */
  268. size = (size_t) (ptr - argv0); /* !!! is this portable? */
  269. retval = (char *) malloc(size + 1);
  270. BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
  271. memcpy(retval, argv0, size);
  272. retval[size] = '\0';
  273. return(retval);
  274. } /* if */
  275. /*
  276. * Last ditch effort: it's the current working directory. (*shrug*)
  277. */
  278. retval = __PHYSFS_platformCurrentDir();
  279. if(retval != NULL) {
  280. return(retval);
  281. }
  282. /*
  283. * Ok, current directory doesn't exist, use the root directory.
  284. * Not a good alternative, but it only happens if the current
  285. * directory was deleted from under the program.
  286. */
  287. retval = (char *) malloc(strlen(dirsep) + 1);
  288. strcpy(retval, dirsep);
  289. return(retval);
  290. } /* calculateBaseDir */
  291. static int initializeMutexes(void)
  292. {
  293. errorLock = __PHYSFS_platformCreateMutex();
  294. if (errorLock == NULL)
  295. goto initializeMutexes_failed;
  296. stateLock = __PHYSFS_platformCreateMutex();
  297. if (stateLock == NULL)
  298. goto initializeMutexes_failed;
  299. return(1); /* success. */
  300. initializeMutexes_failed:
  301. if (errorLock != NULL)
  302. __PHYSFS_platformDestroyMutex(errorLock);
  303. if (stateLock != NULL)
  304. __PHYSFS_platformDestroyMutex(stateLock);
  305. errorLock = stateLock = NULL;
  306. return(0); /* failed. */
  307. } /* initializeMutexes */
  308. int PHYSFS_init(const char *argv0)
  309. {
  310. char *ptr;
  311. BAIL_IF_MACRO(initialized, ERR_IS_INITIALIZED, 0);
  312. BAIL_IF_MACRO(!__PHYSFS_platformInit(), NULL, 0);
  313. BAIL_IF_MACRO(!initializeMutexes(), NULL, 0);
  314. baseDir = calculateBaseDir(argv0);
  315. BAIL_IF_MACRO(baseDir == NULL, NULL, 0);
  316. ptr = __PHYSFS_platformRealPath(baseDir);
  317. free(baseDir);
  318. BAIL_IF_MACRO(ptr == NULL, NULL, 0);
  319. baseDir = ptr;
  320. BAIL_IF_MACRO(!appendDirSep(&baseDir), NULL, 0);
  321. userDir = calculateUserDir();
  322. if (userDir != NULL)
  323. {
  324. ptr = __PHYSFS_platformRealPath(userDir);
  325. free(userDir);
  326. userDir = ptr;
  327. } /* if */
  328. if ((userDir == NULL) || (!appendDirSep(&userDir)))
  329. {
  330. free(baseDir);
  331. baseDir = NULL;
  332. return(0);
  333. } /* if */
  334. initialized = 1;
  335. /* This makes sure that the error subsystem is initialized. */
  336. __PHYSFS_setError(PHYSFS_getLastError());
  337. return(1);
  338. } /* PHYSFS_init */
  339. /* MAKE SURE you hold stateLock before calling this! */
  340. static int closeFileHandleList(FileHandleList **list)
  341. {
  342. FileHandleList *i;
  343. FileHandleList *next = NULL;
  344. FileHandle *h;
  345. for (i = *list; i != NULL; i = next)
  346. {
  347. next = i->next;
  348. h = (FileHandle *) (i->handle.opaque);
  349. if (!h->funcs->fileClose(h))
  350. {
  351. *list = i;
  352. return(0);
  353. } /* if */
  354. free(i);
  355. } /* for */
  356. *list = NULL;
  357. return(1);
  358. } /* closeFileHandleList */
  359. /* MAKE SURE you hold the stateLock before calling this! */
  360. static void freeSearchPath(void)
  361. {
  362. PhysDirInfo *i;
  363. PhysDirInfo *next = NULL;
  364. closeFileHandleList(&openReadList);
  365. if (searchPath != NULL)
  366. {
  367. for (i = searchPath; i != NULL; i = next)
  368. {
  369. next = i->next;
  370. freeDirInfo(i, openReadList);
  371. } /* for */
  372. searchPath = NULL;
  373. } /* if */
  374. } /* freeSearchPath */
  375. int PHYSFS_deinit(void)
  376. {
  377. BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
  378. BAIL_IF_MACRO(!__PHYSFS_platformDeinit(), NULL, 0);
  379. closeFileHandleList(&openWriteList);
  380. BAIL_IF_MACRO(!PHYSFS_setWriteDir(NULL), ERR_FILES_STILL_OPEN, 0);
  381. freeSearchPath();
  382. freeErrorMessages();
  383. if (baseDir != NULL)
  384. {
  385. free(baseDir);
  386. baseDir = NULL;
  387. } /* if */
  388. if (userDir != NULL)
  389. {
  390. free(userDir);
  391. userDir = NULL;
  392. } /* if */
  393. allowSymLinks = 0;
  394. initialized = 0;
  395. __PHYSFS_platformDestroyMutex(errorLock);
  396. __PHYSFS_platformDestroyMutex(stateLock);
  397. errorLock = stateLock = NULL;
  398. return(1);
  399. } /* PHYSFS_deinit */
  400. const PHYSFS_ArchiveInfo **PHYSFS_supportedArchiveTypes(void)
  401. {
  402. return(supported_types);
  403. } /* PHYSFS_supportedArchiveTypes */
  404. void PHYSFS_freeList(void *list)
  405. {
  406. void **i;
  407. for (i = (void **) list; *i != NULL; i++)
  408. free(*i);
  409. free(list);
  410. } /* PHYSFS_freeList */
  411. const char *PHYSFS_getDirSeparator(void)
  412. {
  413. return(__PHYSFS_platformDirSeparator);
  414. } /* PHYSFS_getDirSeparator */
  415. char **PHYSFS_getCdRomDirs(void)
  416. {
  417. return(__PHYSFS_platformDetectAvailableCDs());
  418. } /* PHYSFS_getCdRomDirs */
  419. const char *PHYSFS_getBaseDir(void)
  420. {
  421. return(baseDir); /* this is calculated in PHYSFS_init()... */
  422. } /* PHYSFS_getBaseDir */
  423. const char *PHYSFS_getUserDir(void)
  424. {
  425. return(userDir); /* this is calculated in PHYSFS_init()... */
  426. } /* PHYSFS_getUserDir */
  427. const char *PHYSFS_getWriteDir(void)
  428. {
  429. const char *retval = NULL;
  430. __PHYSFS_platformGrabMutex(stateLock);
  431. if (writeDir != NULL)
  432. retval = writeDir->dirName;
  433. __PHYSFS_platformReleaseMutex(stateLock);
  434. return(retval);
  435. } /* PHYSFS_getWriteDir */
  436. int PHYSFS_setWriteDir(const char *newDir)
  437. {
  438. int retval = 1;
  439. __PHYSFS_platformGrabMutex(stateLock);
  440. if (writeDir != NULL)
  441. {
  442. BAIL_IF_MACRO_MUTEX(!freeDirInfo(writeDir, openWriteList), NULL,
  443. stateLock, 0);
  444. writeDir = NULL;
  445. } /* if */
  446. if (newDir != NULL)
  447. {
  448. writeDir = buildDirInfo(newDir, 1);
  449. retval = (writeDir != NULL);
  450. } /* if */
  451. __PHYSFS_platformReleaseMutex(stateLock);
  452. return(retval);
  453. } /* PHYSFS_setWriteDir */
  454. int PHYSFS_addToSearchPath(const char *newDir, int appendToPath)
  455. {
  456. PhysDirInfo *di;
  457. PhysDirInfo *prev = NULL;
  458. PhysDirInfo *i;
  459. __PHYSFS_platformGrabMutex(stateLock);
  460. for (i = searchPath; i != NULL; i = i->next)
  461. {
  462. /* already in search path? */
  463. BAIL_IF_MACRO_MUTEX(strcmp(newDir, i->dirName)==0, NULL, stateLock, 1);
  464. prev = i;
  465. } /* for */
  466. di = buildDirInfo(newDir, 0);
  467. BAIL_IF_MACRO_MUTEX(di == NULL, NULL, stateLock, 0);
  468. if (appendToPath)
  469. {
  470. di->next = NULL;
  471. if (prev == NULL)
  472. searchPath = di;
  473. else
  474. prev->next = di;
  475. } /* if */
  476. else
  477. {
  478. di->next = searchPath;
  479. searchPath = di;
  480. } /* else */
  481. __PHYSFS_platformReleaseMutex(stateLock);
  482. return(1);
  483. } /* PHYSFS_addToSearchPath */
  484. int PHYSFS_removeFromSearchPath(const char *oldDir)
  485. {
  486. PhysDirInfo *i;
  487. PhysDirInfo *prev = NULL;
  488. PhysDirInfo *next = NULL;
  489. BAIL_IF_MACRO(oldDir == NULL, ERR_INVALID_ARGUMENT, 0);
  490. __PHYSFS_platformGrabMutex(stateLock);
  491. for (i = searchPath; i != NULL; i = i->next)
  492. {
  493. if (strcmp(i->dirName, oldDir) == 0)
  494. {
  495. next = i->next;
  496. BAIL_IF_MACRO_MUTEX(!freeDirInfo(i, openReadList), NULL,
  497. stateLock, 0);
  498. if (prev == NULL)
  499. searchPath = next;
  500. else
  501. prev->next = next;
  502. BAIL_MACRO_MUTEX(NULL, stateLock, 1);
  503. } /* if */
  504. prev = i;
  505. } /* for */
  506. BAIL_MACRO_MUTEX(ERR_NOT_IN_SEARCH_PATH, stateLock, 0);
  507. } /* PHYSFS_removeFromSearchPath */
  508. char **PHYSFS_getSearchPath(void)
  509. {
  510. int count = 1;
  511. int x;
  512. PhysDirInfo *i;
  513. char **retval;
  514. __PHYSFS_platformGrabMutex(stateLock);
  515. for (i = searchPath; i != NULL; i = i->next)
  516. count++;
  517. retval = (char **) malloc(sizeof (char *) * count);
  518. BAIL_IF_MACRO_MUTEX(!retval, ERR_OUT_OF_MEMORY, stateLock, NULL);
  519. count--;
  520. retval[count] = NULL;
  521. for (i = searchPath, x = 0; x < count; i = i->next, x++)
  522. {
  523. retval[x] = (char *) malloc(strlen(i->dirName) + 1);
  524. if (retval[x] == NULL) /* this is friggin' ugly. */
  525. {
  526. while (x > 0)
  527. {
  528. x--;
  529. free(retval[x]);
  530. } /* while */
  531. free(retval);
  532. BAIL_MACRO_MUTEX(ERR_OUT_OF_MEMORY, stateLock, NULL);
  533. } /* if */
  534. strcpy(retval[x], i->dirName);
  535. } /* for */
  536. __PHYSFS_platformReleaseMutex(stateLock);
  537. return(retval);
  538. } /* PHYSFS_getSearchPath */
  539. int PHYSFS_setSaneConfig(const char *organization, const char *appName,
  540. const char *archiveExt, int includeCdRoms,
  541. int archivesFirst)
  542. {
  543. const char *basedir = PHYSFS_getBaseDir();
  544. const char *userdir = PHYSFS_getUserDir();
  545. const char *dirsep = PHYSFS_getDirSeparator();
  546. char *str;
  547. BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
  548. /* set write dir... */
  549. str = malloc(strlen(userdir) + (strlen(organization) * 2) +
  550. (strlen(appName) * 2) + (strlen(dirsep) * 3) + 2);
  551. BAIL_IF_MACRO(str == NULL, ERR_OUT_OF_MEMORY, 0);
  552. sprintf(str, "%s.%s%s%s", userdir, organization, dirsep, appName);
  553. if (!PHYSFS_setWriteDir(str))
  554. {
  555. int no_write = 0;
  556. sprintf(str, ".%s/%s", organization, appName);
  557. if ( (PHYSFS_setWriteDir(userdir)) &&
  558. (PHYSFS_mkdir(str)) )
  559. {
  560. sprintf(str, "%s.%s%s%s", userdir, organization, dirsep, appName);
  561. if (!PHYSFS_setWriteDir(str))
  562. no_write = 1;
  563. } /* if */
  564. else
  565. {
  566. no_write = 1;
  567. } /* else */
  568. if (no_write)
  569. {
  570. PHYSFS_setWriteDir(NULL); /* just in case. */
  571. free(str);
  572. BAIL_MACRO(ERR_CANT_SET_WRITE_DIR, 0);
  573. } /* if */
  574. } /* if */
  575. /* Put write dir first in search path... */
  576. PHYSFS_addToSearchPath(str, 0);
  577. free(str);
  578. /* Put base path on search path... */
  579. PHYSFS_addToSearchPath(basedir, 1);
  580. /* handle CD-ROMs... */
  581. if (includeCdRoms)
  582. {
  583. char **cds = PHYSFS_getCdRomDirs();
  584. char **i;
  585. for (i = cds; *i != NULL; i++)
  586. PHYSFS_addToSearchPath(*i, 1);
  587. PHYSFS_freeList(cds);
  588. } /* if */
  589. /* Root out archives, and add them to search path... */
  590. if (archiveExt != NULL)
  591. {
  592. char **rc = PHYSFS_enumerateFiles("");
  593. char **i;
  594. size_t extlen = strlen(archiveExt);
  595. char *ext;
  596. for (i = rc; *i != NULL; i++)
  597. {
  598. size_t l = strlen(*i);
  599. if ((l > extlen) && ((*i)[l - extlen - 1] == '.'))
  600. {
  601. ext = (*i) + (l - extlen);
  602. if (__PHYSFS_platformStricmp(ext, archiveExt) == 0)
  603. {
  604. const char *d = PHYSFS_getRealDir(*i);
  605. str = malloc(strlen(d) + strlen(dirsep) + l + 1);
  606. if (str != NULL)
  607. {
  608. sprintf(str, "%s%s%s", d, dirsep, *i);
  609. PHYSFS_addToSearchPath(str, archivesFirst == 0);
  610. free(str);
  611. } /* if */
  612. } /* if */
  613. } /* if */
  614. } /* for */
  615. PHYSFS_freeList(rc);
  616. } /* if */
  617. return(1);
  618. } /* PHYSFS_setSaneConfig */
  619. void PHYSFS_permitSymbolicLinks(int allow)
  620. {
  621. allowSymLinks = allow;
  622. } /* PHYSFS_permitSymbolicLinks */
  623. /* string manipulation in C makes my ass itch. */
  624. char * __PHYSFS_convertToDependent(const char *prepend,
  625. const char *dirName,
  626. const char *append)
  627. {
  628. const char *dirsep = __PHYSFS_platformDirSeparator;
  629. size_t sepsize = strlen(dirsep);
  630. char *str;
  631. char *i1;
  632. char *i2;
  633. size_t allocSize;
  634. while (*dirName == '/')
  635. dirName++;
  636. allocSize = strlen(dirName) + 1;
  637. if (prepend != NULL)
  638. allocSize += strlen(prepend) + sepsize;
  639. if (append != NULL)
  640. allocSize += strlen(append) + sepsize;
  641. /* make sure there's enough space if the dir separator is bigger. */
  642. if (sepsize > 1)
  643. {
  644. str = (char *) dirName;
  645. do
  646. {
  647. str = strchr(str, '/');
  648. if (str != NULL)
  649. {
  650. allocSize += (sepsize - 1);
  651. str++;
  652. } /* if */
  653. } while (str != NULL);
  654. } /* if */
  655. str = (char *) malloc(allocSize);
  656. BAIL_IF_MACRO(str == NULL, ERR_OUT_OF_MEMORY, NULL);
  657. if (prepend == NULL)
  658. *str = '\0';
  659. else
  660. {
  661. strcpy(str, prepend);
  662. strcat(str, dirsep);
  663. } /* else */
  664. for (i1 = (char *) dirName, i2 = str + strlen(str); *i1; i1++, i2++)
  665. {
  666. if (*i1 == '/')
  667. {
  668. strcpy(i2, dirsep);
  669. i2 += sepsize;
  670. } /* if */
  671. else
  672. {
  673. *i2 = *i1;
  674. } /* else */
  675. } /* for */
  676. *i2 = '\0';
  677. if (append)
  678. {
  679. strcat(str, dirsep);
  680. strcpy(str, append);
  681. } /* if */
  682. return(str);
  683. } /* __PHYSFS_convertToDependent */
  684. int __PHYSFS_verifySecurity(DirHandle *h, const char *fname)
  685. {
  686. int retval = 1;
  687. char *start;
  688. char *end;
  689. char *str;
  690. start = str = malloc(strlen(fname) + 1);
  691. BAIL_IF_MACRO(str == NULL, ERR_OUT_OF_MEMORY, 0);
  692. strcpy(str, fname);
  693. while (1)
  694. {
  695. end = strchr(start, '/');
  696. if (end != NULL)
  697. *end = '\0';
  698. if ( (strcmp(start, ".") == 0) ||
  699. (strcmp(start, "..") == 0) ||
  700. (strchr(start, '\\') != NULL) ||
  701. (strchr(start, ':') != NULL) )
  702. {
  703. __PHYSFS_setError(ERR_INSECURE_FNAME);
  704. retval = 0;
  705. break;
  706. } /* if */
  707. if ((!allowSymLinks) && (h->funcs->isSymLink(h, str)))
  708. {
  709. __PHYSFS_setError(ERR_SYMLINK_DISALLOWED);
  710. retval = 0;
  711. break;
  712. } /* if */
  713. if (end == NULL)
  714. break;
  715. *end = '/';
  716. start = end + 1;
  717. } /* while */
  718. free(str);
  719. return(retval);
  720. } /* __PHYSFS_verifySecurity */
  721. int PHYSFS_mkdir(const char *dname)
  722. {
  723. DirHandle *h;
  724. char *str;
  725. char *start;
  726. char *end;
  727. int retval = 0;
  728. BAIL_IF_MACRO(dname == NULL, ERR_INVALID_ARGUMENT, 0);
  729. while (*dname == '/')
  730. dname++;
  731. __PHYSFS_platformGrabMutex(stateLock);
  732. BAIL_IF_MACRO_MUTEX(writeDir == NULL, ERR_NO_WRITE_DIR, stateLock, 0);
  733. h = writeDir->dirHandle;
  734. BAIL_IF_MACRO_MUTEX(!h->funcs->mkdir, ERR_NOT_SUPPORTED, stateLock, 0);
  735. BAIL_IF_MACRO_MUTEX(!__PHYSFS_verifySecurity(h, dname), NULL, stateLock, 0);
  736. start = str = malloc(strlen(dname) + 1);
  737. BAIL_IF_MACRO_MUTEX(str == NULL, ERR_OUT_OF_MEMORY, stateLock, 0);
  738. strcpy(str, dname);
  739. while (1)
  740. {
  741. end = strchr(start, '/');
  742. if (end != NULL)
  743. *end = '\0';
  744. retval = h->funcs->mkdir(h, str);
  745. if (!retval)
  746. break;
  747. if (end == NULL)
  748. break;
  749. *end = '/';
  750. start = end + 1;
  751. } /* while */
  752. __PHYSFS_platformReleaseMutex(stateLock);
  753. free(str);
  754. return(retval);
  755. } /* PHYSFS_mkdir */
  756. int PHYSFS_delete(const char *fname)
  757. {
  758. int retval;
  759. DirHandle *h;
  760. BAIL_IF_MACRO(fname == NULL, ERR_INVALID_ARGUMENT, 0);
  761. while (*fname == '/')
  762. fname++;
  763. __PHYSFS_platformGrabMutex(stateLock);
  764. BAIL_IF_MACRO_MUTEX(writeDir == NULL, ERR_NO_WRITE_DIR, stateLock, 0);
  765. h = writeDir->dirHandle;
  766. BAIL_IF_MACRO_MUTEX(!h->funcs->remove, ERR_NOT_SUPPORTED, stateLock, 0);
  767. BAIL_IF_MACRO_MUTEX(!__PHYSFS_verifySecurity(h, fname), NULL, stateLock, 0);
  768. retval = h->funcs->remove(h, fname);
  769. __PHYSFS_platformReleaseMutex(stateLock);
  770. return(retval);
  771. } /* PHYSFS_delete */
  772. const char *PHYSFS_getRealDir(const char *filename)
  773. {
  774. PhysDirInfo *i;
  775. while (*filename == '/')
  776. filename++;
  777. __PHYSFS_platformGrabMutex(stateLock);
  778. for (i = searchPath; i != NULL; i = i->next)
  779. {
  780. DirHandle *h = i->dirHandle;
  781. if (__PHYSFS_verifySecurity(h, filename))
  782. {
  783. if (h->funcs->exists(h, filename))
  784. {
  785. __PHYSFS_platformReleaseMutex(stateLock);
  786. return(i->dirName);
  787. } /* if */
  788. } /* if */
  789. } /* for */
  790. __PHYSFS_platformReleaseMutex(stateLock);
  791. return(NULL);
  792. } /* PHYSFS_getRealDir */
  793. static int countList(LinkedStringList *list)
  794. {
  795. int retval = 0;
  796. LinkedStringList *i;
  797. for (i = list; i != NULL; i = i->next)
  798. retval++;
  799. return(retval);
  800. } /* countList */
  801. static char **convertStringListToPhysFSList(LinkedStringList *finalList)
  802. {
  803. int i;
  804. LinkedStringList *next = NULL;
  805. int len = countList(finalList);
  806. char **retval = (char **) malloc((len + 1) * sizeof (char *));
  807. if (retval == NULL)
  808. __PHYSFS_setError(ERR_OUT_OF_MEMORY);
  809. for (i = 0; i < len; i++)
  810. {
  811. next = finalList->next;
  812. if (retval == NULL)
  813. free(finalList->str);
  814. else
  815. retval[i] = finalList->str;
  816. free(finalList);
  817. finalList = next;
  818. } /* for */
  819. if (retval != NULL)
  820. retval[i] = NULL;
  821. return(retval);
  822. } /* convertStringListToPhysFSList */
  823. static void insertStringListItem(LinkedStringList **final,
  824. LinkedStringList *item)
  825. {
  826. LinkedStringList *i;
  827. LinkedStringList *prev = NULL;
  828. int rc;
  829. for (i = *final; i != NULL; i = i->next)
  830. {
  831. rc = strcmp(i->str, item->str);
  832. if (rc > 0) /* insertion point. */
  833. break;
  834. else if (rc == 0) /* already in list. */
  835. {
  836. free(item->str);
  837. free(item);
  838. return;
  839. } /* else if */
  840. prev = i;
  841. } /* for */
  842. /*
  843. * If we are here, we are either at the insertion point.
  844. * This may be the end of the list, or the list may be empty, too.
  845. */
  846. if (prev == NULL)
  847. *final = item;
  848. else
  849. prev->next = item;
  850. item->next = i;
  851. } /* insertStringListItem */
  852. /* if we run out of memory anywhere in here, we give back what we can. */
  853. static void interpolateStringLists(LinkedStringList **final,
  854. LinkedStringList *newList)
  855. {
  856. LinkedStringList *next = NULL;
  857. while (newList != NULL)
  858. {
  859. next = newList->next;
  860. insertStringListItem(final, newList);
  861. newList = next;
  862. } /* while */
  863. } /* interpolateStringLists */
  864. char **PHYSFS_enumerateFiles(const char *path)
  865. {
  866. PhysDirInfo *i;
  867. char **retval = NULL;
  868. LinkedStringList *rc;
  869. LinkedStringList *finalList = NULL;
  870. int omitSymLinks = !allowSymLinks;
  871. BAIL_IF_MACRO(path == NULL, ERR_INVALID_ARGUMENT, NULL);
  872. while (*path == '/')
  873. path++;
  874. __PHYSFS_platformGrabMutex(stateLock);
  875. for (i = searchPath; i != NULL; i = i->next)
  876. {
  877. DirHandle *h = i->dirHandle;
  878. if (__PHYSFS_verifySecurity(h, path))
  879. {
  880. rc = h->funcs->enumerateFiles(h, path, omitSymLinks);
  881. interpolateStringLists(&finalList, rc);
  882. } /* if */
  883. } /* for */
  884. __PHYSFS_platformReleaseMutex(stateLock);
  885. retval = convertStringListToPhysFSList(finalList);
  886. return(retval);
  887. } /* PHYSFS_enumerateFiles */
  888. int PHYSFS_exists(const char *fname)
  889. {
  890. BAIL_IF_MACRO(fname == NULL, ERR_INVALID_ARGUMENT, 0);
  891. while (*fname == '/')
  892. fname++;
  893. return(PHYSFS_getRealDir(fname) != NULL);
  894. } /* PHYSFS_exists */
  895. int PHYSFS_isDirectory(const char *fname)
  896. {
  897. PhysDirInfo *i;
  898. BAIL_IF_MACRO(fname == NULL, ERR_INVALID_ARGUMENT, 0);
  899. while (*fname == '/')
  900. fname++;
  901. if (*fname == '\0')
  902. return(1);
  903. __PHYSFS_platformGrabMutex(stateLock);
  904. for (i = searchPath; i != NULL; i = i->next)
  905. {
  906. DirHandle *h = i->dirHandle;
  907. if (__PHYSFS_verifySecurity(h, fname))
  908. {
  909. if (h->funcs->exists(h, fname))
  910. {
  911. int retval = h->funcs->isDirectory(h, fname);
  912. __PHYSFS_platformReleaseMutex(stateLock);
  913. return(retval);
  914. } /* if */
  915. } /* if */
  916. } /* for */
  917. __PHYSFS_platformReleaseMutex(stateLock);
  918. return(0);
  919. } /* PHYSFS_isDirectory */
  920. int PHYSFS_isSymbolicLink(const char *fname)
  921. {
  922. PhysDirInfo *i;
  923. if (!allowSymLinks)
  924. return(0);
  925. BAIL_IF_MACRO(fname == NULL, ERR_INVALID_ARGUMENT, 0);
  926. while (*fname == '/')
  927. fname++;
  928. __PHYSFS_platformGrabMutex(stateLock);
  929. for (i = searchPath; i != NULL; i = i->next)
  930. {
  931. DirHandle *h = i->dirHandle;
  932. if (__PHYSFS_verifySecurity(h, fname))
  933. {
  934. if (h->funcs->exists(h, fname))
  935. {
  936. int retval = h->funcs->isSymLink(h, fname);
  937. __PHYSFS_platformReleaseMutex(stateLock);
  938. return(retval);
  939. } /* if */
  940. } /* if */
  941. } /* for */
  942. /* !!! FIXME: setError ERR_FILE_NOT_FOUND? */
  943. __PHYSFS_platformReleaseMutex(stateLock);
  944. return(0);
  945. } /* PHYSFS_isSymbolicLink */
  946. static PHYSFS_file *doOpenWrite(const char *fname, int appending)
  947. {
  948. PHYSFS_file *retval = NULL;
  949. FileHandle *rc = NULL;
  950. DirHandle *h;
  951. const DirFunctions *f;
  952. FileHandleList *list;
  953. BAIL_IF_MACRO(fname == NULL, ERR_INVALID_ARGUMENT, NULL);
  954. while (*fname == '/')
  955. fname++;
  956. __PHYSFS_platformGrabMutex(stateLock);
  957. h = (writeDir == NULL) ? NULL : writeDir->dirHandle;
  958. BAIL_IF_MACRO_MUTEX(!h, ERR_NO_WRITE_DIR, stateLock, NULL);
  959. BAIL_IF_MACRO_MUTEX(!__PHYSFS_verifySecurity(h, fname), NULL,
  960. stateLock, NULL);
  961. list = (FileHandleList *) malloc(sizeof (FileHandleList));
  962. BAIL_IF_MACRO_MUTEX(!list, ERR_OUT_OF_MEMORY, stateLock, NULL);
  963. f = h->funcs;
  964. rc = (appending) ? f->openAppend(h, fname) : f->openWrite(h, fname);
  965. if (rc == NULL)
  966. free(list);
  967. else
  968. {
  969. list->handle.opaque = (void *) rc;
  970. list->next = openWriteList;
  971. openWriteList = list;
  972. retval = &(list->handle);
  973. } /* else */
  974. __PHYSFS_platformReleaseMutex(stateLock);
  975. return(retval);
  976. } /* doOpenWrite */
  977. PHYSFS_file *PHYSFS_openWrite(const char *filename)
  978. {
  979. return(doOpenWrite(filename, 0));
  980. } /* PHYSFS_openWrite */
  981. PHYSFS_file *PHYSFS_openAppend(const char *filename)
  982. {
  983. return(doOpenWrite(filename, 1));
  984. } /* PHYSFS_openAppend */
  985. PHYSFS_file *PHYSFS_openRead(const char *fname)
  986. {
  987. PHYSFS_file *retval;
  988. FileHandle *rc = NULL;
  989. FileHandleList *list;
  990. PhysDirInfo *i;
  991. BAIL_IF_MACRO(fname == NULL, ERR_INVALID_ARGUMENT, NULL);
  992. while (*fname == '/')
  993. fname++;
  994. __PHYSFS_platformGrabMutex(stateLock);
  995. for (i = searchPath; i != NULL; i = i->next)
  996. {
  997. DirHandle *h = i->dirHandle;
  998. if (__PHYSFS_verifySecurity(h, fname))
  999. {
  1000. rc = h->funcs->openRead(h, fname);
  1001. if (rc != NULL)
  1002. break;
  1003. } /* if */
  1004. } /* for */
  1005. BAIL_IF_MACRO_MUTEX(rc == NULL, NULL, stateLock, NULL);
  1006. list = (FileHandleList *) malloc(sizeof (FileHandleList));
  1007. BAIL_IF_MACRO(!list, ERR_OUT_OF_MEMORY, NULL);
  1008. list->handle.opaque = (void *) rc;
  1009. list->next = openReadList;
  1010. openReadList = list;
  1011. retval = &(list->handle);
  1012. __PHYSFS_platformReleaseMutex(stateLock);
  1013. return(retval);
  1014. } /* PHYSFS_openRead */
  1015. static int closeHandleInOpenList(FileHandleList **list, PHYSFS_file *handle)
  1016. {
  1017. FileHandle *h = (FileHandle *) handle->opaque;
  1018. FileHandleList *prev = NULL;
  1019. FileHandleList *i;
  1020. int rc;
  1021. for (i = *list; i != NULL; i = i->next)
  1022. {
  1023. if (&i->handle == handle) /* handle is in this list? */
  1024. {
  1025. rc = h->funcs->fileClose(h);
  1026. if (!rc)
  1027. return(-1);
  1028. if (prev == NULL)
  1029. *list = i->next;
  1030. else
  1031. prev->next = i->next;
  1032. free(i);
  1033. return(1);
  1034. } /* if */
  1035. prev = i;
  1036. } /* for */
  1037. return(0);
  1038. } /* closeHandleInOpenList */
  1039. int PHYSFS_close(PHYSFS_file *handle)
  1040. {
  1041. int rc;
  1042. __PHYSFS_platformGrabMutex(stateLock);
  1043. /* -1 == close failure. 0 == not found. 1 == success. */
  1044. rc = closeHandleInOpenList(&openReadList, handle);
  1045. BAIL_IF_MACRO_MUTEX(rc == -1, NULL, stateLock, 0);
  1046. if (!rc)
  1047. {
  1048. rc = closeHandleInOpenList(&openWriteList, handle);
  1049. BAIL_IF_MACRO_MUTEX(rc == -1, NULL, stateLock, 0);
  1050. } /* if */
  1051. __PHYSFS_platformReleaseMutex(stateLock);
  1052. BAIL_IF_MACRO(!rc, ERR_NOT_A_HANDLE, 0);
  1053. return(1);
  1054. } /* PHYSFS_close */
  1055. PHYSFS_sint64 PHYSFS_read(PHYSFS_file *handle, void *buffer,
  1056. PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
  1057. {
  1058. FileHandle *h = (FileHandle *) handle->opaque;
  1059. assert(h != NULL);
  1060. assert(h->funcs != NULL);
  1061. BAIL_IF_MACRO(h->funcs->read == NULL, ERR_NOT_SUPPORTED, -1);
  1062. return(h->funcs->read(h, buffer, objSize, objCount));
  1063. } /* PHYSFS_read */
  1064. PHYSFS_sint64 PHYSFS_write(PHYSFS_file *handle, const void *buffer,
  1065. PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
  1066. {
  1067. FileHandle *h = (FileHandle *) handle->opaque;
  1068. assert(h != NULL);
  1069. assert(h->funcs != NULL);
  1070. BAIL_IF_MACRO(h->funcs->write == NULL, ERR_NOT_SUPPORTED, -1);
  1071. return(h->funcs->write(h, buffer, objSize, objCount));
  1072. } /* PHYSFS_write */
  1073. int PHYSFS_eof(PHYSFS_file *handle)
  1074. {
  1075. FileHandle *h = (FileHandle *) handle->opaque;
  1076. assert(h != NULL);
  1077. assert(h->funcs != NULL);
  1078. BAIL_IF_MACRO(h->funcs->eof == NULL, ERR_NOT_SUPPORTED, -1);
  1079. return(h->funcs->eof(h));
  1080. } /* PHYSFS_eof */
  1081. PHYSFS_sint64 PHYSFS_tell(PHYSFS_file *handle)
  1082. {
  1083. FileHandle *h = (FileHandle *) handle->opaque;
  1084. assert(h != NULL);
  1085. assert(h->funcs != NULL);
  1086. BAIL_IF_MACRO(h->funcs->tell == NULL, ERR_NOT_SUPPORTED, -1);
  1087. return(h->funcs->tell(h));
  1088. } /* PHYSFS_tell */
  1089. int PHYSFS_seek(PHYSFS_file *handle, PHYSFS_uint64 pos)
  1090. {
  1091. FileHandle *h = (FileHandle *) handle->opaque;
  1092. assert(h != NULL);
  1093. assert(h->funcs != NULL);
  1094. BAIL_IF_MACRO(h->funcs->seek == NULL, ERR_NOT_SUPPORTED, 0);
  1095. BAIL_IF_MACRO(pos < 0, ERR_INVALID_ARGUMENT, 0);
  1096. return(h->funcs->seek(h, pos));
  1097. } /* PHYSFS_seek */
  1098. PHYSFS_sint64 PHYSFS_fileLength(PHYSFS_file *handle)
  1099. {
  1100. FileHandle *h = (FileHandle *) handle->opaque;
  1101. assert(h != NULL);
  1102. assert(h->funcs != NULL);
  1103. BAIL_IF_MACRO(h->funcs->fileLength == NULL, ERR_NOT_SUPPORTED, 0);
  1104. return(h->funcs->fileLength(h));
  1105. } /* PHYSFS_filelength */
  1106. /* end of physfs.c ... */