macclassic.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. * GetDefaultUser() from PPCToolbox.h isn't supported in CarbonLib, for one.
  16. */
  17. #ifdef __PHYSFS_CARBONIZED__
  18. #include <Carbon.h>
  19. #else
  20. #include <OSUtils.h>
  21. #include <Processes.h>
  22. #include <Files.h>
  23. #include <PPCToolbox.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. Str32 name;
  101. UInt32 ref;
  102. BAIL_IF_MACRO(GetDefaultUser(&ref, name) != noErr, ERR_OS_ERROR, NULL);
  103. retval = (char *) malloc(name[0] + 1);
  104. BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
  105. memcpy(retval, &name[1], name[0]);
  106. retval[name[0]] = '\0'; /* null-terminate it. */
  107. return(retval);
  108. } /* __PHYSFS_platformGetUserName */
  109. char *__PHYSFS_platformGetUserDir(void)
  110. {
  111. return(NULL); /* bah...use default behaviour, I guess. */
  112. } /* __PHYSFS_platformGetUserDir */
  113. PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
  114. {
  115. return(1); /* single threaded. */
  116. } /* __PHYSFS_platformGetThreadID */
  117. int __PHYSFS_platformStricmp(const char *x, const char *y)
  118. {
  119. extern int _stricmp(const char *, const char *);
  120. return(_stricmp(x, y)); /* (*shrug*) */
  121. } /* __PHYSFS_platformStricmp */
  122. int __PHYSFS_platformExists(const char *fname)
  123. {
  124. BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0);
  125. } /* __PHYSFS_platformExists */
  126. int __PHYSFS_platformIsSymLink(const char *fname)
  127. {
  128. return(0); /* !!! FIXME: What happens if (fname) is an alias? */
  129. } /* __PHYSFS_platformIsSymlink */
  130. int __PHYSFS_platformIsDirectory(const char *fname)
  131. {
  132. BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0);
  133. } /* __PHYSFS_platformIsDirectory */
  134. char *__PHYSFS_platformCvtToDependent(const char *prepend,
  135. const char *dirName,
  136. const char *append)
  137. {
  138. BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
  139. } /* __PHYSFS_platformCvtToDependent */
  140. /* Much like my college days, try to sleep for 10 milliseconds at a time... */
  141. void __PHYSFS_platformTimeslice(void)
  142. {
  143. } /* __PHYSFS_platformTimeslice */
  144. LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
  145. int omitSymLinks)
  146. {
  147. BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
  148. } /* __PHYSFS_platformEnumerateFiles */
  149. char *__PHYSFS_platformCurrentDir(void)
  150. {
  151. BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
  152. } /* __PHYSFS_platformCurrentDir */
  153. char *__PHYSFS_platformRealPath(const char *path)
  154. {
  155. /* !!! FIXME: This isn't nearly right. */
  156. char *retval = (char *) malloc(strlen(path) + 1);
  157. strcpy(retval, path);
  158. return(retval);
  159. } /* __PHYSFS_platformRealPath */
  160. int __PHYSFS_platformMkDir(const char *path)
  161. {
  162. BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0);
  163. } /* __PHYSFS_platformMkDir */
  164. void *__PHYSFS_platformOpenRead(const char *filename)
  165. {
  166. BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
  167. } /* __PHYSFS_platformOpenRead */
  168. void *__PHYSFS_platformOpenWrite(const char *filename)
  169. {
  170. BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
  171. } /* __PHYSFS_platformOpenWrite */
  172. void *__PHYSFS_platformOpenAppend(const char *filename)
  173. {
  174. BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
  175. } /* __PHYSFS_platformOpenAppend */
  176. PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
  177. PHYSFS_uint32 size, PHYSFS_uint32 count)
  178. {
  179. BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
  180. } /* __PHYSFS_platformRead */
  181. PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
  182. PHYSFS_uint32 size, PHYSFS_uint32 count)
  183. {
  184. BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
  185. } /* __PHYSFS_platformWrite */
  186. int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
  187. {
  188. BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
  189. } /* __PHYSFS_platformSeek */
  190. PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
  191. {
  192. BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
  193. } /* __PHYSFS_platformTell */
  194. PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
  195. {
  196. BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
  197. } /* __PHYSFS_platformFileLength */
  198. int __PHYSFS_platformEOF(void *opaque)
  199. {
  200. BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
  201. } /* __PHYSFS_platformEOF */
  202. int __PHYSFS_platformFlush(void *opaque)
  203. {
  204. BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0);
  205. } /* __PHYSFS_platformFlush */
  206. int __PHYSFS_platformClose(void *opaque)
  207. {
  208. BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0);
  209. } /* __PHYSFS_platformClose */
  210. int __PHYSFS_platformDelete(const char *path)
  211. {
  212. BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0);
  213. } /* __PHYSFS_platformDelete */
  214. void *__PHYSFS_platformCreateMutex(void)
  215. {
  216. return((void *) 0x0001); /* no mutexes on MacOS Classic. */
  217. } /* __PHYSFS_platformCreateMutex */
  218. void __PHYSFS_platformDestroyMutex(void *mutex)
  219. {
  220. /* no mutexes on MacOS Classic. */
  221. } /* __PHYSFS_platformDestroyMutex */
  222. int __PHYSFS_platformGrabMutex(void *mutex)
  223. {
  224. return(1); /* no mutexes on MacOS Classic. */
  225. } /* __PHYSFS_platformGrabMutex */
  226. void __PHYSFS_platformReleaseMutex(void *mutex)
  227. {
  228. /* no mutexes on MacOS Classic. */
  229. } /* __PHYSFS_platformReleaseMutex */
  230. /* end of unix.c ... */