platform/macclassic.c
author Ryan C. Gordon <icculus@icculus.org>
Wed, 16 Mar 2005 12:06:18 +0000
changeset 700 32e9d36b7cb1
parent 695 73bfbbe645a8
child 701 49a5ec86b8b3
permissions -rw-r--r--
Whoops, this goes here.
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
 *
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
 * Please see the file LICENSE in the source's root directory.
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
214
19846c18071b Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 185
diff changeset
     9
#if HAVE_CONFIG_H
19846c18071b Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 185
diff changeset
    10
#  include <config.h>
19846c18071b Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 185
diff changeset
    11
#endif
19846c18071b Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 185
diff changeset
    12
538
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
    13
#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
    14
#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
    15
#include <string.h>
622
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
    16
#include <ctype.h>
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    17
700
32e9d36b7cb1 Whoops, this goes here.
Ryan C. Gordon <icculus@icculus.org>
parents: 695
diff changeset
    18
#ifdef __MWERKS__
32e9d36b7cb1 Whoops, this goes here.
Ryan C. Gordon <icculus@icculus.org>
parents: 695
diff changeset
    19
#include <alloca.h>
32e9d36b7cb1 Whoops, this goes here.
Ryan C. Gordon <icculus@icculus.org>
parents: 695
diff changeset
    20
#endif
32e9d36b7cb1 Whoops, this goes here.
Ryan C. Gordon <icculus@icculus.org>
parents: 695
diff changeset
    21
 
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    22
/*
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    23
 * 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
    24
 *  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
    25
 *  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
    26
 *  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
    27
 *  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
    28
 *
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    29
 * 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
    30
 *  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
    31
 *  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
    32
 *  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
    33
 *    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
    34
 *
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    35
 * 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
    36
 *  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
    37
 *  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
    38
 *  implement that.
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    39
 */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    40
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
/*
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
 * 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
    44
 *  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
    45
 *  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
    46
 *  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
    47
 */
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    48
#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
    49
#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
    50
#else
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
#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
    52
#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
    53
#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
    54
#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
    55
#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
    56
#include <MacMemory.h>
162
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
    57
#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
    58
#include <DriverGestalt.h>
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    59
#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
    60
#endif
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
#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
    63
#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
    64
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
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
    67
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
    68
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    69
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
    70
{
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
    71
    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
    72
        return(NULL);
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
    73
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
    74
    switch (err)
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
    75
    {
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    76
        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
    77
        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
    78
        case dirFulErr: return(ERR_DIRECTORY_FULL);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    79
        case dskFulErr: return(ERR_DISK_FULL);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    80
        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
    81
        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
    82
        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
    83
        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
    84
        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
    85
        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
    86
        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
    87
        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
    88
        case fLckdErr: return(ERR_FILE_LOCKED);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    89
        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
    90
        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
    91
        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
    92
        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
    93
        case rfNumErr: return(ERR_INVALID_REFNUM);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    94
        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
    95
        case volOffLinErr: return(ERR_VOLUME_OFFLINE);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    96
        case permErr: return(ERR_PERMISSION_DENIED);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
    97
        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
    98
        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
    99
        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
   100
        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
   101
        case fsRnErr: return(ERR_PROBLEM_RENAME);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   102
        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
   103
        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
   104
        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
   105
        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
   106
        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
   107
        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
   108
        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
   109
        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
   110
        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
   111
        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
   112
        /*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
   113
        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
   114
        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
   115
        case afpAccessDenied: return(ERR_ACCESS_DENIED);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   116
        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
   117
        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
   118
        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
   119
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   120
        case paramErr:
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   121
        case errFSBadFSRef:
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   122
        case errFSBadBuffer:
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   123
        case errFSMissingName:
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   124
        case errFSBadPosMode:
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   125
        case errFSBadAllocFlags:
538
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   126
        case errFSBadItemCount:
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   127
        case errFSBadSearchParams:
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   128
        case afpDenyConflict:
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   129
            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
   130
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   131
        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
   132
    } /* switch */
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   133
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   134
    return(NULL);
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   135
} /* 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
   136
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   137
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   138
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
   139
{
538
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   140
    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
   141
    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
   142
    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
   143
    {
695
73bfbbe645a8 MacOS Classic fixes and MPW support (thanks, Chris!).
Ryan C. Gordon <icculus@icculus.org>
parents: 692
diff changeset
   144
        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
   145
        errstr = buf;
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   146
    } /* if */
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   147
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   148
    if (errstr != NULL)
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   149
        __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
   150
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 424
diff changeset
   151
    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
   152
} /* oserr */
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   153
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   154
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
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
   156
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
   157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
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
   159
{
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
   160
    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
   161
    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
   162
    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
   163
    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
   164
    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
   165
    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
   166
    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
   167
    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
   168
    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
   169
    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
   170
} /* __PHYSFS_platformInit */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
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
   174
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
    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
   176
} /* __PHYSFS_platformDeinit */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
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
   179
