physfs.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404
  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. int 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. int tid;
  86. __PHYSFS_platformGrabMutex(errorLock);
  87. if (errorMessages != NULL)
  88. {
  89. /*!!! I think tid needs to be a 64-bit value??? */
  90. tid = (int)__PHYSFS_platformGetThreadID();
  91. for (i = errorMessages; i != NULL; i = i->next)
  92. {
  93. if (i->tid == tid)
  94. {
  95. __PHYSFS_platformReleaseMutex(errorLock);
  96. return(i);
  97. } /* if */
  98. } /* for */
  99. } /* if */
  100. __PHYSFS_platformReleaseMutex(errorLock);
  101. return(NULL); /* no error available. */
  102. } /* findErrorForCurrentThread */
  103. void __PHYSFS_setError(const char *str)
  104. {
  105. ErrMsg *err;
  106. if (str == NULL)
  107. return;
  108. err = findErrorForCurrentThread();
  109. if (err == NULL)
  110. {
  111. err = (ErrMsg *) malloc(sizeof (ErrMsg));
  112. if (err == NULL)
  113. return; /* uhh...? */
  114. memset((void *) err, '\0', sizeof (ErrMsg));
  115. /*!!! I think tid needs to be a 64-bit value??? */
  116. err->tid = (int)__PHYSFS_platformGetThreadID();
  117. __PHYSFS_platformGrabMutex(errorLock);
  118. err->next = errorMessages;
  119. errorMessages = err;
  120. __PHYSFS_platformReleaseMutex(errorLock);
  121. } /* if */
  122. err->errorAvailable = 1;
  123. strncpy(err->errorString, str, sizeof (err->errorString));
  124. err->errorString[sizeof (err->errorString) - 1] = '\0';
  125. } /* __PHYSFS_setError */
  126. const char *PHYSFS_getLastError(void)
  127. {
  128. ErrMsg *err = findErrorForCurrentThread();
  129. if ((err == NULL) || (!err->errorAvailable))
  130. return(NULL);
  131. err->errorAvailable = 0;
  132. return(err->errorString);
  133. } /* PHYSFS_getLastError */
  134. /* MAKE SURE that errorLock is held before calling this! */
  135. static void freeErrorMessages(void)
  136. {
  137. ErrMsg *i;
  138. ErrMsg *next;
  139. for (i = errorMessages; i != NULL; i = next)
  140. {
  141. next = i->next;
  142. free(i);
  143. } /* for */
  144. } /* freeErrorMessages */
  145. void PHYSFS_getLinkedVersion(PHYSFS_Version *ver)
  146. {
  147. if (ver != NULL)
  148. {
  149. ver->major = PHYSFS_VER_MAJOR;
  150. ver->minor = PHYSFS_VER_MINOR;
  151. ver->patch = PHYSFS_VER_PATCH;
  152. } /* if */
  153. } /* PHYSFS_getLinkedVersion */
  154. static DirHandle *openDirectory(const char *d, int forWriting)
  155. {
  156. const DirFunctions **i;
  157. BAIL_IF_MACRO(!__PHYSFS_platformExists(d), ERR_NO_SUCH_FILE, NULL);
  158. for (i = dirFunctions; *i != NULL; i++)
  159. {
  160. if ((*i)->isArchive(d, forWriting))
  161. return( (*i)->openArchive(d, forWriting) );
  162. } /* for */
  163. __PHYSFS_setError(ERR_UNSUPPORTED_ARCHIVE);
  164. return(NULL);
  165. } /* openDirectory */
  166. static PhysDirInfo *buildDirInfo(const char *newDir, int forWriting)
  167. {
  168. DirHandle *dirHandle = NULL;
  169. PhysDirInfo *di = NULL;
  170. BAIL_IF_MACRO(newDir == NULL, ERR_INVALID_ARGUMENT, 0);
  171. dirHandle = openDirectory(newDir, forWriting);
  172. BAIL_IF_MACRO(dirHandle == NULL, NULL, 0);
  173. di = (PhysDirInfo *) malloc(sizeof (PhysDirInfo));
  174. if (di == NULL)
  175. {
  176. dirHandle->funcs->dirClose(dirHandle);
  177. BAIL_IF_MACRO(di == NULL, ERR_OUT_OF_MEMORY, 0);
  178. } /* if */
  179. di->dirName = (char *) malloc(strlen(newDir) + 1);
  180. if (di->dirName == NULL)
  181. {
  182. free(di);
  183. dirHandle->funcs->dirClose(dirHandle);
  184. BAIL_MACRO(ERR_OUT_OF_MEMORY, 0);
  185. } /* if */
  186. di->next = NULL;
  187. di->dirHandle = dirHandle;
  188. strcpy(di->dirName, newDir);
  189. return(di);
  190. } /* buildDirInfo */
  191. /* MAKE SURE you've got the stateLock held before calling this! */
  192. static int freeDirInfo(PhysDirInfo *di, FileHandleList *openList)
  193. {
  194. FileHandleList *i;
  195. if (di == NULL)
  196. return(1);
  197. for (i = openList; i != NULL; i = i->next)
  198. {
  199. const DirHandle *h = ((FileHandle *) &(i->handle.opaque))->dirHandle;
  200. BAIL_IF_MACRO(h == di->dirHandle, ERR_FILES_STILL_OPEN, 0);
  201. } /* for */
  202. di->dirHandle->funcs->dirClose(di->dirHandle);
  203. free(di->dirName);
  204. free(di);
  205. return(1);
  206. } /* freeDirInfo */
  207. static char *calculateUserDir(void)
  208. {
  209. char *retval = NULL;
  210. const char *str = NULL;
  211. str = __PHYSFS_platformGetUserDir();
  212. if (str != NULL)
  213. retval = (char *) str;
  214. else
  215. {
  216. const char *dirsep = PHYSFS_getDirSeparator();
  217. const char *uname = __PHYSFS_platformGetUserName();
  218. str = (uname != NULL) ? uname : "default";
  219. retval = (char *) malloc(strlen(baseDir) + strlen(str) +
  220. strlen(dirsep) + 6);
  221. if (retval == NULL)
  222. __PHYSFS_setError(ERR_OUT_OF_MEMORY);
  223. else
  224. sprintf(retval, "%susers%s%s", baseDir, dirsep, str);
  225. if (uname != NULL)
  226. free((void *) uname);
  227. } /* else */
  228. return(retval);
  229. } /* calculateUserDir */
  230. static int appendDirSep(char **dir)
  231. {
  232. const char *dirsep = PHYSFS_getDirSeparator();
  233. char *ptr;
  234. if (strcmp((*dir + strlen(*dir)) - strlen(dirsep), dirsep) == 0)
  235. return(1);
  236. ptr = realloc(*dir, strlen(*dir) + strlen(dirsep) + 1);
  237. if (!ptr)
  238. {
  239. free(*dir);
  240. return(0);
  241. } /* if */
  242. strcat(ptr, dirsep);
  243. *dir = ptr;
  244. return(1);
  245. } /* appendDirSep */
  246. static char *calculateBaseDir(const char *argv0)
  247. {
  248. const char *dirsep = PHYSFS_getDirSeparator();
  249. char *retval;
  250. char *ptr;
  251. /*
  252. * See if the platform driver wants to handle this for us...
  253. */
  254. retval = __PHYSFS_platformCalcBaseDir(argv0);
  255. if (retval != NULL)
  256. return(retval);
  257. /*
  258. * Determine if there's a path on argv0. If there is, that's the base dir.
  259. */
  260. ptr = strstr(argv0, dirsep);
  261. if (ptr != NULL)
  262. {
  263. char *p = ptr;
  264. size_t size;
  265. while (p != NULL)
  266. {
  267. ptr = p;
  268. p = strstr(p + 1, dirsep);
  269. } /* while */
  270. size = (size_t) (ptr - argv0); /* !!! is this portable? */
  271. retval = (char *) malloc(size + 1);
  272. BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
  273. memcpy(retval, argv0, size);
  274. retval[size] = '\0';
  275. return(retval);
  276. } /* if */
  277. /*
  278. * Last ditch effort: it's the current working directory. (*shrug*)
  279. */
  280. retval = __PHYSFS_platformCurrentDir();
  281. if(retval != NULL) {
  282. return(retval);
  283. }
  284. /*
  285. * Ok, current directory doesn't exist, use the root directory.
  286. * Not a good alternative, but it only happens if the current
  287. * directory was deleted from under the program.
  288. */
  289. retval = (char *) malloc(strlen(dirsep) + 1);
  290. strcpy(retval, dirsep);
  291. return(retval);
  292. } /* calculateBaseDir */
  293. static int initializeMutexes(void)
  294. {
  295. errorLock = __PHYSFS_platformCreateMutex();
  296. if (errorLock == NULL)
  297. goto initializeMutexes_failed;
  298. stateLock = __PHYSFS_platformCreateMutex();
  299. if (stateLock == NULL)
  300. goto initializeMutexes_failed;
  301. return(1); /* success. */
  302. initializeMutexes_failed:
  303. if (errorLock != NULL)
  304. __PHYSFS_platformDestroyMutex(errorLock);
  305. if (stateLock != NULL)
  306. __PHYSFS_platformDestroyMutex(stateLock);
  307. errorLock = stateLock = NULL;
  308. return(0); /* failed. */
  309. } /* initializeMutexes */
  310. int PHYSFS_init(const char *argv0)
  311. {
  312. char *ptr;
  313. BAIL_IF_MACRO(initialized, ERR_IS_INITIALIZED, 0);
  314. BAIL_IF_MACRO(!__PHYSFS_platformInit(), NULL, 0);
  315. BAIL_IF_MACRO(!initializeMutexes(), NULL, 0);
  316. baseDir = calculateBaseDir(argv0);
  317. BAIL_IF_MACRO(baseDir == NULL, NULL, 0);
  318. ptr = __PHYSFS_platformRealPath(baseDir);
  319. free(baseDir);
  320. BAIL_IF_MACRO(ptr == NULL, NULL, 0);
  321. baseDir = ptr;
  322. BAIL_IF_MACRO(!appendDirSep(&baseDir), NULL, 0);
  323. userDir = calculateUserDir();
  324. if (userDir != NULL)
  325. {
  326. ptr = __PHYSFS_platformRealPath(userDir);
  327. free(userDir);
  328. userDir = ptr;
  329. } /* if */
  330. if ((userDir == NULL) || (!appendDirSep(&userDir)))
  331. {
  332. free(baseDir);
  333. baseDir = NULL;
  334. return(0);
  335. } /* if */
  336. initialized = 1;
  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 ... */