platform/macclassic.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 11 Mar 2007 10:10:28 +0000
changeset 809 116b8fe30371
parent 808 7656f86a9a2c
child 810 fafcbe604881
permissions -rw-r--r--
Renamed LICENSE to LICENSE.txt
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/*
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
 * MacOS Classic support routines for PhysicsFS.
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 *
809
116b8fe30371 Renamed LICENSE to LICENSE.txt
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
     4
 * Please see the file LICENSE.txt in the source's root directory.
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 *
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
 *  This file written by Ryan C. Gordon.
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
 */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
538
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
     9
#include <stdio.h>
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
#include <stdlib.h>
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
#include <string.h>
622
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
    12
#include <ctype.h>
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    13
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    14
/*
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    15
 * Most of the API calls in here are, according to ADC, available since
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    16
 *  MacOS 8.1. I don't think I used any MacOS 9 or CarbonLib-specific
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    17
 *  functions. There might be one or two 8.5 calls, and perhaps when the
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    18
 *  ADC docs say "Available in MacOS 8.1" they really mean "this works
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    19
 *  with System 6, but we don't want to hear about it at this point."
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    20
 *
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    21
 * IsAliasFile() showed up in MacOS 8.5. You can duplicate this code with
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    22
 *  PBGetCatInfoSync(), which is an older API, if you hope the bits in the
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    23
 *  catalog info never change (which they won't for, say, MacOS 8.1).
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    24
 *  See Apple Technote FL-30:
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    25
 *    http://developer.apple.com/technotes/fl/fl_30.html
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    26
 *
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    27
 * If you want to use weak pointers and Gestalt, and choose the correct
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    28
 *  code to use during __PHYSFS_platformInit(), I'll accept a patch, but
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    29
 *  chances are, it wasn't worth the time it took to write this, let alone
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    30
 *  implement that.
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    31
 */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    32
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
/*
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
 * Please note that I haven't tried this code with CarbonLib or under
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
 *  MacOS X at all. The code in unix.c is known to work with Darwin,
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    37
 *  and you may or may not be better off using that, especially since
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    38
 *  mutexes are no-ops in this file. Patches welcome.
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
 */
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    40
#ifdef __PHYSFS_CARBONIZED__  /* this is currently not defined anywhere. */
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
#include <Carbon.h>
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
#else
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
#include <OSUtils.h>
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
#include <Processes.h>
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
#include <Files.h>
158
ecc4a7f173c1 Username is now accurately reported, which means that the default user dir works more correctly.
Ryan C. Gordon <icculus@icculus.org>
parents: 157
diff changeset
    46
#include <TextUtils.h>
ecc4a7f173c1 Username is now accurately reported, which means that the default user dir works more correctly.
Ryan C. Gordon <icculus@icculus.org>
parents: 157
diff changeset
    47
#include <Resources.h>
ecc4a7f173c1 Username is now accurately reported, which means that the default user dir works more correctly.
Ryan C. Gordon <icculus@icculus.org>
parents: 157
diff changeset
    48
#include <MacMemory.h>
162
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
    49
#include <Events.h>
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
    50
