platform/macclassic.c
changeset 158 ecc4a7f173c1
parent 157 916ee05fe0db
child 162 06ed1dc94f73
equal deleted inserted replaced
157:916ee05fe0db 158:ecc4a7f173c1
    11 
    11 
    12 /*
    12 /*
    13  * Please note that I haven't tried this code with CarbonLib or under
    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,
    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.
    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  */
    16  */
    19 #ifdef __PHYSFS_CARBONIZED__   
    17 #ifdef __PHYSFS_CARBONIZED__   
    20 #include <Carbon.h>
    18 #include <Carbon.h>
    21 #else
    19 #else
    22 #include <OSUtils.h>
    20 #include <OSUtils.h>
    23 #include <Processes.h>
    21 #include <Processes.h>
    24 #include <Files.h>
    22 #include <Files.h>
    25 #include <PPCToolbox.h>
    23 #include <TextUtils.h>
       
    24 #include <Resources.h>
       
    25 #include <MacMemory.h>
    26 #endif
    26 #endif
    27 
    27 
    28 #define __PHYSICSFS_INTERNAL__
    28 #define __PHYSICSFS_INTERNAL__
    29 #include "physfs_internal.h"
    29 #include "physfs_internal.h"
    30 
    30 
   116 
   116 
   117 
   117 
   118 char *__PHYSFS_platformGetUserName(void)
   118 char *__PHYSFS_platformGetUserName(void)
   119 {
   119 {
   120     char *retval = NULL;
   120     char *retval = NULL;
   121     Str32 name;
   121     StringHandle strHandle;
   122     UInt32 ref;
   122     short origResourceFile = CurResFile();
   123     BAIL_IF_MACRO(GetDefaultUser(&ref, name) != noErr, ERR_OS_ERROR, NULL);
   123 
   124 
   124     /* use the System resource file. */
   125     retval = (char *) malloc(name[0] + 1);
   125     UseResFile(0);
   126     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
   126     /* apparently, -16096 specifies the username. */
   127     memcpy(retval, &name[1], name[0]);
   127     strHandle = GetString(-16096);
   128     retval[name[0]] = '\0';  /* null-terminate it. */
   128     UseResFile(origResourceFile);
       
   129     BAIL_IF_MACRO(strHandle == NULL, ERR_OS_ERROR, NULL);
       
   130 
       
   131     HLock((Handle) strHandle);
       
   132     retval = (char *) malloc((*strHandle)[0] + 1);
       
   133     if (retval == NULL)
       
   134     {
       
   135         HUnlock((Handle) strHandle);
       
   136         BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
       
   137     } /* if */
       
   138     memcpy(retval, &(*strHandle)[1], (*strHandle)[0]);
       
   139     retval[(*strHandle)[0]] = '\0';  /* null-terminate it. */
       
   140     HUnlock((Handle) strHandle);
       
   141 
   129     return(retval);
   142     return(retval);
   130 } /* __PHYSFS_platformGetUserName */
   143 } /* __PHYSFS_platformGetUserName */
   131 
   144 
   132 
   145 
   133 char *__PHYSFS_platformGetUserDir(void)
   146 char *__PHYSFS_platformGetUserDir(void)