macclassic.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. /*
  2. * MacOS Classic support routines for PhysicsFS.
  3. *
  4. * Please see the file LICENSE in the source's root directory.
  5. *
  6. * This file written by Ryan C. Gordon.
  7. */
  8. #include <stdlib.h>
  9. #include <string.h>
  10. /*
  11. * Please note that I haven't tried this code with CarbonLib or under
  12. * MacOS X at all. The code in unix.c is known to work with Darwin,
  13. * and you may or may not be better off using that.
  14. */
  15. #ifdef __PHYSFS_CARBONIZED__
  16. #include <Carbon.h>
  17. #else
  18. #include <OSUtils.h>
  19. #include <Processes.h>
  20. #include <Files.h>
  21. #include <TextUtils.h>
  22. #include <Resources.h>
  23. #include <MacMemory.h>
  24. #endif
  25. #define __PHYSICSFS_INTERNAL__
  26. #include "physfs_internal.h"
  27. const char *__PHYSFS_platformDirSeparator = ":";
  28. int __PHYSFS_platformInit(void)
  29. {
  30. return(1); /* always succeeds. */
  31. } /* __PHYSFS_platformInit */
  32. int __PHYSFS_platformDeinit(void)
  33. {
  34. return(1); /* always succeed. */
  35. } /* __PHYSFS_platformDeinit */
  36. char **__PHYSFS_platformDetectAvailableCDs(void)
  37. {
  38. BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
  39. } /* __PHYSFS_platformDetectAvailableCDs */
  40. char *__PHYSFS_platformCalcBaseDir(const char *argv0)
  41. {
  42. char *ptr;
  43. char *retval = NULL;
  44. UInt32 retLength = 0;
  45. ProcessSerialNumber psn;
  46. struct ProcessInfoRec procInfo;
  47. FSSpec spec;
  48. CInfoPBRec infoPB;
  49. OSErr err;
  50. Str255 str255;
  51. /* Get the FSSpecPtr of the current process's binary... */
  52. BAIL_IF_MACRO(GetCurrentProcess(&psn) != noErr, ERR_OS_ERROR, NULL);
  53. memset(&procInfo, '\0', sizeof (procInfo));
  54. procInfo.processInfoLength = sizeof (procInfo);
  55. procInfo.processAppSpec = &spec;
  56. err = GetProcessInformation(&psn, &procInfo);
  57. BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, NULL);
  58. /* Get the name of the binary's parent directory. */
  59. memset(&infoPB, '\0', sizeof (CInfoPBRec));
  60. infoPB.dirInfo.ioNamePtr = str255; /* put name in here. */
  61. infoPB.dirInfo.ioVRefNum = spec.vRefNum; /* ID of bin's volume. */
  62. infoPB.dirInfo.ioDrParID = spec.parID; /* ID of bin's dir. */
  63. infoPB.dirInfo.ioFDirIndex = -1; /* get dir (not file) info. */
  64. /* walk the tree back to the root dir (volume), building path string... */
  65. do
  66. {
  67. /* check parent dir of what we last looked at... */
  68. infoPB.dirInfo.ioDrDirID = infoPB.dirInfo.ioDrParID;
  69. if (PBGetCatInfoAsync(&infoPB) != noErr)
  70. {
  71. if (retval != NULL)
  72. free(retval);
  73. BAIL_MACRO(ERR_OS_ERROR, NULL);
  74. } /* if */
  75. /* allocate more space for the retval... */
  76. retLength += str255[0] + 1; /* + 1 for a ':' or null char... */
  77. ptr = (char *) malloc(retLength);
  78. if (ptr == NULL)
  79. {
  80. if (retval != NULL)
  81. free(retval);
  82. BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
  83. } /* if */
  84. /* prepend new dir to retval and cleanup... */
  85. memcpy(ptr, &str255[1], str255[0]);
  86. ptr[str255[0]] = '\0'; /* null terminate it. */
  87. if (retval != NULL)
  88. {
  89. strcat(ptr, ":");
  90. strcat(ptr, retval);
  91. free(retval);
  92. } /* if */
  93. retval = ptr;
  94. } while (infoPB.dirInfo.ioDrDirID != fsRtDirID);
  95. return(retval);
  96. } /* __PHYSFS_platformCalcBaseDir */
  97. char *__PHYSFS_platformGetUserName(void)
  98. {
  99. char *retval = NULL;
  100. StringHandle strHandle;
  101. short origResourceFile = CurResFile();
  102. /* use the System resource file. */
  103. UseResFile(0);
  104. /* apparently, -16096 specifies the username. */
  105. strHandle = GetString(-16096);
  106. UseResFile(origResourceFile);
  107. BAIL_IF_MACRO(strHandle == NULL, ERR_OS_ERROR, NULL);
  108. HLock((Handle) strHandle);
  109. retval = (char *) malloc((*strHandle)[0] + 1);
  110. if (retval == NULL)
  111. {
  112. HUnlock((Handle) strHandle);
  113. BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
  114. } /* if */
  115. memcpy(retval, &(*strHandle)[1], (*strHandle)[0]);
  116. retval[(*strHandle)[0]] = '\0'; /* null-terminate it. */
  117. HUnlock((Handle) strHandle);
  118. return(retval);
  119. } /* __PHYSFS_platformGetUserName */
  120. char *__PHYSFS_platformGetUserDir(void)
  121. {
  122. return(NULL); /* bah...use default behaviour, I guess. */
  123. } /* __PHYSFS_platformGetUserDir */
  124. PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
  125. {
  126. return(1); /* single threaded. */
  127. } /* __PHYSFS_platformGetThreadID */
  128. int __PHYSFS_platformStricmp(const char *x, const char *y)
  129. {
  130. extern int _stricmp(const char *, const char *);
  131. return(_stricmp(x, y)); /* (*shrug*) */
  132. } /* __PHYSFS_platformStricmp */
  133. int __PHYSFS_platformExists(const char *fname)
  134. {
  135. BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0);
  136. } /* __PHYSFS_platformExists */
  137. int __PHYSFS_platformIsSymLink(const char *fname)
  138. {
  139. return(0); /* !!! FIXME: What happens if (fname) is an alias? */
  140. } /* __PHYSFS_platformIsSymlink */
  141. int __PHYSFS_platformIsDirectory(const char *fname)
  142. {
  143. BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0);
  144. } /* __PHYSFS_platformIsDirectory */
  145. char *__PHYSFS_platformCvtToDependent(const char *prepend,
  146. const char *dirName,
  147. const char *append)
  148. {
  149. BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
  150. } /* __PHYSFS_platformCvtToDependent */
  151. /* Much like my college days, try to sleep for 10 milliseconds at a time... */
  152. void __PHYSFS_platformTimeslice(void)
  153. {
  154. } /* __PHYSFS_platformTimeslice */
  155. LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
  156. int omitSymLinks)
  157. {
  158. BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
  159. } /* __PHYSFS_platformEnumerateFiles */
  160. char *__PHYSFS_platformCurrentDir(void)
  161. {
  162. BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
  163. } /* __PHYSFS_platformCurrentDir */
  164. char *__PHYSFS_platformRealPath(const char *path)
  165. {
  166. /* !!! FIXME: This isn't nearly right. */
  167. char *retval = (char *) malloc(strlen(path) + 1);
  168. strcpy(retval, path);
  169. return(retval);
  170. } /* __PHYSFS_platformRealPath */
  171. int __PHYSFS_platformMkDir(const char *path)
  172. {
  173. BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0);
  174. } /* __PHYSFS_platformMkDir */
  175. void *__PHYSFS_platformOpenRead(const char *filename)
  176. {
  177. BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
  178. } /* __PHYSFS_platformOpenRead */
  179. void *__PHYSFS_platformOpenWrite(const char *filename)
  180. {
  181. BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
  182. } /* __PHYSFS_platformOpenWrite */
  183. void *__PHYSFS_platformOpenAppend(const char *filename)
  184. {
  185. BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
  186. } /* __PHYSFS_platformOpenAppend */
  187. PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
  188. PHYSFS_uint32 size, PHYSFS_uint32 count)
  189. {
  190. BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
  191. } /* __PHYSFS_platformRead */
  192. PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
  193. PHYSFS_uint32 size, PHYSFS_uint32 count)
  194. {
  195. BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
  196. } /* __PHYSFS_platformWrite */
  197. int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
  198. {
  199. BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
  200. } /* __PHYSFS_platformSeek */
  201. PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
  202. {
  203. BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
  204. } /* __PHYSFS_platformTell */
  205. PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
  206. {
  207. BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
  208. } /* __PHYSFS_platformFileLength */
  209. int __PHYSFS_platformEOF(void *opaque)
  210. {
  211. BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
  212. } /* __PHYSFS_platformEOF */
  213. int __PHYSFS_platformFlush(void *opaque)
  214. {
  215. BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0);
  216. } /* __PHYSFS_platformFlush */
  217. int __PHYSFS_platformClose(void *opaque)
  218. {
  219. BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0);
  220. } /* __PHYSFS_platformClose */
  221. int __PHYSFS_platformDelete(const char *path)
  222. {
  223. BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0);
  224. } /* __PHYSFS_platformDelete */
  225. void *__PHYSFS_platformCreateMutex(void)
  226. {
  227. return((void *) 0x0001); /* no mutexes on MacOS Classic. */
  228. } /* __PHYSFS_platformCreateMutex */
  229. void __PHYSFS_platformDestroyMutex(void *mutex)
  230. {
  231. /* no mutexes on MacOS Classic. */
  232. } /* __PHYSFS_platformDestroyMutex */
  233. int __PHYSFS_platformGrabMutex(void *mutex)
  234. {
  235. return(1); /* no mutexes on MacOS Classic. */
  236. } /* __PHYSFS_platformGrabMutex */
  237. void __PHYSFS_platformReleaseMutex(void *mutex)
  238. {
  239. /* no mutexes on MacOS Classic. */
  240. } /* __PHYSFS_platformReleaseMutex */
  241. /* end of unix.c ... */