#include <DriverGestalt.h>
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    51
#include <Aliases.h>
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
#endif
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
#define __PHYSICSFS_INTERNAL__
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
#include "physfs_internal.h"
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
const char *__PHYSFS_platformDirSeparator = ":";
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
    60
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    61
static const char *get_macos_error_string(OSErr err)
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
    62
{
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
    63
    if (err == noErr)
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
    64
        return(NULL);
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
    65
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
    66
    switch (err)
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
    67
    {
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    68
        case fnfErr: return(ERR_NO_SUCH_FILE);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    69
        case notOpenErr: return(ERR_NO_SUCH_VOLUME);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    70
        case dirFulErr: return(ERR_DIRECTORY_FULL);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    71
        case dskFulErr: return(ERR_DISK_FULL);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    72
        case nsvErr: return(ERR_NO_SUCH_VOLUME);
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
    73
        case ioErr: return(ERR_IO_ERROR);
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
    74
        case bdNamErr: return(ERR_BAD_FILENAME);
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
    75
        case fnOpnErr: return(ERR_NOT_A_HANDLE);
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
    76
        case eofErr: return(ERR_PAST_EOF);
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
    77
        case posErr: return(ERR_SEEK_OUT_OF_RANGE);
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    78
        case tmfoErr: return(ERR_TOO_MANY_HANDLES);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    79
        case wPrErr: return(ERR_VOL_LOCKED_HW);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    80
        case fLckdErr: return(ERR_FILE_LOCKED);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    81
        case vLckdErr: return(ERR_VOL_LOCKED_SW);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    82
        case fBsyErr: return(ERR_FILE_OR_DIR_BUSY);
538
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
    83
        case dupFNErr: return(ERR_FILE_EXISTS);
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    84
        case opWrErr: return(ERR_FILE_ALREADY_OPEN_W);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    85
        case rfNumErr: return(ERR_INVALID_REFNUM);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    86
        case gfpErr: return(ERR_GETTING_FILE_POS);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    87
        case volOffLinErr: return(ERR_VOLUME_OFFLINE);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    88
        case permErr: return(ERR_PERMISSION_DENIED);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    89
        case volOnLinErr: return(ERR_VOL_ALREADY_ONLINE);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    90
        case nsDrvErr: return(ERR_NO_SUCH_DRIVE);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    91
        case noMacDskErr: return(ERR_NOT_MAC_DISK);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    92
        case extFSErr: return(ERR_VOL_EXTERNAL_FS);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    93
        case fsRnErr: return(ERR_PROBLEM_RENAME);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    94
        case badMDBErr: return(ERR_BAD_MASTER_BLOCK);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    95
        case wrPermErr: return(ERR_PERMISSION_DENIED);
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
    96
        case memFullErr: return(ERR_OUT_OF_MEMORY);
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    97
        case dirNFErr: return(ERR_NO_SUCH_PATH);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    98
        case tmwdoErr: return(ERR_TOO_MANY_HANDLES);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    99
        case badMovErr: return(ERR_CANT_MOVE_FORBIDDEN);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   100
        case wrgVolTypErr: return(ERR_WRONG_VOL_TYPE);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   101
        case volGoneErr: return(ERR_SERVER_VOL_LOST);
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   102
        case errFSNameTooLong: return(ERR_BAD_FILENAME);
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   103
        case errFSNotAFolder: return(ERR_NOT_A_DIR);
538
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   104
        /*case errFSNotAFile: return(ERR_NOT_A_FILE);*/
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   105
        case fidNotFound: return(ERR_FILE_ID_NOT_FOUND);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   106
        case fidExists: return(ERR_FILE_ID_EXISTS);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   107
        case afpAccessDenied: return(ERR_ACCESS_DENIED);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   108
        case afpNoServer: return(ERR_SERVER_NO_RESPOND);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   109
        case afpUserNotAuth: return(ERR_USER_AUTH_FAILED);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   110
        case afpPwdExpiredErr: return(ERR_PWORD_EXPIRED);
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   111
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   112
        case paramErr:
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   113
        case errFSBadFSRef:
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   114
        case errFSBadBuffer:
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   115
        case errFSMissingName:
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   116
        case errFSBadPosMode:
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   117
        case errFSBadAllocFlags:
538
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   118
        case errFSBadItemCount:
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   119
        case errFSBadSearchParams:
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   120
        case afpDenyConflict:
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   121
            return(ERR_PHYSFS_BAD_OS_CALL);
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   122
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   123
        default: return(ERR_MACOS_GENERIC);
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   124
    } /* switch */
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   125
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   126
    return(NULL);
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   127
} /* get_macos_error_string */
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   128
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   129
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   130
static OSErr oserr(OSErr retval)
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   131
{
538
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   132
    char buf[sizeof (ERR_MACOS_GENERIC) + 32];
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   133
    const char *errstr = get_macos_error_string(retval);
538
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   134
    if (strcmp(errstr, ERR_MACOS_GENERIC) == 0)
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   135
    {
695
73bfbbe645a8 MacOS Classic fixes and MPW support (thanks, Chris!).
Ryan C. Gordon <icculus@icculus.org>
parents: 692
diff changeset
   136
        sprintf(buf, ERR_MACOS_GENERIC, (int) retval);
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   137
        errstr = buf;
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   138
    } /* if */
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   139
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   140
    if (errstr != NULL)
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   141
        __PHYSFS_setError(errstr);
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   142
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   143
    return(retval);
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   144
} /* oserr */
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   145
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   146
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   147
static struct ProcessInfoRec procInfo;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   148
static FSSpec procfsspec;
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
int __PHYSFS_platformInit(void)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
{
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   152
    OSErr err;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   153
    ProcessSerialNumber psn;
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   154
    BAIL_IF_MACRO(oserr(GetCurrentProcess(&psn)) != noErr, NULL, 0);
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   155
    memset(&procInfo, '\0', sizeof (ProcessInfoRec));
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   156
    memset(&procfsspec, '\0', sizeof (FSSpec));
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   157
    procInfo.processInfoLength = sizeof (ProcessInfoRec);
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   158
    procInfo.processAppSpec = &procfsspec;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   159
    err = GetProcessInformation(&psn, &procInfo);
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   160
    BAIL_IF_MACRO(oserr(err) != noErr, NULL, 0);
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   161
    return(1);  /* we're golden. */
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
} /* __PHYSFS_platformInit */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   164
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
int __PHYSFS_platformDeinit(void)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
    return(1);  /* always succeed. */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   168
} /* __PHYSFS_platformDeinit */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   171
/* 
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   172
 * CD detection code is borrowed from Apple Technical Q&A DV18.
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   173
 *  http://developer.apple.com/qa/dv/dv18.html
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   174
 */
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   175
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
{
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   177
    
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   178
    DriverGestaltParam pb;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   179
    DrvQEl *dqp;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   180
    OSErr status;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   181
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   182
    pb.csCode = kDriverGestaltCode;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   183
    pb.driverGestaltSelector = kdgDeviceType;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   184
    dqp = (DrvQEl *) GetDrvQHdr()->qHead;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   185
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   186
    while (dqp != NULL)
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   187
    {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   188
        pb.ioCRefNum = dqp->dQRefNum;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   189
        pb.ioVRefNum = dqp->dQDrive;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   190
        status = PBStatusSync((ParmBlkPtr) &pb);
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   191
        if ((status == noErr) && (pb.driverGestaltResponse == kdgCDType))
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   192
        {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   193
            Str63 volName;
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   194
            size_t size;
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   195
            HParamBlockRec hpbr;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   196
            memset(&hpbr, '\0', sizeof (HParamBlockRec));
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   197
            hpbr.volumeParam.ioNamePtr = volName;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   198
            hpbr.volumeParam.ioVRefNum = dqp->dQDrive;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   199
            hpbr.volumeParam.ioVolIndex = 0;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   200
            if (PBHGetVInfoSync(&hpbr) == noErr)
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   201
            {
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   202
                size = (size_t) volName[0];  /* convert to ASCIZ string... */
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   203
                memmove(&volName[0], &volName[1], size);
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   204
                volName[size] = '\0';
692
9c2381075c5e Builds on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 691
diff changeset
   205
                cb(data, (const char *) volName);
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   206
            } /* if */
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   207
        } /* if */
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   208
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   209
        dqp = (DrvQEl *) dqp->qLink;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   210
    } /* while */
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
} /* __PHYSFS_platformDetectAvailableCDs */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
185
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   214
static char *convFSSpecToPath(FSSpec *spec, int includeFile)
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   216
    char *ptr;
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217
    char *retval = NULL;
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   218
    UInt32 retLength = 0;
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   219
    CInfoPBRec infoPB;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   220
    Str255 str255;
185
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   221
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   222
    str255[0] = spec->name[0];
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   223
    memcpy(&str255[1], &spec->name[1], str255[0]);
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   224
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
    memset(&infoPB, '\0', sizeof (CInfoPBRec));
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   226
    infoPB.dirInfo.ioNamePtr = str255;          /* put name in here.         */
185
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   227
    infoPB.dirInfo.ioVRefNum = spec->vRefNum;   /* ID of bin's volume.       */ 
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   228
    infoPB.dirInfo.ioDrParID = spec->parID;     /* ID of bin's dir.          */
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   229
    infoPB.dirInfo.ioFDirIndex = (includeFile) ? 0 : -1;
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   230
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   231
    /* walk the tree back to the root dir (volume), building path string... */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   232
    do
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   233
    {
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   234
        /* check parent dir of what we last looked at... */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   235
        infoPB.dirInfo.ioDrDirID = infoPB.dirInfo.ioDrParID;
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   236
        if (oserr(PBGetCatInfoSync(&infoPB)) != noErr)
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   237
        {
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   238
            if (retval != NULL)
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   239
                allocator.Free(retval);
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   240
            return(NULL);
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   241
        } /* if */
185
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   242
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   243
        infoPB.dirInfo.ioFDirIndex = -1;  /* look at parent dir next time. */
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   244
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   245
        /* allocate more space for the retval... */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   246
        retLength += str255[0] + 1; /* + 1 for a ':' or null char... */
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   247
        ptr = (char *) allocator.Malloc(retLength);
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   248
        if (ptr == NULL)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   249
        {
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   250
            if (retval != NULL)
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   251
                allocator.Free(retval);
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   252
            BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   253
        } /* if */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   254
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   255
        /* prepend new dir to retval and cleanup... */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   256
        memcpy(ptr, &str255[1], str255[0]);
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   257
        ptr[str255[0]] = '\0';  /* null terminate it. */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   258
        if (retval != NULL)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   259
        {
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   260
            strcat(ptr, ":");
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   261
            strcat(ptr, retval);
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   262
            allocator.Free(retval);
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   263
        } /* if */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   264
        retval = ptr;
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   265
    } while (infoPB.dirInfo.ioDrDirID != fsRtDirID);
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   266
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   267
    return(retval);
