src/platform_macosx.c
author Ryan C. Gordon <icculus@icculus.org>
Sat, 09 Jul 2011 23:11:17 -0700
changeset 1169 ceda1aef5617
parent 1112 12e187aa051c
child 1173 77b2df665bd1
permissions -rw-r--r--
Fixed basedir calculation on Mac OS X.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/*
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
 * Mac OS X support routines for PhysicsFS.
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 *
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
 * Please see the file LICENSE.txt in the source's root directory.
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 *
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
 *  This file written by Ryan C. Gordon.
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
 */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
#define __PHYSICSFS_INTERNAL__
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
#include "physfs_platforms.h"
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
#ifdef PHYSFS_PLATFORM_MACOSX
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
#include <Carbon/Carbon.h>
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
#include <IOKit/storage/IOMedia.h>
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
#include <IOKit/storage/IOCDMedia.h>
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
#include <IOKit/storage/IODVDMedia.h>
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
#include <sys/mount.h>
1169
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
    19
#include <sys/stat.h>
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
/* Seems to get defined in some system header... */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
#ifdef Free
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
#undef Free
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
#endif
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
#include "physfs_internal.h"
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
/* Wrap PHYSFS_Allocator in a CFAllocator... */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
static CFAllocatorRef cfallocator = NULL;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
CFStringRef cfallocDesc(const void *info)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
{
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
    return(CFStringCreateWithCString(cfallocator, "PhysicsFS",
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
                                     kCFStringEncodingASCII));
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
} /* cfallocDesc */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
static void *cfallocMalloc(CFIndex allocSize, CFOptionFlags hint, void *info)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
{
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
    return allocator.Malloc(allocSize);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
} /* cfallocMalloc */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
static void cfallocFree(void *ptr, void *info)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
{
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
    allocator.Free(ptr);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
} /* cfallocFree */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
static void *cfallocRealloc(void *ptr, CFIndex newsize,
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
                            CFOptionFlags hint, void *info)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
{
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
    if ((ptr == NULL) || (newsize <= 0))
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
        return NULL;  /* ADC docs say you should always return NULL here. */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
    return allocator.Realloc(ptr, newsize);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
} /* cfallocRealloc */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
int __PHYSFS_platformInit(void)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
{
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
    /* set up a CFAllocator, so Carbon can use the physfs allocator, too. */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
    CFAllocatorContext ctx;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
    memset(&ctx, '\0', sizeof (ctx));
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
    ctx.copyDescription = cfallocDesc;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
    ctx.allocate = cfallocMalloc;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
    ctx.reallocate = cfallocRealloc;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
    ctx.deallocate = cfallocFree;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
    cfallocator = CFAllocatorCreate(kCFAllocatorUseContext, &ctx);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
    BAIL_IF_MACRO(cfallocator == NULL, ERR_OUT_OF_MEMORY, 0);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1012
diff changeset
    71
    return 1;  /* success. */
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
} /* __PHYSFS_platformInit */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
int __PHYSFS_platformDeinit(void)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
{
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
    CFRelease(cfallocator);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
    cfallocator = NULL;
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1012
diff changeset
    79
    return 1;  /* always succeed. */
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
} /* __PHYSFS_platformDeinit */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
/* CD-ROM detection code... */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
/*
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
 * Code based on sample from Apple Developer Connection:
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
 *  http://developer.apple.com/samplecode/Sample_Code/Devices_and_Hardware/Disks/VolumeToBSDNode/VolumeToBSDNode.c.htm
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
 */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