/* 
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
 * 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
   181
 *  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
   182
 */
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   183
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
   184
{
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   185
    
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
   186
    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
   187
    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
   188
    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
   189
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
    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
   191
    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
   192
    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
   193
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
   194
    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
   195
    {
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
        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
   197
        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
   198
        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
   199
        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
   200
        {
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
            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
   202
            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
   203
            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
   204
            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
   205
            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
   206
            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
   207
            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
   208
            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
   209
            {
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   210
                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
   211
                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
   212
                volName[size] = '\0';
692
9c2381075c5e Builds on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 691
diff changeset
   213
                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
   214
            } /* 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
   215
        } /* 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
   216
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
   217
        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
   218
    } /* while */
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   219
} /* __PHYSFS_platformDetectAvailableCDs */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   220
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   221
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
   222
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
   223
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   224
    char *ptr;
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
    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
   226
    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
   227
    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
   228
    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
   229
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
   230
    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
   231
    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
   232
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   233
    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
   234
    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
   235
    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
   236
    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
   237
    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
   238
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   239
    /* 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
   240
    do
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   241
    {
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   242
        /* 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
   243
        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
   244
        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
   245
        {
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   246
            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
   247
                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
   248
            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
   249
        } /* 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
   250
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
   251
        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
   252
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   253
        /* 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
   254
        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
   255
        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
   256
        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
   257
        {
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)
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   259
                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
   260
            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
   261
        } /* if */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   262
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   263
        /* 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
   264
        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
   265
        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
   266
        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
   267
        {
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   268
            strcat(ptr, ":");
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   269
            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
   270
            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
   271
        } /* if */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   272
        retval = ptr;
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   273
    } 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
   274
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   275
    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
   276
} /* 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
   277
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
   278
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
   279
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
   280
{
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
   281
    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
   282
    
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
   283
    /* 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
   284
    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
   285
    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
   286
} /* __PHYSFS_platformCalcBaseDir */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   287
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   288
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   289
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
   290
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   291
    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
   292
    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
   293
    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
   294
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
   295
    /* 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
   296
    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
   297
    /* 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
   298
    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
   299
    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
   300
    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
   301
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
   302
    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
   303
    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
   304
    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
   305
    {
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
   306
        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
   307
        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
   308
    } /* 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
   309
    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
   310
    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
   311
    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
   312
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   313
    return(retval);
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   314
} /* __PHYSFS_platformGetUserName */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   315
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   316
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   317
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
   318
{
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
   319
#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
   320
    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
   321
#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
   322
    /* (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
   323
    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
   324
#endif
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   325
} /* __PHYSFS_platformGetUserDir */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   326
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   327
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   328
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
   329
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   330
    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
   331
} /* __PHYSFS_platformGetThreadID */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   332
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   333
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   334
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
   335
{
622
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   336
    int ux, uy;
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   337
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   338
    do
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
        ux = toupper((int) *x);
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   341
        uy = toupper((int) *y);
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   342
        if (ux != uy)
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   343
            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
   344
        x++;
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   345
        y++;
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   346
    } while ((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
    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
   349
} /* __PHYSFS_platformStricmp */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   350
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   351
622
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   352
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
   353
{
622
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   354
    int ux, uy;
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   355
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   356
    if (!len)
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   357
        return(0);
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   358
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   359
    do
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   360
    {
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   361
        ux = toupper((int) *x);
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   362
        uy = toupper((int) *y);
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   363
        if (ux != uy)
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   364
            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
   365
        x++;
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   366
        y++;
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   367
        len--;
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   368
    } while ((ux) && (uy) && (len));
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   369
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   370
    return(0);
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   371
} /* __PHYSFS_platformStrnicmp */
596
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 538
diff changeset
   372
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 538
diff changeset
   373
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   374
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
   375
{
169
34829282ffe8 Fixed isDirectory and enumarateFiles (had wrong param in PBGetCatInfoSync()).
Ryan C. Gordon <icculus@icculus.org>
parents: 166
diff changeset
   376
    OSErr err;
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   377
    Str255 str255;
335
1d4720c018c3 FIXME cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 316
diff changeset
   378
    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
   379
    int len = strlen(fname) + ((needColon) ? 1 : 0);
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   380
    if (len > 255)
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   381
        return(bdNamErr);
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   382
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   383
    /* !!! FIXME: What happens with relative pathnames? */
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   384
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
   385
    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
   386
    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
   387
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
   388
    /* 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
   389
    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
   390
        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
   391
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   392
    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
   393
    return(err);
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   394
} /* fnameToFSSpecNoAlias */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   395
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
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
   398
{
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   399
    Boolean alias = 0;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   400
    Boolean folder = 0;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   401
    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
   402
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   403
    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
   404
    {
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   405
        /* 
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   406
         * 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
   407
         *  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
   408
         *  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
   409
         */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   410
        char *ptr;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   411
        char *start;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   412
        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
   413
        strcpy(path, fname);
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   414
        ptr = strchr(path, ':');
362
ac8c846a0a66 Changed enumeration code to use __PHYSFS_addToLinkedStringList().
Ryan C. Gordon <icculus@icculus.org>
parents: 335
diff changeset
   415
        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
   416
        ptr = strchr(ptr + 1, ':');
362
ac8c846a0a66 Changed enumeration code to use __PHYSFS_addToLinkedStringList().
Ryan C. Gordon <icculus@icculus.org>
parents: 335
diff changeset
   417
        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
   418
        *ptr = '\0';
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   419
        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
   420
        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
   421
        start = ptr;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   422
        ptr = strchr(start + 1, ':');
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   423
335
1d4720c018c3 FIXME cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 316
diff changeset
   424
        /* 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
   425
        do
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   426
        {
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   427
            CInfoPBRec infoPB;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   428
            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
   429
            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
   430
            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
   431
            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
   432
            infoPB.dirInfo.ioFDirIndex = 0;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   433
            err = PBGetCatInfoSync(&infoPB);
335
1d4720c018c3 FIXME cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 316
diff changeset
   434
            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
   435
                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
   436
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   437
            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
   438
                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
   439
335
1d4720c018c3 FIXME cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 316
diff changeset
   440
            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
   441
                *ptr = '\0';
335
1d4720c018c3 FIXME cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 316
diff changeset
   442
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   443
            *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
   444
            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
   445
                               (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
   446
            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
   447
                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
   448
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   449
            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
   450
            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
   451
                return(fnameToFSSpecNoAlias(fname, spec)); /* reset */
335
1d4720c018c3 FIXME cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 316
diff changeset
   452
1d4720c018c3 FIXME cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 316
diff changeset
   453
            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
   454
            if (ptr != NULL)
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   455
                ptr = strchr(start + 1, ':');                
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   456
        } while (start != NULL);
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   457
    } /* if */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   458
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   459
    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
   460
    {
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   461
        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
   462
        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
   463
        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
   464
    } /* else */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   465
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   466
    return(noErr);  /* w00t. */
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   467
} /* fnameToFSSpec */
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   468
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   469
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   470
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
   471
{
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   472
    FSSpec spec;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   473
    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
   474
} /* __PHYSFS_platformExists */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   475
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   476
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   477
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
   478
{
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   479
    OSErr err;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   480
    FSSpec spec;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   481
    Boolean a = 0;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   482
    Boolean f = 0;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   483
    CInfoPBRec infoPB;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   484
    char *ptr;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   485
    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
   486
    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
   487
    strcpy(dir, fname);
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   488
    ptr = strrchr(dir, ':');
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   489
    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
   490
        return(0);
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   491
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   492
    /* 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
   493
    *ptr = '\0';
393
468f75bf4d7d Minor cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
   494
    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
   495
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   496
    *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
   497
    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
   498
    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
   499
    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
   500
    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
   501
    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
   502
    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
   503
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   504
    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
   505
                       (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
   506
    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
   507
    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
   508
    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
   509
} /* __PHYSFS_platformIsSymlink */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   510
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   511
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   512
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
   513
{
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   514
    FSSpec spec;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   515
    CInfoPBRec infoPB;
169
34829282ffe8 Fixed isDirectory and enumarateFiles (had wrong param in PBGetCatInfoSync()).
Ryan C. Gordon <icculus@icculus.org>
parents: 166
diff changeset
   516
    OSErr err;
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   517
393
468f75bf4d7d Minor cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
   518
    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
   519
    memset(&infoPB, '\0', sizeof (CInfoPBRec));
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   520
    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
   521
    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
   522
    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
   523
    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
   524
    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
   525
    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
   526
    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
   527
} /* __PHYSFS_platformIsDirectory */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   528
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   529
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   530
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
   531
                                      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
   532
                                      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
   533
{
162
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   534
    int len = ((prepend) ? strlen(prepend) : 0) +
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   535
              ((append) ? strlen(append) : 0) +
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   536
              strlen(dirName) + 1;
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   537
    const char *src;
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   538
    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
   539
    char *retval = (char *) allocator.Malloc(len);
162
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   540
    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
   541
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   542
    if (prepend != NULL)
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   543
    {
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   544
        strcpy(retval, prepend);
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   545
        dst = retval + strlen(retval);
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   546
    } /* if */
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   547
    else
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   548
    {
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   549
        *retval = '\0';
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   550
        dst = retval;
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   551
    } /* else */
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   552
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   553
    for (src = dirName; *src; src++, dst++)
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   554
        *dst = ((*src == '/') ? ':' : *src);
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   555
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   556
    *dst = '\0';
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   557
    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
   558
} /* __PHYSFS_platformCvtToDependent */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   559
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   560
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   561
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
   562
{
162
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   563
    SystemTask();
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   564
} /* __PHYSFS_platformTimeslice */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   565
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   566
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   567
/* 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
   568
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
   569
                                     int omitSymLinks,
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   570
                                     PHYSFS_StringCallback callback,
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   571
                                     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
   572
{
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
   573
    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
   574
    UInt16 max;
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   575
    FSSpec spec;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   576
    CInfoPBRec infoPB;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   577
    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
   578
    long dirID;
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   579
393
468f75bf4d7d Minor cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
   580
    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
   581
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
    /* 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
   583
    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
   584
    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
   585
    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
   586
    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
   587
    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
   588
    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
   589
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
   590
    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
   591
        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
   592
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
   593
    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
   594
    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
   595
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
   596
    for (i = 1; i <= max; i++)
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   597
    {
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   598
        size_t size;
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   599
        FSSpec aliasspec;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   600
        Boolean alias = 0;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   601
        Boolean folder = 0;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   602
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   603
        memset(&infoPB, '\0', sizeof (CInfoPBRec));
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   604
        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
   605
        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
   606
        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
   607
        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
   608
        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
   609
        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
   610
            continue;  /* skip this file. Oh well. */
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   611
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   612
        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
   613
            continue;  /* skip it. */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   614
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   615
        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
   616
            continue;  /* skip it. */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   617
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   618
        if ((alias) && (omitSymLinks))
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   619
            continue;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   620
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   621
        /* 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
   622
        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
   623
        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
   624
        str255[size] = '\0';
692
9c2381075c5e Builds on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 691
diff changeset
   625
        callback(callbackdata, (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
   626
    } /* for */
692
9c2381075c5e Builds on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 691
diff changeset
   627
9c2381075c5e Builds on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 691
diff changeset
   628
    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
   629
} /* macClassicEnumerateFiles */
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   630
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   631
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   632
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
   633
                                     int omitSymLinks,
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   634
                                     PHYSFS_StringCallback callback,
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   635
                                     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
   636
{
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   637
    macClassicEnumerateFiles(dirname, omitSymLinks, callback, callbackdata);
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   638
} /* __PHYSFS_platformEnumerateFiles */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   639
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   640
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   641
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
   642
{
162
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
     * 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
   645
     *  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
   646
     *  so just return the base dir.
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   647
     * 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
   648
     */
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   649
    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
   650
} /* __PHYSFS_platformCurrentDir */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   651
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   652
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   653
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
   654
{
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
   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
     * 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
   657
     *  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
   658
     *  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
   659
     *  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
   660
     */
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
   661
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
   662
    FSSpec spec;
393
468f75bf4d7d Minor cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
   663
    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
   664
    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
   665
} /* __PHYSFS_platformRealPath */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   666
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   667
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   668
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
   669
{
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
   670
    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
   671
    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
   672
    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
   673
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
    BAIL_IF_MACRO(err == noErr, ERR_FILE_EXISTS, 0);
393
468f75bf4d7d Minor cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
   675
    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
   676
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
   677
    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
   678
    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
   679
    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
   680
} /* __PHYSFS_platformMkDir */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   681
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   682
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
   683
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
   684
{
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
    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
   686
    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
   687
    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
   688
    OSErr err = fnameToFSSpec(fname, &spec);
393
468f75bf4d7d Minor cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
   689
    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
   690
    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
   691
    {
362
ac8c846a0a66 Changed enumeration code to use __PHYSFS_addToLinkedStringList().
Ryan C. Gordon <icculus@icculus.org>
parents: 335
diff changeset
   692
        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
   693
        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
   694
                      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
   695
        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
   696
        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
   697
    } /* 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
   698
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   699
    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
   700
    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
   701
    {
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
   702
        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
   703
            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
   704
        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
   705
    } /* 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
   706
538
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   707
    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
   708
    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
   709
    {
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   710
        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
   711
        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
   712
            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
   713
        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
   714
    } /* 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
   715
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
   716
    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
   717
} /* 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
   718
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
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   720
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
   721
{
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
   722
    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
   723
    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
   724
    {
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   725
        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
   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
            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
   728
            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
   729
        } /* 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
   730
    } /* 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
   731
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
   732
    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
   733
} /* __PHYSFS_platformOpenRead */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   734
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   735
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   736
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
   737
{
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
    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
   739
    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
   740
    {
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   741
        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
   742
            (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
   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
            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
   745
            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
   746
        } /* 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
   747
    } /* 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
   748
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
   749
    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
   750
} /* __PHYSFS_platformOpenWrite */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   751
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   752
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   753
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
   754
{
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
   755
    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
   756
    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
   757
    {
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   758
        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
   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
            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
   761
            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
   762
        } /* 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
   763
    } /* 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
   764
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
   765
    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
   766
} /* __PHYSFS_platformOpenAppend */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   767
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   768
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   769
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
   770
                                    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
   771
{
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
    SInt16 ref = *((SInt16 *) opaque);
695
73bfbbe645a8 MacOS Classic fixes and MPW support (thanks, Chris!).
Ryan C. Gordon <icculus@icculus.org>
parents: 692
diff changeset
   773
    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
   774
695
73bfbbe645a8 MacOS Classic fixes and MPW support (thanks, Chris!).
Ryan C. Gordon <icculus@icculus.org>
parents: 692
diff changeset
   775
	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
   776
	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
   777
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
   778
    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
   779
} /* __PHYSFS_platformRead */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   780
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   781
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   782
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
   783
                                     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
   784
{
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
    SInt16 ref = *((SInt16 *) opaque);
695
73bfbbe645a8 MacOS Classic fixes and MPW support (thanks, Chris!).
Ryan C. Gordon <icculus@icculus.org>
parents: 692
diff changeset
   786
    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
   787
695
73bfbbe645a8 MacOS Classic fixes and MPW support (thanks, Chris!).
Ryan C. Gordon <icculus@icculus.org>
parents: 692
diff changeset
   788
	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
   789
	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
   790
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
   791
    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
   792
} /* __PHYSFS_platformWrite */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   793
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   794
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   795
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
   796
{
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
   797
    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
   798
    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
   799
    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
   800
    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
   801
} /* __PHYSFS_platformSeek */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   802
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   803
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   804
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
   805
{
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
   806
    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
   807
    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
   808
    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
   809
    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
   810
} /* __PHYSFS_platformTell */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   811
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   812
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   813
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
   814
{
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
   815
    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
   816
    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
   817
    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
   818
    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
   819
} /* __PHYSFS_platformFileLength */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   820
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   821
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   822
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
   823
{
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
   824
    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
   825
    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
   826
    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
   827
    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
   828
    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
   829
} /* __PHYSFS_platformEOF */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   830
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   831
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   832
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
   833
{
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
    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
   835
    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
   836
    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
   837
    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
   838
    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
   839
    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
   840
} /* __PHYSFS_platformFlush */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   841
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   842
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   843
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
   844
{
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
   845
    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
   846
    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
   847
    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
   848
    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
   849
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   850
    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
   851
    {
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   852
        HParamBlockRec hpbr;
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   853
        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
   854
        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
   855
        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
   856
        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
   857
        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
   858
            flushVol = 1;
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   859
    } /* 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
   860
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   861
    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
   862
    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
   863
424
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   864
    if (flushVol)
a691527e9f6e Now returns human-readable error messages when possible. Minor fix in
Ryan C. Gordon <icculus@icculus.org>
parents: 393
diff changeset
   865
        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
   866
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
   867
    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
   868
} /* __PHYSFS_platformClose */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   869
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   870
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   871
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
   872
{
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
    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
   874
    OSErr err;
393
468f75bf4d7d Minor cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
   875
    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
   876
    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
   877
    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
   878
    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
   879
} /* __PHYSFS_platformDelete */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   880
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
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
   883
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   884
    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
   885
} /* __PHYSFS_platformCreateMutex */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   886
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
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
   889
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   890
    /* 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
   891
} /* __PHYSFS_platformDestroyMutex */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   892
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
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
   895
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   896
    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
   897
} /* __PHYSFS_platformGrabMutex */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   898
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   899
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   900
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
   901
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   902
    /* 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
   903
} /* __PHYSFS_platformReleaseMutex */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   904
240
052041af9001 Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
   905
052041af9001 Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
   906
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
   907
{
247
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   908
    FSSpec spec;
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   909
    CInfoPBRec infoPB;
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   910
    UInt32 modDate;
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   911
393
468f75bf4d7d Minor cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
   912
    if (fnameToFSSpec(fname, &spec) != noErr)
468f75bf4d7d Minor cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
   913
        return(-1); /* fnameToFSSpec() sets physfs error message. */
247
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   914
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   915
    memset(&infoPB, '\0', sizeof (CInfoPBRec));
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   916
    infoPB.dirInfo.ioNamePtr = spec.name;
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   917
    infoPB.dirInfo.ioVRefNum = spec.vRefNum;
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   918
    infoPB.dirInfo.ioDrDirID = spec.parID;
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   919
    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
   920
    BAIL_IF_MACRO(oserr(PBGetCatInfoSync(&infoPB)) != noErr, NULL, -1);
247
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   921
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   922
    modDate = ((infoPB.dirInfo.ioFlAttrib & kioFlAttribDirMask) != 0) ?
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   923
                   infoPB.dirInfo.ioDrMdDat : infoPB.hFileInfo.ioFlMdDat;
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   924
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   925
    /* 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
   926
    /*  subtract seconds between those epochs, counting leap years.   */
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   927
    modDate -= 2082844800;
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   928
fd2af57f1e93 Implemented __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   929
    return((PHYSFS_sint64) modDate);
240
052041af9001 Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
   930
} /* __PHYSFS_platformGetLastModTime */
052041af9001 Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
   931
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   932
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   933
/* !!! 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
   934
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
   935
{
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   936
    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
   937
} /* __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
   938
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
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
   941
{
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   942
    /* 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
   943
} /* __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
   944
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   945
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   946
void *__PHYSFS_platformAllocatorMalloc(size_t s)
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
    #undef malloc
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   949
    return(malloc(s));
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   950
} /* __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
   951
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   952
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   953
void *__PHYSFS_platformAllocatorRealloc(void *ptr, size_t s)
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   954
{
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   955
    #undef realloc
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   956
    return(realloc(ptr, s));
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   957
} /* __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
   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
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   960
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
   961
{
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   962
    #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
   963
    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
   964
} /* __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
   965
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
   966
/* 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
   967