185
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   268
} /* convFSSpecToPath */
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   269
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   270
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   271
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   272
{
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   273
    FSSpec spec;
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   274
    
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   275
    /* Get the name of the binary's parent directory. */
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   276
    FSMakeFSSpec(procfsspec.vRefNum, procfsspec.parID, procfsspec.name, &spec);
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   277
    return(convFSSpecToPath(&spec, 0));
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   278
} /* __PHYSFS_platformCalcBaseDir */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   279
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   280
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   281
char *__PHYSFS_platformGetUserName(void)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   282
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   283
    char *retval = NULL;
158
ecc4a7f173c1 Username is now accurately reported, which means that the default user dir works more correctly.
Ryan C. Gordon <icculus@icculus.org>
parents: 157
diff changeset
   284
    StringHandle strHandle;
ecc4a7f173c1 Username is now accurately reported, which means that the default user dir works more correctly.
Ryan C. Gordon <icculus@icculus.org>
parents: 157
diff changeset
   285
    short origResourceFile = CurResFile();
ecc4a7f173c1 Username is now accurately reported, which means that the default user dir works more correctly.
Ryan C. Gordon <icculus@icculus.org>
parents: 157
diff changeset
   286
ecc4a7f173c1 Username is now accurately reported, which means that the default user dir works more correctly.
Ryan C. Gordon <icculus@icculus.org>
parents: 157
diff changeset
   287
    /* use the System resource file. */
ecc4a7f173c1 Username is now accurately reported, which means that the default user dir works more correctly.
Ryan C. Gordon <icculus@icculus.org>
parents: 157
diff changeset
   288
    UseResFile(0);
ecc4a7f173c1 Username is now accurately reported, which means that the default user dir works more correctly.
Ryan C. Gordon <icculus@icculus.org>
parents: 157
diff changeset
   289
    /* apparently, -16096 specifies the username. */
538
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   290
    strHandle = GetString(-16096);
158
ecc4a7f173c1 Username is now accurately reported, which means that the default user dir works more correctly.
Ryan C. Gordon <icculus@icculus.org>
parents: 157
diff changeset
   291
    UseResFile(origResourceFile);
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   292
    BAIL_IF_MACRO(strHandle == NULL, NULL, NULL);
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   293
158
ecc4a7f173c1 Username is now accurately reported, which means that the default user dir works more correctly.
Ryan C. Gordon <icculus@icculus.org>
parents: 157
diff changeset
   294
    HLock((Handle) strHandle);
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   295
    retval = (char *) allocator.Malloc((*strHandle)[0] + 1);
158
ecc4a7f173c1 Username is now accurately reported, which means that the default user dir works more correctly.
Ryan C. Gordon <icculus@icculus.org>
parents: 157
diff changeset
   296
    if (retval == NULL)
ecc4a7f173c1 Username is now accurately reported, which means that the default user dir works more correctly.
Ryan C. Gordon <icculus@icculus.org>
parents: 157
diff changeset
   297
    {
ecc4a7f173c1 Username is now accurately reported, which means that the default user dir works more correctly.
Ryan C. Gordon <icculus@icculus.org>
parents: 157
diff changeset
   298
        HUnlock((Handle) strHandle);
ecc4a7f173c1 Username is now accurately reported, which means that the default user dir works more correctly.
Ryan C. Gordon <icculus@icculus.org>
parents: 157
diff changeset
   299
        BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
ecc4a7f173c1 Username is now accurately reported, which means that the default user dir works more correctly.
Ryan C. Gordon <icculus@icculus.org>
parents: 157
diff changeset
   300
    } /* if */
ecc4a7f173c1 Username is now accurately reported, which means that the default user dir works more correctly.
Ryan C. Gordon <icculus@icculus.org>
parents: 157
diff changeset
   301
    memcpy(retval, &(*strHandle)[1], (*strHandle)[0]);
ecc4a7f173c1 Username is now accurately reported, which means that the default user dir works more correctly.
Ryan C. Gordon <icculus@icculus.org>
parents: 157
diff changeset
   302
    retval[(*strHandle)[0]] = '\0';  /* null-terminate it. */
ecc4a7f173c1 Username is now accurately reported, which means that the default user dir works more correctly.
Ryan C. Gordon <icculus@icculus.org>
parents: 157
diff changeset
   303
    HUnlock((Handle) strHandle);