static int darwinIsWholeMedia(io_service_t service)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
{
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
    int retval = 0;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
    CFTypeRef wholeMedia;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
    if (!IOObjectConformsTo(service, kIOMediaClass))
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1012
diff changeset
    96
        return 0;
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
        
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
    wholeMedia = IORegistryEntryCreateCFProperty(service,
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
                                                 CFSTR(kIOMediaWholeKey),
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
                                                 cfallocator, 0);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
    if (wholeMedia == NULL)
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1012
diff changeset
   102
        return 0;
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
    retval = CFBooleanGetValue(wholeMedia);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
    CFRelease(wholeMedia);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
    return retval;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
} /* darwinIsWholeMedia */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   109
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
static int darwinIsMountedDisc(char *bsdName, mach_port_t masterPort)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
{
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
    int retval = 0;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
    CFMutableDictionaryRef matchingDict;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
    kern_return_t rc;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
    io_iterator_t iter;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
    io_service_t service;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
    if ((matchingDict = IOBSDNameMatching(masterPort, 0, bsdName)) == NULL)
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1012
diff changeset
   120
        return 0;
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
    rc = IOServiceGetMatchingServices(masterPort, matchingDict, &iter);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
    if ((rc != KERN_SUCCESS) || (!iter))
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1012
diff changeset
   124
        return 0;
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
    service = IOIteratorNext(iter);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
    IOObjectRelease(iter);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
    if (!service)
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1012
diff changeset
   129
        return 0;
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
    rc = IORegistryEntryCreateIterator(service, kIOServicePlane,
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
             kIORegistryIterateRecursively | kIORegistryIterateParents, &iter);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
    
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
    if (!iter)
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1012
diff changeset
   135
        return 0;
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
    if (rc != KERN_SUCCESS)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
    {
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
        IOObjectRelease(iter);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1012
diff changeset
   140
        return 0;
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
    } /* if */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
    IOObjectRetain(service);  /* add an extra object reference... */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
    do
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
    {
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
        if (darwinIsWholeMedia(service))
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
        {
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
            if ( (IOObjectConformsTo(service, kIOCDMediaClass)) ||
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
                 (IOObjectConformsTo(service, kIODVDMediaClass)) )
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
            {
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
                retval = 1;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
            } /* if */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
        } /* if */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
        IOObjectRelease(service);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
    } while ((service = IOIteratorNext(iter)) && (!retval));
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
                
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
    IOObjectRelease(iter);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
    IOObjectRelease(service);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1012
diff changeset
   161
    return retval;
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
} /* darwinIsMountedDisc */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   164
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
{
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
    const char *devPrefix = "/dev/";
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   168
    const int prefixLen = strlen(devPrefix);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
    mach_port_t masterPort = 0;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
    struct statfs *mntbufp;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
    int i, mounts;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
    if (IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS)
867
ff3343429cb5 Don't put comments in BAIL_* macros where we want an empty argument...
Ryan C. Gordon <icculus@icculus.org>
parents: 847
diff changeset
   174
        BAIL_MACRO(ERR_OS_ERROR, ) /*return void*/;
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
    mounts = getmntinfo(&mntbufp, MNT_WAIT);  /* NOT THREAD SAFE! */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
    for (i = 0; i < mounts; i++)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
    {
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   179
        char *dev = mntbufp[i].f_mntfromname;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
        char *mnt = mntbufp[i].f_mntonname;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
        if (strncmp(dev, devPrefix, prefixLen) != 0)  /* a virtual device? */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
            continue;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
        dev += prefixLen;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
        if (darwinIsMountedDisc(dev, masterPort))
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
            cb(data, mnt);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
    } /* for */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   188
} /* __PHYSFS_platformDetectAvailableCDs */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   191
static char *convertCFString(CFStringRef cfstr)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
{
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
    CFIndex len = CFStringGetMaximumSizeForEncoding(CFStringGetLength(cfstr),
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
                                                    kCFStringEncodingUTF8) + 1;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
    char *retval = (char *) allocator.Malloc(len);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
    if (CFStringGetCString(cfstr, retval, len, kCFStringEncodingUTF8))
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
    {
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
        /* shrink overallocated buffer if possible... */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   201
        CFIndex newlen = strlen(retval) + 1;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
        if (newlen < len)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
        {
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
            void *ptr = allocator.Realloc(retval, newlen);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
            if (ptr != NULL)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
                retval = (char *) ptr;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
        } /* if */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
    } /* if */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   209
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
    else  /* probably shouldn't fail, but just in case... */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
    {
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
        allocator.Free(retval);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
        BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
    } /* else */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1012
diff changeset
   216
    return retval;
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217
} /* convertCFString */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   218
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   219
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   220
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   221
{
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   222
    ProcessSerialNumber psn = { 0, kCurrentProcess };
1169
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   223
    struct stat statbuf;
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   224
    FSRef fsref;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
    CFRange cfrange;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   226
    CFURLRef cfurl = NULL;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   227
    CFStringRef cfstr = NULL;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   228
    CFMutableStringRef cfmutstr = NULL;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   229
    char *retval = NULL;
1169
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   230
    char *cstr = NULL;
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   231
    int rc = 0;
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   232
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   233
    BAIL_IF_MACRO(GetProcessBundleLocation(&psn, &fsref) != noErr, NULL, NULL);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   234
    cfurl = CFURLCreateFromFSRef(cfallocator, &fsref);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   235
    BAIL_IF_MACRO(cfurl == NULL, NULL, NULL);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   236
    cfstr = CFURLCopyFileSystemPath(cfurl, kCFURLPOSIXPathStyle);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   237
    CFRelease(cfurl);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   238
    BAIL_IF_MACRO(cfstr == NULL, NULL, NULL);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   239
    cfmutstr = CFStringCreateMutableCopy(cfallocator, 0, cfstr);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   240
    CFRelease(cfstr);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   241
    BAIL_IF_MACRO(cfmutstr == NULL, NULL, NULL);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   242
1169
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   243
    /* we have to decide if we got a binary's path, or the .app dir... */
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   244
    cstr = convertCFString(cfmutstr);
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   245
    if (cstr == NULL)
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   246
    {
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   247
        CFRelease(cfmutstr);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1012
diff changeset
   248
        return NULL;
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   249
    } /* if */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   250
1169
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   251
    rc = stat(cstr, &statbuf);
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   252
    allocator.Free(cstr);  /* done with this. */
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   253
    if (rc == -1)
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   254
    {
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   255
        CFRelease(cfmutstr);
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   256
        return NULL;  /* maybe default behaviour will work? */
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   257
    } /* if */
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   258
1169
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   259
    if (S_ISREG(statbuf.st_mode))
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   260
    {
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   261
        /* Find last dirsep so we can chop the filename from the path. */
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   262
        cfrange = CFStringFind(cfmutstr, CFSTR("/"), kCFCompareBackwards);
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   263
        if (cfrange.location == kCFNotFound)
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   264
        {
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   265
            assert(0);  /* shouldn't ever hit this... */
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   266
            CFRelease(cfmutstr);
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   267
            return NULL;
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   268
        } /* if */
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   269
1169
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   270
        /* chop the "/exename" from the end of the path string... */
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   271
        cfrange.length = CFStringGetLength(cfmutstr) - cfrange.location;
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   272
        CFStringDelete(cfmutstr, cfrange);
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   273
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   274
        /* If we're an Application Bundle, chop everything but the base. */
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   275
        cfrange = CFStringFind(cfmutstr, CFSTR("/Contents/MacOS"),
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   276
                               kCFCompareCaseInsensitive |
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   277
                               kCFCompareBackwards |
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   278
                               kCFCompareAnchored);
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   279
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   280
        if (cfrange.location != kCFNotFound)
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   281
            CFStringDelete(cfmutstr, cfrange);  /* chop that, too. */
ceda1aef5617 Fixed basedir calculation on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1112
diff changeset
   282
    } /* if */
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   283
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   284
    retval = convertCFString(cfmutstr);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   285
    CFRelease(cfmutstr);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   286
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1012
diff changeset
   287
    return retval;  /* whew. */
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   288
} /* __PHYSFS_platformCalcBaseDir */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   289
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   290
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   291
/* !!! FIXME */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   292
#define osxerr(x) x
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   293
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   294
char *__PHYSFS_platformRealPath(const char *path)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   295
{
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   296
    /* The symlink and relative path resolving happens in FSPathMakeRef() */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   297
    FSRef fsref;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   298
    CFURLRef cfurl = NULL;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   299
    CFStringRef cfstr = NULL;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   300
    char *retval = NULL;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   301
    OSStatus rc = osxerr(FSPathMakeRef((UInt8 *) path, &fsref, NULL));
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   302
    BAIL_IF_MACRO(rc != noErr, NULL, NULL);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   303
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   304
    /* Now get it to spit out a full path. */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   305
    cfurl = CFURLCreateFromFSRef(cfallocator, &fsref);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   306
    BAIL_IF_MACRO(cfurl == NULL, ERR_OUT_OF_MEMORY, NULL);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   307
    cfstr = CFURLCopyFileSystemPath(cfurl, kCFURLPOSIXPathStyle);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   308
    CFRelease(cfurl);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   309
    BAIL_IF_MACRO(cfstr == NULL, ERR_OUT_OF_MEMORY, NULL);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   310
    retval = convertCFString(cfstr);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   311
    CFRelease(cfstr);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   312
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1012
diff changeset
   313
    return retval;
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   314
} /* __PHYSFS_platformRealPath */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   315
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   316
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   317
char *__PHYSFS_platformCurrentDir(void)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   318
{
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1012
diff changeset
   319
    return __PHYSFS_platformRealPath(".");  /* let CFURL sort it out. */
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   320
} /* __PHYSFS_platformCurrentDir */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   321
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   322
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   323
/* Platform allocator uses default CFAllocator at PHYSFS_init() time. */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   324
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   325
static CFAllocatorRef cfallocdef = NULL;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   326
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   327
static int macosxAllocatorInit(void)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   328
{
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   329
    int retval = 0;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   330
    cfallocdef = CFAllocatorGetDefault();
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   331
    retval = (cfallocdef != NULL);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   332
    if (retval)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   333
        CFRetain(cfallocdef);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1012
diff changeset
   334
    return retval;
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   335
} /* macosxAllocatorInit */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   336
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   337
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   338
static void macosxAllocatorDeinit(void)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   339
{
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   340
    if (cfallocdef != NULL)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   341
    {
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   342
        CFRelease(cfallocdef);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   343
        cfallocdef = NULL;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   344
    } /* if */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   345
} /* macosxAllocatorDeinit */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   346
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   347
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   348
static void *macosxAllocatorMalloc(PHYSFS_uint64 s)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   349
{
1112
12e187aa051c Made __PHYSFS_ui64FitsAddressSpace's behaviour match its name.
Ryan C. Gordon <icculus@icculus.org>
parents: 1016
diff changeset
   350
    BAIL_IF_MACRO(!__PHYSFS_ui64FitsAddressSpace(s), ERR_OUT_OF_MEMORY, NULL);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1012
diff changeset
   351
    return CFAllocatorAllocate(cfallocdef, (CFIndex) s, 0);
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   352
} /* macosxAllocatorMalloc */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   353
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   354
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   355
static void *macosxAllocatorRealloc(void *ptr, PHYSFS_uint64 s)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   356
{
1112
12e187aa051c Made __PHYSFS_ui64FitsAddressSpace's behaviour match its name.
Ryan C. Gordon <icculus@icculus.org>
parents: 1016
diff changeset
   357
    BAIL_IF_MACRO(!__PHYSFS_ui64FitsAddressSpace(s), ERR_OUT_OF_MEMORY, NULL);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1012
diff changeset
   358
    return CFAllocatorReallocate(cfallocdef, ptr, (CFIndex) s, 0);
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   359
} /* macosxAllocatorRealloc */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   360
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   361
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   362
static void macosxAllocatorFree(void *ptr)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   363
{
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   364
    CFAllocatorDeallocate(cfallocdef, ptr);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   365
} /* macosxAllocatorFree */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   366
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   367
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   368
int __PHYSFS_platformSetDefaultAllocator(PHYSFS_Allocator *a)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   369
{
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   370
    allocator.Init = macosxAllocatorInit;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   371
    allocator.Deinit = macosxAllocatorDeinit;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   372
    allocator.Malloc = macosxAllocatorMalloc;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   373
    allocator.Realloc = macosxAllocatorRealloc;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   374
    allocator.Free = macosxAllocatorFree;
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1012
diff changeset
   375
    return 1;  /* return non-zero: we're supplying custom allocator. */
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   376
} /* __PHYSFS_platformSetDefaultAllocator */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   377
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   378
1012
f254870dd7dd Attempt to clean up the thread ID mess in platform_unix ...
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   379
void *__PHYSFS_platformGetThreadID(void)
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   380
{
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1012
diff changeset
   381
    return ( (void *) ((size_t) MPCurrentTaskID()) );
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   382
} /* __PHYSFS_platformGetThreadID */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   383
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   384
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   385
void *__PHYSFS_platformCreateMutex(void)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   386
{
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   387
    MPCriticalRegionID m = NULL;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   388
    if (osxerr(MPCreateCriticalRegion(&m)) != noErr)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   389
        return NULL;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   390
    return m;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   391
} /* __PHYSFS_platformCreateMutex */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   392
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   393
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   394
void __PHYSFS_platformDestroyMutex(void *mutex)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   395
{
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   396
    MPCriticalRegionID m = (MPCriticalRegionID) mutex;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   397
    MPDeleteCriticalRegion(m);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   398
} /* __PHYSFS_platformDestroyMutex */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   399
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   400
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   401
int __PHYSFS_platformGrabMutex(void *mutex)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   402
{
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   403
    MPCriticalRegionID m = (MPCriticalRegionID) mutex;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   404
    if (MPEnterCriticalRegion(m, kDurationForever) != noErr)
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1012
diff changeset
   405
        return 0;
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1012
diff changeset
   406
    return 1;
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   407
} /* __PHYSFS_platformGrabMutex */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   408
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   409
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   410
void __PHYSFS_platformReleaseMutex(void *mutex)
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   411
{
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   412
    MPCriticalRegionID m = (MPCriticalRegionID) mutex;
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   413
    MPExitCriticalRegion(m);
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   414
} /* __PHYSFS_platformReleaseMutex */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   415
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   416
#endif /* PHYSFS_PLATFORM_MACOSX */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   417
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   418
/* end of macosx.c ... */
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   419