src/physfs_platform_apple.m
author Ryan C. Gordon <icculus@icculus.org>
Sun, 17 May 2020 01:41:52 -0400
changeset 1691 c66c9326b05d
parent 1639 46561a309895
permissions -rw-r--r--
7z: Make error handling a little more robust.
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
/*
1549
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
     2
 * Apple platform (macOS, iOS, watchOS, etc) support routines for PhysicsFS.
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
     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__
1589
e4f75163b60d Cleaned up some header inclusion politics.
Ryan C. Gordon <icculus@icculus.org>
parents: 1551
diff changeset
    10
#include "physfs_platforms.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
    11
1549
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    12
#ifdef PHYSFS_PLATFORM_APPLE
1291
854cdfefdf12 For iOS, build the Mac OS X platform code, not the generic Unix code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1264
diff changeset
    13
1589
e4f75163b60d Cleaned up some header inclusion politics.
Ryan C. Gordon <icculus@icculus.org>
parents: 1551
diff changeset
    14
#include <Foundation/Foundation.h>
1549
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    15
1589
e4f75163b60d Cleaned up some header inclusion politics.
Ryan C. Gordon <icculus@icculus.org>
parents: 1551
diff changeset
    16
#include "physfs_internal.h"
1291
854cdfefdf12 For iOS, build the Mac OS X platform code, not the generic Unix code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1264
diff changeset
    17
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
    18
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
    19
{
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
    20
    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
    21
} /* __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
    22
5e5e6c067413 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
1536
c791c9aaa2a2 __PHYSFS_platformDeinit() should return void.
Ryan C. Gordon <icculus@icculus.org>
parents: 1513
diff changeset
    24
void __PHYSFS_platformDeinit(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
    25
{
1536
c791c9aaa2a2 __PHYSFS_platformDeinit() should return void.
Ryan C. Gordon <icculus@icculus.org>
parents: 1513
diff changeset
    26
    /* no-op */
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
    27
} /* __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
    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
1549
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    30
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    31
{
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    32
    @autoreleasepool
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    33
    {
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    34
        NSString *path = [[NSBundle mainBundle] bundlePath];
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    35
        BAIL_IF(!path, PHYSFS_ERR_OS_ERROR, NULL);
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    36
        size_t len = [path lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    37
        char *retval = (char *) allocator.Malloc(len + 2);
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    38
        BAIL_IF(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    39
        [path getCString:retval maxLength:len+1 encoding:NSUTF8StringEncoding];
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    40
        retval[len] = '/';
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    41
        retval[len+1] = '\0';
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    42
        return retval;  /* whew. */
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    43
    } /* @autoreleasepool */
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    44
} /* __PHYSFS_platformCalcBaseDir */
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    45
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    46
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    47
char *__PHYSFS_platformCalcPrefDir(const char *org, const char *app)
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    48
{
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    49
    @autoreleasepool
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    50
    {
1551
178e177063dd apple: Patched to compile on XCode versions < 7.
Ryan C. Gordon <icculus@icculus.org>
parents: 1549
diff changeset
    51
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, TRUE);
1549
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    52
        BAIL_IF(!paths, PHYSFS_ERR_OS_ERROR, NULL);
1639
46561a309895 apple: Patched to compile with older (mac 10.7) SDKs (thanks, Ken and Ryan!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1589
diff changeset
    53
        NSString *path = (NSString *) [paths objectAtIndex:0];
1549
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    54
        BAIL_IF(!path, PHYSFS_ERR_OS_ERROR, NULL);
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    55
        size_t len = [path lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    56
        const size_t applen = strlen(app);
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    57
        char *retval = (char *) allocator.Malloc(len + applen + 3);
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    58
        BAIL_IF(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    59
        [path getCString:retval maxLength:len+1 encoding:NSUTF8StringEncoding];
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    60
        snprintf(retval + len, applen + 3, "/%s/", app);
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    61
        return retval;  /* whew. */
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    62
    } /* @autoreleasepool */
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    63
} /* __PHYSFS_platformCalcPrefDir */
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    64
1291
854cdfefdf12 For iOS, build the Mac OS X platform code, not the generic Unix code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1264
diff changeset
    65
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
    66
/* 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
    67
5e5e6c067413 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
/*
5e5e6c067413 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
 * Code based on sample from Apple Developer Connection:
1373
527ef3c6a2d6 HTTPS all the things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1342
diff changeset
    70
 *  https://developer.apple.com/samplecode/Sample_Code/Devices_and_Hardware/Disks/VolumeToBSDNode/VolumeToBSDNode.c.htm
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
    71
 */
5e5e6c067413 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
1291
854cdfefdf12 For iOS, build the Mac OS X platform code, not the generic Unix code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1264
diff changeset
    73
#if !defined(PHYSFS_NO_CDROM_SUPPORT)
854cdfefdf12 For iOS, build the Mac OS X platform code, not the generic Unix code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1264
diff changeset
    74
1549
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    75
#include <IOKit/IOKitLib.h>
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    76
#include <IOKit/storage/IOMedia.h>
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    77
#include <IOKit/storage/IOCDMedia.h>
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    78
#include <IOKit/storage/IODVDMedia.h>
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    79
#include <sys/mount.h>
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
    80
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
    81
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
    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
    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
    84
    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
    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
    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
    87
        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
    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
    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
    90
                                                 CFSTR(kIOMediaWholeKey),
1441
c54966817dc6 mac: Removed Carbon header include and custom allocator (just use malloc).
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    91
                                                 NULL, 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
    92
    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
    93
        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
    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
    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
    96
    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
    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
    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
    99
} /* 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
   100
5e5e6c067413 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
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
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
   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
    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
   105
    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
   106
    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
   107
    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
   108
    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
   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
    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
   111
        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
   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
    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
   114
    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
   115
        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
   116
5e5e6c067413 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
    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
   118
    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
   119
    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
   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 = 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
   123
             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
   124
    
5e5e6c067413 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
    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
   126
        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
   127
5e5e6c067413 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 (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
   129
    {
5e5e6c067413 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
        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
   131
        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
   132
    } /* 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
   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
    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
   135
5e5e6c067413 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
    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
   137
    {
5e5e6c067413 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
        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
   139
        {
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
            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
   141
                 (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
   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
                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
   144
            } /* 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
   145
        } /* 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
   146
        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
   147
    } 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
   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
    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
   150
    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
   151
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
   152
    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
   153
} /* 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
   154
1291
854cdfefdf12 For iOS, build the Mac OS X platform code, not the generic Unix code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1264
diff changeset
   155
#endif /* !defined(PHYSFS_NO_CDROM_SUPPORT) */
854cdfefdf12 For iOS, build the Mac OS X platform code, not the generic Unix code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1264
diff changeset
   156
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
   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
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
   159
{
1291
854cdfefdf12 For iOS, build the Mac OS X platform code, not the generic Unix code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1264
diff changeset
   160
#if !defined(PHYSFS_NO_CDROM_SUPPORT)
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
   161
    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
   162
    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
   163
    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
   164
    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
   165
    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
   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
    if (IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS)
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1373
diff changeset
   168
        BAIL(PHYSFS_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
   169
5e5e6c067413 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
    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
   171
    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
   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
        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
   174
        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
   175
        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
   176
            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
   177
5e5e6c067413 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
        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
   179
        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
   180
            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
   181
    } /* for */
1291
854cdfefdf12 For iOS, build the Mac OS X platform code, not the generic Unix code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1264
diff changeset
   182
#endif /* !defined(PHYSFS_NO_CDROM_SUPPORT) */
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
   183
} /* __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
   184
1549
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
   185
#endif /* PHYSFS_PLATFORM_APPLE */
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
   186
1549
59ee9cc813c8 apple: Start using some Cocoa APIs, clean up a few related things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1548
diff changeset
   187
/* end of physfs_platform_apple.m ... */
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
   188