ecc4a7f173c1 Username is now accurately reported, which means that the default user dir works more correctly.
Ryan C. Gordon <icculus@icculus.org>
parents: 157
diff changeset
   304
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   305
    return(retval);
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   306
} /* __PHYSFS_platformGetUserName */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   307
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   308
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   309
char *__PHYSFS_platformGetUserDir(void)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   310
{
185
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   311
#if 0
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   312
    return(NULL);  /* bah...use default behaviour, I guess. */
185
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   313
#else
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   314
    /* (Hmm. Default behaviour is broken in the base library.  :)  )  */
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   315
    return(__PHYSFS_platformCalcBaseDir(NULL));
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   316
#endif
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   317
} /* __PHYSFS_platformGetUserDir */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   318
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   319
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   320
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   321
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   322
    return(1);  /* single threaded. */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   323
} /* __PHYSFS_platformGetThreadID */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   324
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   325
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   326
int __PHYSFS_platformStricmp(const char *x, const char *y)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   327
{
622
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   328
    int ux, uy;
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   329
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   330
    do
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   331
    {
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   332
        ux = toupper((int) *x);
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   333
        uy = toupper((int) *y);
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   334
        if (ux != uy)
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   335
            return((ux > uy) ? 1 : -1);
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   336
        x++;
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   337
        y++;
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   338
    } while ((ux) && (uy));
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   339
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   340
    return(0);
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   341
} /* __PHYSFS_platformStricmp */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   342
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   343
622
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   344
int __PHYSFS_platformStrnicmp(const char *x, const char *y, PHYSFS_uint32 len)
596
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 538
diff changeset
   345
{
622
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   346
    int ux, uy;
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   347
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   348
    if (!len)
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   349
        return(0);
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   350
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   351
    do
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   352
    {
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   353
        ux = toupper((int) *x);
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   354
        uy = toupper((int) *y);
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   355
        if (ux != uy)
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   356
            return((ux > uy) ? 1 : -1);
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   357
        x++;
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   358
        y++;
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   359
        len--;
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   360
    } while ((ux) && (uy) && (len));
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   361
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   362
    return(0);
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   363
} /* __PHYSFS_platformStrnicmp */
596
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 538
diff changeset
   364
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 538
diff changeset
   365
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   366
static OSErr fnameToFSSpecNoAlias(const char *fname, FSSpec *spec)
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   367
{
169
34829282ffe8 Fixed isDirectory and enumarateFiles (had wrong param in PBGetCatInfoSync()).
Ryan C. Gordon <icculus@icculus.org>
parents: 166
diff changeset
   368
    OSErr err;
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   369
    Str255 str255;
335
1d4720c018c3 FIXME cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 316
diff changeset
   370
    int needColon = (strchr(fname, ':') == NULL);
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   371
    int len = strlen(fname) + ((needColon) ? 1 : 0);
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   372
    if (len > 255)
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   373
        return(bdNamErr);
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   374
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   375
    /* !!! FIXME: What happens with relative pathnames? */
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   376
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   377
    str255[0] = len;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   378
    memcpy(&str255[1], fname, len);
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   379
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   380
    /* probably just a volume name, which seems to need a ':' at the end. */
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   381
    if (needColon)
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   382
        str255[len] = ':';
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   383
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   384
    err = oserr(FSMakeFSSpec(0, 0, str255, spec));
169
34829282ffe8 Fixed isDirectory and enumarateFiles (had wrong param in PBGetCatInfoSync()).
Ryan C. Gordon <icculus@icculus.org>
parents: 166
diff changeset
   385
    return(err);
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   386
} /* fnameToFSSpecNoAlias */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   387
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   388
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   389
static OSErr fnameToFSSpec(const char *fname, FSSpec *spec)
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   390
{
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   391
    Boolean alias = 0;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   392
    Boolean folder = 0;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   393
    OSErr err = fnameToFSSpecNoAlias(fname, spec);
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   394
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   395
    if (err == dirNFErr)  /* might be an alias in the middle of the path. */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   396
    {
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   397
        /* 
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   398
         * Has to be at least two ':' chars, or we wouldn't get a
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   399
         *  dir-not-found condition. (no ':' means it was just a volume,
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   400
         *  just one ':' means we would have gotten a fnfErr, if anything.
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   401
         */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   402
        char *ptr;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   403
        char *start;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   404
        char *path = alloca(strlen(fname) + 1);
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   405
        strcpy(path, fname);
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   406
        ptr = strchr(path, ':');
362
ac8c846a0a66 Changed enumeration code to use __PHYSFS_addToLinkedStringList().
Ryan C. Gordon <icculus@icculus.org>
parents: 335
diff changeset
   407
        BAIL_IF_MACRO(!ptr, ERR_NO_SUCH_FILE, err); /* just in case */
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   408
        ptr = strchr(ptr + 1, ':');
362
ac8c846a0a66 Changed enumeration code to use __PHYSFS_addToLinkedStringList().
Ryan C. Gordon <icculus@icculus.org>
parents: 335
diff changeset
   409
        BAIL_IF_MACRO(!ptr, ERR_NO_SUCH_FILE, err); /* just in case */
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   410
        *ptr = '\0';
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   411
        err = fnameToFSSpecNoAlias(path, spec); /* get first dir. */
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   412
        BAIL_IF_MACRO(oserr(err) != noErr, NULL, err);
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   413
        start = ptr;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   414
        ptr = strchr(start + 1, ':');
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   415
335
1d4720c018c3 FIXME cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 316
diff changeset
   416
        /* Now check each element of the path for aliases... */
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   417
        do
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   418
        {
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   419
            CInfoPBRec infoPB;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   420
            memset(&infoPB, '\0', sizeof (CInfoPBRec));
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   421
            infoPB.dirInfo.ioNamePtr = spec->name;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   422
            infoPB.dirInfo.ioVRefNum = spec->vRefNum;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   423
            infoPB.dirInfo.ioDrDirID = spec->parID;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   424
            infoPB.dirInfo.ioFDirIndex = 0;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   425
            err = PBGetCatInfoSync(&infoPB);
335
1d4720c018c3 FIXME cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 316
diff changeset
   426
            if (err != noErr)  /* not an alias, really just a bogus path. */
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   427
                return(fnameToFSSpecNoAlias(fname, spec)); /* reset */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   428
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   429
            if ((infoPB.dirInfo.ioFlAttrib & kioFlAttribDirMask) != 0)
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   430
                spec->parID = infoPB.dirInfo.ioDrDirID;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   431
335
1d4720c018c3 FIXME cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 316
diff changeset
   432
            if (ptr != NULL)  /* terminate string after next element. */
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   433
                *ptr = '\0';
335
1d4720c018c3 FIXME cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 316
diff changeset
   434
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   435
            *start = strlen(start + 1);  /* make it a pstring. */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   436
            err = FSMakeFSSpec(spec->vRefNum, spec->parID,
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   437
                               (const unsigned char *) start, spec);
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   438
            if (err != noErr)  /* not an alias, really a bogus path. */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   439
                return(fnameToFSSpecNoAlias(fname, spec)); /* reset */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   440
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   441
            err = ResolveAliasFileWithMountFlags(spec, 1, &folder, &alias, 0);
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   442
            if (err != noErr)  /* not an alias, really a bogus path. */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   443
                return(fnameToFSSpecNoAlias(fname, spec)); /* reset */
335
1d4720c018c3 FIXME cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 316
diff changeset
   444
1d4720c018c3 FIXME cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 316
diff changeset
   445
            start = ptr;  /* move to the next element. */
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   446
            if (ptr != NULL)
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   447
                ptr = strchr(start + 1, ':');                
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   448
        } while (start != NULL);
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   449
    } /* if */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   450
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   451
    else /* there's something there; make sure final file is not an alias. */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   452
    {
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   453
        BAIL_IF_MACRO(oserr(err) != noErr, NULL, err);
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   454
        err = ResolveAliasFileWithMountFlags(spec, 1, &folder, &alias, 0);
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   455
        BAIL_IF_MACRO(oserr(err) != noErr, NULL, err);
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   456
    } /* else */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   457
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   458
    return(noErr);  /* w00t. */
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   459
} /* fnameToFSSpec */
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   460
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   461
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   462
int __PHYSFS_platformExists(const char *fname)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   463
{
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   464
    FSSpec spec;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   465
    return(fnameToFSSpec(fname, &spec) == noErr);
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   466
} /* __PHYSFS_platformExists */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   467
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   468
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   469
int __PHYSFS_platformIsSymLink(const char *fname)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   470
{
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   471
    OSErr err;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   472
    FSSpec spec;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   473
    Boolean a = 0;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   474
    Boolean f = 0;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   475
    CInfoPBRec infoPB;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   476
    char *ptr;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   477
    char *dir = alloca(strlen(fname) + 1);
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   478
    BAIL_IF_MACRO(dir == NULL, ERR_OUT_OF_MEMORY, 0);
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   479
    strcpy(dir, fname);
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   480
    ptr = strrchr(dir, ':');
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   481
    if (ptr == NULL)  /* just a volume name? Can't be a symlink. */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   482
        return(0);
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   483
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   484
    /* resolve aliases up to the actual file... */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   485
    *ptr = '\0';
393
468f75bf4d7d Minor cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
   486
    BAIL_IF_MACRO(fnameToFSSpec(dir, &spec) != noErr, NULL, 0);
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   487
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   488
    *ptr = strlen(ptr + 1);  /* ptr is now a pascal string. Yikes! */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   489
    memset(&infoPB, '\0', sizeof (CInfoPBRec));
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   490
    infoPB.dirInfo.ioNamePtr = spec.name;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   491
    infoPB.dirInfo.ioVRefNum = spec.vRefNum;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   492
    infoPB.dirInfo.ioDrDirID = spec.parID;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   493
    infoPB.dirInfo.ioFDirIndex = 0;
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   494
    BAIL_IF_MACRO(oserr(PBGetCatInfoSync(&infoPB)) != noErr, NULL, 0);
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   495
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   496
    err = FSMakeFSSpec(spec.vRefNum, infoPB.dirInfo.ioDrDirID,
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   497
                       (const unsigned char *) ptr, &spec);
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   498
    BAIL_IF_MACRO(oserr(err) != noErr, NULL, 0);
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   499
    BAIL_IF_MACRO(oserr(IsAliasFile(&spec, &a, &f)) != noErr, NULL, 0);
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   500
    return(a);
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   501
} /* __PHYSFS_platformIsSymlink */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   502
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   503
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   504
int __PHYSFS_platformIsDirectory(const char *fname)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   505
{
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   506
    FSSpec spec;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   507
    CInfoPBRec infoPB;
169
34829282ffe8 Fixed isDirectory and enumarateFiles (had wrong param in PBGetCatInfoSync()).
Ryan C. Gordon <icculus@icculus.org>
parents: 166
diff changeset
   508
    OSErr err;
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   509
393
468f75bf4d7d Minor cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
   510
    BAIL_IF_MACRO(fnameToFSSpec(fname, &spec) != noErr, NULL, 0);
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   511
    memset(&infoPB, '\0', sizeof (CInfoPBRec));
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   512
    infoPB.dirInfo.ioNamePtr = spec.name;     /* put name in here.       */
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   513
    infoPB.dirInfo.ioVRefNum = spec.vRefNum;  /* ID of file's volume.    */ 
169
34829282ffe8 Fixed isDirectory and enumarateFiles (had wrong param in PBGetCatInfoSync()).
Ryan C. Gordon <icculus@icculus.org>
parents: 166
diff changeset
   514
    infoPB.dirInfo.ioDrDirID = spec.parID;    /* ID of bin's dir.        */
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   515
    infoPB.dirInfo.ioFDirIndex = 0;           /* file (not parent) info. */
169
34829282ffe8 Fixed isDirectory and enumarateFiles (had wrong param in PBGetCatInfoSync()).
Ryan C. Gordon <icculus@icculus.org>
parents: 166
diff changeset
   516
    err = PBGetCatInfoSync(&infoPB);
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   517
    BAIL_IF_MACRO(oserr(err) != noErr, NULL, 0);
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   518
    return((infoPB.dirInfo.ioFlAttrib & kioFlAttribDirMask) != 0);
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   519
} /* __PHYSFS_platformIsDirectory */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   520
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   521
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   522
char *__PHYSFS_platformCvtToDependent(const char *prepend,
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   523
                                      const char *dirName,
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   524
                                      const char *append)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   525
{
162
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   526
    int len = ((prepend) ? strlen(prepend) : 0) +
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   527
              ((append) ? strlen(append) : 0) +
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   528
              strlen(dirName) + 1;
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   529
    const char *src;
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   530
    char *dst;
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   531
    char *retval = (char *) allocator.Malloc(len);
162
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   532
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   533
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   534
    if (prepend != NULL)
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   535
    {
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   536
        strcpy(retval, prepend);
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   537
        dst = retval + strlen(retval);
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   538
    } /* if */
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   539
    else
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   540
    {
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   541
        *retval = '\0';
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   542
        dst = retval;
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   543
    } /* else */
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   544
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   545
    for (src = dirName; *src; src++, dst++)
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   546
        *dst = ((*src == '/') ? ':' : *src);
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   547
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   548
    *dst = '\0';
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   549
    return(retval);
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   550
} /* __PHYSFS_platformCvtToDependent */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   551
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   552
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   553
void __PHYSFS_platformTimeslice(void)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   554
{
162
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   555
    SystemTask();
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   556
} /* __PHYSFS_platformTimeslice */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   557
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   558
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   559
/* returns int so we can use BAIL*MACRO... */
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   560
static int macClassicEnumerateFiles(const char *dirname,
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   561
                                     int omitSymLinks,
754
e7cd7411eadf API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents: 747
diff changeset
   562
                                     PHYSFS_EnumFilesCallback callback,
e7cd7411eadf API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents: 747
diff changeset
   563
                                     const char *origdir,
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   564
                                     void *callbackdata)
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   565
{
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   566
    UInt16 i;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   567
    UInt16 max;
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   568
    FSSpec spec;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   569
    CInfoPBRec infoPB;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   570
    Str255 str255;
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   571
    long dirID;
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   572
393
468f75bf4d7d Minor cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
   573
    BAIL_IF_MACRO(fnameToFSSpec(dirname, &spec) != noErr, NULL, 0);
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   574
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   575
    /* get the dir ID of what we want to enumerate... */
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   576
    memset(&infoPB, '\0', sizeof (CInfoPBRec));
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   577
    infoPB.dirInfo.ioNamePtr = spec.name;     /* name of dir to enum.    */
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   578
    infoPB.dirInfo.ioVRefNum = spec.vRefNum;  /* ID of file's volume.    */ 
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   579
    infoPB.dirInfo.ioDrDirID = spec.parID;    /* ID of dir.              */
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   580
    infoPB.dirInfo.ioFDirIndex = 0;           /* file (not parent) info. */
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   581
    BAIL_IF_MACRO(oserr(PBGetCatInfoSync(&infoPB)) != noErr, NULL, NULL);
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   582
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   583
    if ((infoPB.dirInfo.ioFlAttrib & kioFlAttribDirMask) == 0)
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   584
        BAIL_MACRO(ERR_NOT_A_DIR, NULL);
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   585
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   586
    dirID = infoPB.dirInfo.ioDrDirID;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   587
    max = infoPB.dirInfo.ioDrNmFls;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   588
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   589
    for (i = 1; i <= max; i++)
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   590
    {
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   591
        size_t size;
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   592
        FSSpec aliasspec;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   593
        Boolean alias = 0;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   594
        Boolean folder = 0;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   595
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   596
        memset(&infoPB, '\0', sizeof (CInfoPBRec));
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   597
        str255[0] = 0;
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   598
        infoPB.dirInfo.ioNamePtr = str255;        /* store name in here.  */
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   599
        infoPB.dirInfo.ioVRefNum = spec.vRefNum;  /* ID of dir's volume. */ 
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   600
        infoPB.dirInfo.ioDrDirID = dirID;         /* ID of dir.           */
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   601
        infoPB.dirInfo.ioFDirIndex = i;         /* next file's info.    */
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   602
        if (PBGetCatInfoSync(&infoPB) != noErr)
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   603
            continue;  /* skip this file. Oh well. */
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   604
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   605
        if (FSMakeFSSpec(spec.vRefNum, dirID, str255, &aliasspec) != noErr)
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   606
            continue;  /* skip it. */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   607
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   608
        if (IsAliasFile(&aliasspec, &alias, &folder) != noErr)
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   609
            continue;  /* skip it. */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   610
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   611
        if ((alias) && (omitSymLinks))
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   612
            continue;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   613
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   614
        /* still here? Add it to the list. */
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   615
        size = (size_t) str255[0];  /* (convert to ASCIZ string...) */
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   616
        memmove(&str255[0], &str255[1], size);
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   617
        str255[size] = '\0';
754
e7cd7411eadf API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents: 747
diff changeset
   618
        callback(callbackdata, origdir, (const char *) str255);
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   619
    } /* for */
692
9c2381075c5e Builds on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 691
diff changeset
   620
9c2381075c5e Builds on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 691
diff changeset
   621
    return(1);
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   622
} /* macClassicEnumerateFiles */
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   623
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   624
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   625
void __PHYSFS_platformEnumerateFiles(const char *dirname,
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   626
                                     int omitSymLinks,
754
e7cd7411eadf API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents: 747
diff changeset
   627
                                     PHYSFS_EnumFilesCallback callback,
e7cd7411eadf API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents: 747
diff changeset
   628
                                     const char *origdir,
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   629
                                     void *callbackdata)
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   630
{
754
e7cd7411eadf API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents: 747
diff changeset
   631
    macClassicEnumerateFiles(dirname, omitSymLinks, callback,
e7cd7411eadf API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents: 747
diff changeset
   632
                             origdir, callbackdata);
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   633
} /* __PHYSFS_platformEnumerateFiles */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   634
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   635
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   636
char *__PHYSFS_platformCurrentDir(void)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   637
{
162
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   638
    /*
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   639
     * I don't think MacOS has a concept of "current directory", beyond
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   640
     *  what is grafted on by a given standard C library implementation,
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   641
     *  so just return the base dir.
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   642
     * We don't use this for anything crucial at the moment anyhow.
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   643
     */
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   644
    return(__PHYSFS_platformCalcBaseDir(NULL));
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   645
} /* __PHYSFS_platformCurrentDir */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   646
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   647
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   648
char *__PHYSFS_platformRealPath(const char *path)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   649
{
185
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   650
    /*
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   651
     * fnameToFSSpec() will resolve any symlinks to get to the real
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   652
     *  file's FSSpec, which, when converted, will contain the real
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   653
     *  direct path to a given file. convFSSpecToPath() mallocs a
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   654
     *  return value buffer.
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   655
     */
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   656
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   657
    FSSpec spec;
393
468f75bf4d7d Minor cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
   658
    BAIL_IF_MACRO(fnameToFSSpec(path, &spec) != noErr, NULL, NULL);
185
4959e825c3ef Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We're now feature-complete on the Mac, as far as I can tell.
Ryan C. Gordon <icculus@icculus.org>
parents: 183
diff changeset
   659
    return(convFSSpecToPath(&spec, 1));
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   660
} /* __PHYSFS_platformRealPath */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   661
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   662
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   663
int __PHYSFS_platformMkDir(const char *path)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   664
{
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   665
    SInt32 val = 0;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   666
    FSSpec spec;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   667
    OSErr err = fnameToFSSpec(path, &spec);
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   668
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   669
    BAIL_IF_MACRO(err == noErr, ERR_FILE_EXISTS, 0);
393
468f75bf4d7d Minor cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
   670
    BAIL_IF_MACRO(err != fnfErr, NULL, 0);
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   671
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   672
    err = DirCreate(spec.vRefNum, spec.parID, spec.name, &val);
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   673
    BAIL_IF_MACRO(oserr(err) != noErr, NULL, 0);
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   674
    return(1);
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   675
} /* __PHYSFS_platformMkDir */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   676
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   677
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   678
static SInt16 *macDoOpen(const char *fname, SInt8 perm, int createIfMissing)
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   679
{
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   680
    int created = 0;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   681
    SInt16 *retval = NULL;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   682
    FSSpec spec;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   683
    OSErr err = fnameToFSSpec(fname, &spec);
393
468f75bf4d7d Minor cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
   684
    BAIL_IF_MACRO((err != noErr) && (err != fnfErr), NULL, NULL);
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   685
    if (err == fnfErr)
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   686
    {
362
ac8c846a0a66 Changed enumeration code to use __PHYSFS_addToLinkedStringList().
Ryan C. Gordon <icculus@icculus.org>
parents: 335
diff changeset
   687
        BAIL_IF_MACRO(!createIfMissing, ERR_NO_SUCH_FILE, NULL);
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   688
        err = HCreate(spec.vRefNum, spec.parID, spec.name,
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   689
                      procInfo.processSignature, 'BINA');
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   690
        BAIL_IF_MACRO(oserr(err) != noErr, NULL, NULL);
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   691
        created = 1;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   692
    } /* if */
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   693
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   694
    retval = (SInt16 *) allocator.Malloc(sizeof (SInt16));
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   695
    if (retval == NULL)
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   696
    {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   697
        if (created)
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   698
            HDelete(spec.vRefNum, spec.parID, spec.name);
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   699
        BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   700
    } /* if */
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   701
538
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   702
    err = HOpenDF(spec.vRefNum, spec.parID, spec.name, perm, retval);
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   703
    if (oserr(err) != noErr)
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   704
    {
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   705
        allocator.Free(retval);
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   706
        if (created)
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   707
            HDelete(spec.vRefNum, spec.parID, spec.name);
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   708
        return(NULL);
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   709
    } /* if */
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   710
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   711
    return(retval);
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   712
} /* macDoOpen */
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   713
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   714
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   715
void *__PHYSFS_platformOpenRead(const char *filename)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   716
{
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   717
    SInt16 *retval = macDoOpen(filename, fsRdPerm, 0);
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   718
    if (retval != NULL)   /* got a file; seek to start. */
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   719
    {
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   720
        if (oserr(SetFPos(*retval, fsFromStart, 0)) != noErr)
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   721
        {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   722
            FSClose(*retval);
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   723
            return(NULL);
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   724
        } /* if */
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   725
    } /* if */
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   726
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   727
    return((void *) retval);
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   728
} /* __PHYSFS_platformOpenRead */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   729
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   730
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   731
void *__PHYSFS_platformOpenWrite(const char *filename)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   732
{
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   733
    SInt16 *retval = macDoOpen(filename, fsRdWrPerm, 1);
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   734
    if (retval != NULL)   /* got a file; truncate it. */
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   735
    {
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   736
        if ((oserr(SetEOF(*retval, 0)) != noErr) ||
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   737
            (oserr(SetFPos(*retval, fsFromStart, 0)) != noErr))
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   738
        {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   739
            FSClose(*retval);
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   740
            return(NULL);
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   741
        } /* if */
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   742
    } /* if */
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   743
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   744
    return((void *) retval);
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   745
} /* __PHYSFS_platformOpenWrite */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   746
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   747
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   748
void *__PHYSFS_platformOpenAppend(const char *filename)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   749
{
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   750
    SInt16 *retval = macDoOpen(filename, fsRdWrPerm, 1);
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   751
    if (retval != NULL)   /* got a file; seek to end. */
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   752
    {
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   753
        if (oserr(SetFPos(*retval, fsFromLEOF, 0)) != noErr)
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   754
        {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   755
            FSClose(*retval);
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   756
            return(NULL);
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   757
        } /* if */
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   758
    } /* if */
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   759
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   760
    return(retval);
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   761
} /* __PHYSFS_platformOpenAppend */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   762
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   763
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   764
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   765
                                    PHYSFS_uint32 size, PHYSFS_uint32 count)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   766
{
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   767
    SInt16 ref = *((SInt16 *) opaque);
695
73bfbbe645a8 MacOS Classic fixes and MPW support (thanks, Chris!).
Ryan C. Gordon <icculus@icculus.org>
parents: 692
diff changeset
   768
    SInt32 br = size*count;
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   769
695
73bfbbe645a8 MacOS Classic fixes and MPW support (thanks, Chris!).
Ryan C. Gordon <icculus@icculus.org>
parents: 692
diff changeset
   770
	BAIL_IF_MACRO(oserr(FSRead(ref, &br, buffer)) != noErr, NULL, br/size);
73bfbbe645a8 MacOS Classic fixes and MPW support (thanks, Chris!).
Ryan C. Gordon <icculus@icculus.org>
parents: 692
diff changeset
   771
	BAIL_IF_MACRO(br != size*count, NULL, br/size);  /* !!! FIXME: seek back if only read part of an object! */
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   772
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   773
    return(count);
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   774
} /* __PHYSFS_platformRead */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   775
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   776
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   777
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   778
                                     PHYSFS_uint32 size, PHYSFS_uint32 count)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   779
{
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   780
    SInt16 ref = *((SInt16 *) opaque);
695
73bfbbe645a8 MacOS Classic fixes and MPW support (thanks, Chris!).
Ryan C. Gordon <icculus@icculus.org>
parents: 692
diff changeset
   781
    SInt32 bw = size*count;
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   782
695
73bfbbe645a8 MacOS Classic fixes and MPW support (thanks, Chris!).
Ryan C. Gordon <icculus@icculus.org>
parents: 692
diff changeset
   783
	BAIL_IF_MACRO(oserr(FSWrite(ref, &bw, buffer)) != noErr, NULL, bw/size);
73bfbbe645a8 MacOS Classic fixes and MPW support (thanks, Chris!).
Ryan C. Gordon <icculus@icculus.org>
parents: 692
diff changeset
   784
	BAIL_IF_MACRO(bw != size*count, NULL, bw/size); /* !!! FIXME: seek back if only wrote part of an object! */
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   785
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   786
    return(count);
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   787
} /* __PHYSFS_platformWrite */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   788
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   789
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   790
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   791
{
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   792
    SInt16 ref = *((SInt16 *) opaque);
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   793
    OSErr err = SetFPos(ref, fsFromStart, (SInt32) pos);
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   794
    BAIL_IF_MACRO(oserr(err) != noErr, NULL, 0);
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   795
    return(1);
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   796
} /* __PHYSFS_platformSeek */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   797
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   798
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   799
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   800
{
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   801
    SInt16 ref = *((SInt16 *) opaque);
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   802
    SInt32 curPos;
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   803
    BAIL_IF_MACRO(oserr(GetFPos(ref, &curPos)) != noErr, NULL, -1);
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   804
    return((PHYSFS_sint64) curPos);
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   805
} /* __PHYSFS_platformTell */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   806
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   807
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   808
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   809
{
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   810
    SInt16 ref = *((SInt16 *) opaque);
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   811
    SInt32 eofPos;
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   812
    BAIL_IF_MACRO(oserr(GetEOF(ref, &eofPos)) != noErr, NULL, -1);
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   813
    return((PHYSFS_sint64) eofPos);
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   814
} /* __PHYSFS_platformFileLength */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   815
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   816
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   817
int __PHYSFS_platformEOF(void *opaque)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   818
{
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   819
    SInt16 ref = *((SInt16 *) opaque);
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   820
    SInt32 eofPos, curPos;
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   821
    BAIL_IF_MACRO(oserr(GetEOF(ref, &eofPos)) != noErr, NULL, 1);
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   822
    BAIL_IF_MACRO(oserr(GetFPos(ref, &curPos)) != noErr, NULL, 1);
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   823
    return(curPos >= eofPos);
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   824
} /* __PHYSFS_platformEOF */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   825
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   826
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   827
int __PHYSFS_platformFlush(void *opaque)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   828
{
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   829
    SInt16 ref = *((SInt16 *) opaque);
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   830
    ParamBlockRec pb;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   831
    memset(&pb, '\0', sizeof (ParamBlockRec));
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   832
    pb.ioParam.ioRefNum = ref;
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   833
    BAIL_IF_MACRO(oserr(PBFlushFileSync(&pb)) != noErr, NULL, 0);
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   834
    return(1);
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   835
} /* __PHYSFS_platformFlush */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   836
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   837
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   838
int __PHYSFS_platformClose(void *opaque)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   839
{
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   840
    SInt16 ref = *((SInt16 *) opaque);
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   841
    SInt16 vRefNum;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   842
    Str63 volName;
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   843
    int flushVol = 0;
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   844
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   845
    if (GetVRefNum(ref, &vRefNum) == noErr)
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   846
    {
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   847
        HParamBlockRec hpbr;
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   848
        memset(&hpbr, '\0', sizeof (HParamBlockRec));
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   849
        hpbr.volumeParam.ioNamePtr = volName;
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   850
        hpbr.volumeParam.ioVRefNum = vRefNum;
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   851
        hpbr.volumeParam.ioVolIndex = 0;
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   852
        if (PBHGetVInfoSync(&hpbr) == noErr)
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   853
            flushVol = 1;
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   854
    } /* if */
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   855
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   856
    BAIL_IF_MACRO(oserr(FSClose(ref)) != noErr, NULL, 0);
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   857
    allocator.Free(opaque);
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   858
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   859
    if (flushVol)
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   860
        FlushVol(volName, vRefNum);  /* update catalog info, etc. */
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   861
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   862
    return(1);
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   863
} /* __PHYSFS_platformClose */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   864
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   865
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   866
int __PHYSFS_platformDelete(const char *path)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   867
{
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   868
    FSSpec spec;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   869
    OSErr err;
393
468f75bf4d7d Minor cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
   870
    BAIL_IF_MACRO(fnameToFSSpec(path, &spec) != noErr, NULL, 0);
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   871
    err = HDelete(spec.vRefNum, spec.parID, spec.name);
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   872
    BAIL_IF_MACRO(oserr(err) != noErr, NULL, 0);
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   873
    return(1);
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   874
} /* __PHYSFS_platformDelete */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   875
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   876
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   877
void *__PHYSFS_platformCreateMutex(void)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   878
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   879
    return((void *) 0x0001);  /* no mutexes on MacOS Classic. */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   880
} /* __PHYSFS_platformCreateMutex */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   881
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   882
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   883
void __PHYSFS_platformDestroyMutex(void *mutex)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   884
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   885
    /* no mutexes on MacOS Classic. */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   886
} /* __PHYSFS_platformDestroyMutex */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   887
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   888
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   889
int __PHYSFS_platformGrabMutex(void *mutex)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   890
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   891
    return(1);  /* no mutexes on MacOS Classic. */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   892
} /* __PHYSFS_platformGrabMutex */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   893
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   894
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   895
void __PHYSFS_platformReleaseMutex(void *mutex)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   896
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   897
    /* no mutexes on MacOS Classic. */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   898
} /* __PHYSFS_platformReleaseMutex */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   899
240
052041af9001 Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
   900
