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