platform/macclassic.c
changeset 157 916ee05fe0db
child 158 ecc4a7f173c1
equal deleted inserted replaced
156:f45e26b5f398 157:916ee05fe0db
       
     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 
       
     9 #include <stdlib.h>
       
    10 #include <string.h>
       
    11 
       
    12 /*
       
    13  * Please note that I haven't tried this code with CarbonLib or under
       
    14  *  MacOS X at all. The code in unix.c is known to work with Darwin,
       
    15  *  and you may or may not be better off using that.
       
    16  *
       
    17  * GetDefaultUser() from PPCToolbox.h isn't supported in CarbonLib, for one.
       
    18  */
       
    19 #ifdef __PHYSFS_CARBONIZED__   
       
    20 #include <Carbon.h>
       
    21 #else
       
    22 #include <OSUtils.h>
       
    23 #include <Processes.h>
       
    24 #include <Files.h>
       
    25 #include <PPCToolbox.h>
       
    26 #endif
       
    27 
       
    28 #define __PHYSICSFS_INTERNAL__
       
    29 #include "physfs_internal.h"
       
    30 
       
    31 
       
    32 const char *__PHYSFS_platformDirSeparator = ":";
       
    33 
       
    34 
       
    35 int __PHYSFS_platformInit(void)
       
    36 {
       
    37     return(1); /* always succeeds. */
       
    38 } /* __PHYSFS_platformInit */
       
    39 
       
    40 
       
    41 int __PHYSFS_platformDeinit(void)
       
    42 {
       
    43     return(1);  /* always succeed. */
       
    44 } /* __PHYSFS_platformDeinit */
       
    45 
       
    46 
       
    47 char **__PHYSFS_platformDetectAvailableCDs(void)
       
    48 {
       
    49     BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
       
    50 } /* __PHYSFS_platformDetectAvailableCDs */
       
    51 
       
    52 
       
    53 char *__PHYSFS_platformCalcBaseDir(const char *argv0)
       
    54 {
       
    55     char *ptr;
       
    56     char *retval = NULL;
       
    57     UInt32 retLength = 0;
       
    58     ProcessSerialNumber psn;
       
    59     struct ProcessInfoRec procInfo;
       
    60     FSSpec spec;
       
    61     CInfoPBRec infoPB;
       
    62     OSErr err;
       
    63     Str255 str255;
       
    64     
       
    65     /* Get the FSSpecPtr of the current process's binary... */
       
    66     BAIL_IF_MACRO(GetCurrentProcess(&psn) != noErr, ERR_OS_ERROR, NULL);
       
    67     memset(&procInfo, '\0', sizeof (procInfo));
       
    68     procInfo.processInfoLength = sizeof (procInfo);
       
    69     procInfo.processAppSpec = &spec;
       
    70     err = GetProcessInformation(&psn, &procInfo);
       
    71     BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, NULL);
       
    72 
       
    73     /* Get the name of the binary's parent directory. */
       
    74     memset(&infoPB, '\0', sizeof (CInfoPBRec));
       
    75     infoPB.dirInfo.ioNamePtr = str255;       /* put name in here.         */
       
    76     infoPB.dirInfo.ioVRefNum = spec.vRefNum;  /* ID of bin's volume.       */ 
       
    77     infoPB.dirInfo.ioDrParID = spec.parID;    /* ID of bin's dir.          */
       
    78     infoPB.dirInfo.ioFDirIndex = -1;          /* get dir (not file) info.  */
       
    79 
       
    80     /* walk the tree back to the root dir (volume), building path string... */
       
    81     do
       
    82     {
       
    83         /* check parent dir of what we last looked at... */
       
    84         infoPB.dirInfo.ioDrDirID = infoPB.dirInfo.ioDrParID;
       
    85         if (PBGetCatInfoAsync(&infoPB) != noErr)
       
    86         {
       
    87             if (retval != NULL)
       
    88                 free(retval);
       
    89             BAIL_MACRO(ERR_OS_ERROR, NULL);
       
    90         } /* if */
       
    91         
       
    92         /* allocate more space for the retval... */
       
    93         retLength += str255[0] + 1; /* + 1 for a ':' or null char... */
       
    94         ptr = (char *) malloc(retLength);
       
    95         if (ptr == NULL)
       
    96         {
       
    97             if (retval != NULL)
       
    98                 free(retval);
       
    99             BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
       
   100         } /* if */
       
   101 
       
   102         /* prepend new dir to retval and cleanup... */
       
   103         memcpy(ptr, &str255[1], str255[0]);
       
   104         ptr[str255[0]] = '\0';  /* null terminate it. */
       
   105         if (retval != NULL)
       
   106         {
       
   107             strcat(ptr, ":");
       
   108             strcat(ptr, retval);
       
   109             free(retval);
       
   110         } /* if */
       
   111         retval = ptr;
       
   112     } while (infoPB.dirInfo.ioDrDirID != fsRtDirID);
       
   113 
       
   114     return(retval);
       
   115 } /* __PHYSFS_platformCalcBaseDir */
       
   116 
       
   117 
       
   118 char *__PHYSFS_platformGetUserName(void)
       
   119 {
       
   120     char *retval = NULL;
       
   121     Str32 name;
       
   122     UInt32 ref;
       
   123     BAIL_IF_MACRO(GetDefaultUser(&ref, name) != noErr, ERR_OS_ERROR, NULL);
       
   124 
       
   125     retval = (char *) malloc(name[0] + 1);
       
   126     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
       
   127     memcpy(retval, &name[1], name[0]);
       
   128     retval[name[0]] = '\0';  /* null-terminate it. */
       
   129     return(retval);
       
   130 } /* __PHYSFS_platformGetUserName */
       
   131 
       
   132 
       
   133 char *__PHYSFS_platformGetUserDir(void)
       
   134 {
       
   135     return(NULL);  /* bah...use default behaviour, I guess. */
       
   136 } /* __PHYSFS_platformGetUserDir */
       
   137 
       
   138 
       
   139 PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
       
   140 {
       
   141     return(1);  /* single threaded. */
       
   142 } /* __PHYSFS_platformGetThreadID */
       
   143 
       
   144 
       
   145 int __PHYSFS_platformStricmp(const char *x, const char *y)
       
   146 {
       
   147     extern int _stricmp(const char *, const char *);
       
   148     return(_stricmp(x, y));  /* (*shrug*) */
       
   149 } /* __PHYSFS_platformStricmp */
       
   150 
       
   151 
       
   152 int __PHYSFS_platformExists(const char *fname)
       
   153 {
       
   154     BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0);
       
   155 } /* __PHYSFS_platformExists */
       
   156 
       
   157 
       
   158 int __PHYSFS_platformIsSymLink(const char *fname)
       
   159 {
       
   160     return(0);  /* !!! FIXME: What happens if (fname) is an alias? */
       
   161 } /* __PHYSFS_platformIsSymlink */
       
   162 
       
   163 
       
   164 int __PHYSFS_platformIsDirectory(const char *fname)
       
   165 {
       
   166     BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0);
       
   167 } /* __PHYSFS_platformIsDirectory */
       
   168 
       
   169 
       
   170 char *__PHYSFS_platformCvtToDependent(const char *prepend,
       
   171                                       const char *dirName,
       
   172                                       const char *append)
       
   173 {
       
   174     BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
       
   175 } /* __PHYSFS_platformCvtToDependent */
       
   176 
       
   177 
       
   178 /* Much like my college days, try to sleep for 10 milliseconds at a time... */
       
   179 void __PHYSFS_platformTimeslice(void)
       
   180 {
       
   181 } /* __PHYSFS_platformTimeslice */
       
   182 
       
   183 
       
   184 LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
       
   185                                                   int omitSymLinks)
       
   186 {
       
   187     BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
       
   188 } /* __PHYSFS_platformEnumerateFiles */
       
   189 
       
   190 
       
   191 char *__PHYSFS_platformCurrentDir(void)
       
   192 {
       
   193     BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
       
   194 } /* __PHYSFS_platformCurrentDir */
       
   195 
       
   196 
       
   197 char *__PHYSFS_platformRealPath(const char *path)
       
   198 {
       
   199     /* !!! FIXME: This isn't nearly right. */
       
   200     char *retval = (char *) malloc(strlen(path) + 1);
       
   201     strcpy(retval, path);
       
   202     return(retval);
       
   203 } /* __PHYSFS_platformRealPath */
       
   204 
       
   205 
       
   206 int __PHYSFS_platformMkDir(const char *path)
       
   207 {
       
   208     BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0);
       
   209 } /* __PHYSFS_platformMkDir */
       
   210 
       
   211 
       
   212 void *__PHYSFS_platformOpenRead(const char *filename)
       
   213 {
       
   214     BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
       
   215 } /* __PHYSFS_platformOpenRead */
       
   216 
       
   217 
       
   218 void *__PHYSFS_platformOpenWrite(const char *filename)
       
   219 {
       
   220     BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
       
   221 } /* __PHYSFS_platformOpenWrite */
       
   222 
       
   223 
       
   224 void *__PHYSFS_platformOpenAppend(const char *filename)
       
   225 {
       
   226     BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
       
   227 } /* __PHYSFS_platformOpenAppend */
       
   228 
       
   229 
       
   230 PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
       
   231                                     PHYSFS_uint32 size, PHYSFS_uint32 count)
       
   232 {
       
   233     BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
       
   234 } /* __PHYSFS_platformRead */
       
   235 
       
   236 
       
   237 PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
       
   238                                      PHYSFS_uint32 size, PHYSFS_uint32 count)
       
   239 {
       
   240     BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
       
   241 } /* __PHYSFS_platformWrite */
       
   242 
       
   243 
       
   244 int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
       
   245 {
       
   246     BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
       
   247 } /* __PHYSFS_platformSeek */
       
   248 
       
   249 
       
   250 PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
       
   251 {
       
   252     BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
       
   253 } /* __PHYSFS_platformTell */
       
   254 
       
   255 
       
   256 PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
       
   257 {
       
   258     BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
       
   259 } /* __PHYSFS_platformFileLength */
       
   260 
       
   261 
       
   262 int __PHYSFS_platformEOF(void *opaque)
       
   263 {
       
   264     BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
       
   265 } /* __PHYSFS_platformEOF */
       
   266 
       
   267 
       
   268 int __PHYSFS_platformFlush(void *opaque)
       
   269 {
       
   270     BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0);
       
   271 } /* __PHYSFS_platformFlush */
       
   272 
       
   273 
       
   274 int __PHYSFS_platformClose(void *opaque)
       
   275 {
       
   276     BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0);
       
   277 } /* __PHYSFS_platformClose */
       
   278 
       
   279 
       
   280 int __PHYSFS_platformDelete(const char *path)
       
   281 {
       
   282     BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0);
       
   283 } /* __PHYSFS_platformDelete */
       
   284 
       
   285 
       
   286 void *__PHYSFS_platformCreateMutex(void)
       
   287 {
       
   288     return((void *) 0x0001);  /* no mutexes on MacOS Classic. */
       
   289 } /* __PHYSFS_platformCreateMutex */
       
   290 
       
   291 
       
   292 void __PHYSFS_platformDestroyMutex(void *mutex)
       
   293 {
       
   294     /* no mutexes on MacOS Classic. */
       
   295 } /* __PHYSFS_platformDestroyMutex */
       
   296 
       
   297 
       
   298 int __PHYSFS_platformGrabMutex(void *mutex)
       
   299 {
       
   300     return(1);  /* no mutexes on MacOS Classic. */
       
   301 } /* __PHYSFS_platformGrabMutex */
       
   302 
       
   303 
       
   304 void __PHYSFS_platformReleaseMutex(void *mutex)
       
   305 {
       
   306     /* no mutexes on MacOS Classic. */
       
   307 } /* __PHYSFS_platformReleaseMutex */
       
   308 
       
   309 /* end of unix.c ... */
       
   310