052041af9001 Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
   901
PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname)
052041af9001 Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
   902
{
247
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   903
    FSSpec spec;
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   904
    CInfoPBRec infoPB;
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   905
    UInt32 modDate;
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   906
393
468f75bf4d7d Minor cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
   907
    if (fnameToFSSpec(fname, &spec) != noErr)
468f75bf4d7d Minor cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
   908
        return(-1); /* fnameToFSSpec() sets physfs error message. */
247
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   909
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   910
    memset(&infoPB, '\0', sizeof (CInfoPBRec));
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   911
    infoPB.dirInfo.ioNamePtr = spec.name;
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   912
    infoPB.dirInfo.ioVRefNum = spec.vRefNum;
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   913
    infoPB.dirInfo.ioDrDirID = spec.parID;
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   914
    infoPB.dirInfo.ioFDirIndex = 0;
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   915
    BAIL_IF_MACRO(oserr(PBGetCatInfoSync(&infoPB)) != noErr, NULL, -1);
247
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   916
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   917
    modDate = ((infoPB.dirInfo.ioFlAttrib & kioFlAttribDirMask) != 0) ?
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   918
                   infoPB.dirInfo.ioDrMdDat : infoPB.hFileInfo.ioFlMdDat;
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   919
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   920
    /* epoch is different on MacOS. They use Jan 1, 1904, apparently. */
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   921
    /*  subtract seconds between those epochs, counting leap years.   */
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   922
    modDate -= 2082844800;
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   923
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   924
    return((PHYSFS_sint64) modDate);
240
052041af9001 Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
   925
} /* __PHYSFS_platformGetLastModTime */
052041af9001 Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
   926
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   927
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   928
/* !!! FIXME: Don't use C runtime for allocators? */
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   929
int __PHYSFS_platformAllocatorInit(void)
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   930
{
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   931
    return(1);  /* always succeeds. */
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   932
} /* __PHYSFS_platformAllocatorInit */
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   933
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   934
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   935
void __PHYSFS_platformAllocatorDeinit(void)
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   936
{
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   937
    /* no-op */
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   938
} /* __PHYSFS_platformAllocatorInit */
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   939
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   940
747
3da194b12f43 Don't use size_t in physfs.h, since it relies on C runtime headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 701
diff changeset
   941
void *__PHYSFS_platformAllocatorMalloc(PHYSFS_uint64 s)
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   942
{
763
efadd9cdb6a4 Cleaned up overflow checks in platform memory allocators (thanks to Nicolas
Ryan C. Gordon <icculus@icculus.org>
parents: 754
diff changeset
   943
    BAIL_IF_MACRO(__PHYSFS_ui64FitsAddressSpace(s), ERR_OUT_OF_MEMORY, NULL);
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   944
    #undef malloc
747
3da194b12f43 Don't use size_t in physfs.h, since it relies on C runtime headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 701
diff changeset
   945
    return(malloc((size_t) s));
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   946
} /* __PHYSFS_platformMalloc */
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   947
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   948
747
3da194b12f43 Don't use size_t in physfs.h, since it relies on C runtime headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 701
diff changeset
   949
void *__PHYSFS_platformAllocatorRealloc(void *ptr, PHYSFS_uint64 s)
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   950
{
763
efadd9cdb6a4 Cleaned up overflow checks in platform memory allocators (thanks to Nicolas
Ryan C. Gordon <icculus@icculus.org>
parents: 754
diff changeset
   951
    BAIL_IF_MACRO(__PHYSFS_ui64FitsAddressSpace(s), ERR_OUT_OF_MEMORY, NULL);
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   952
    #undef realloc
747
3da194b12f43 Don't use size_t in physfs.h, since it relies on C runtime headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 701
diff changeset
   953
    return(realloc(ptr, (size_t) s));
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   954
} /* __PHYSFS_platformRealloc */
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   955
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   956
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   957
void __PHYSFS_platformAllocatorFree(void *ptr)
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   958
{
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   959
    #undef free
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   960
    free(ptr);
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   961
} /* __PHYSFS_platformAllocatorFree */
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   962
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   963
/* end of macclassic.c ... */
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   964