platform/macclassic.c
author Ryan C. Gordon <icculus@icculus.org>
Sat, 06 Apr 2002 02:00:00 +0000
changeset 183 352d940a99d0
parent 173 72a59de5e6e5
child 185 4959e825c3ef
permissions -rw-r--r--
Now handles Finder aliases as if they were symlinks.
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
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
#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
    10
#include <string.h>
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    11
#include <alloca.h>
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    12
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    13
/*
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    14
 * 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
    15
 *  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
    16
 *  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
    17
 *  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
    18
 *  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
    19
 *
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    20
 * 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
    21
 *  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
    22
 *  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
    23
 *  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
    24
 *    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
    25
 *
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    26
 * 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
    27
 *  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
    28
 *  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
    29
 *  implement that.
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
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
/*
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
 * 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
    35
 *  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
    36
 *  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
    37
 *  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
    38
 */
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    39
#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
    40
#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
    41
#else
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
#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
    43
#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
    44
#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
    45
#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
    46
#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
    47
#include <MacMemory.h>
162
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
    48
#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
    49
#include <DriverGestalt.h>
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
    50
#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
    51
#endif
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
#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
    54
#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
    55
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
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
    58
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
    59
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
    60
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
    61
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
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
    63
{
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
    64
    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
    65
    ProcessSerialNumber psn;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
    66
    BAIL_IF_MACRO(GetCurrentProcess(&psn) != noErr, ERR_OS_ERROR, 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
    67
    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
    68
    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
    69
    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
    70
    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
    71
    err = GetProcessInformation(&psn, &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
    72
    BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, 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
    73
    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
    74
} /* __PHYSFS_platformInit */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
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
    78
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
    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
    80
} /* __PHYSFS_platformDeinit */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
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
    83
/* 
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
    84
 * 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
    85
 *  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
    86
 */
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
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
    88
{
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
    89
    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
    90
    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
    91
    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
    92
    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
    93
    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
    94
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
    95
    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
    96
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
    97
    *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
    98
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
    99
    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
   100
    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
   101
    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
   102
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   103
    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
   104
    {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   105
        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
   106
        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
   107
        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
   108
        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
   109
        {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   110
            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
   111
            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
   112
            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
   113
            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
   114
            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
   115
            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
   116
            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
   117
            {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   118
                char **tmp = realloc(retval, sizeof (char *) * 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
   119
                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
   120
                {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   121
                    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
   122
                    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
   123
                    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
   124
                    {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   125
                        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
   126
                        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
   127
                        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
   128
                        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
   129
                    } /* 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
   130
                } /* 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
   131
            } /* 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
   132
        } /* 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
   133
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   134
        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
   135
    } /* 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
   136
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   137
    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
   138
    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
   139
} /* __PHYSFS_platformDetectAvailableCDs */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
    char *ptr;
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
    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
   146
    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
   147
    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
   148
    Str255 str255;
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
    FSSpec spec;
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
    
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
    /* Get the name of the binary's parent directory. */
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   152
    memcpy(&spec, &procfsspec, sizeof (FSSpec));
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
    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
   154
    infoPB.dirInfo.ioNamePtr = str255;          /* put 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
   155
    infoPB.dirInfo.ioVRefNum = spec.vRefNum;    /* ID of bin'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
   156
    infoPB.dirInfo.ioDrParID = spec.parID;      /* ID of bin's 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
   157
    infoPB.dirInfo.ioFDirIndex = -1;            /* get dir (not file) info.  */
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
    /* 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
   160
    do
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
    {
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
        /* 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
   163
        infoPB.dirInfo.ioDrDirID = infoPB.dirInfo.ioDrParID;
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   164
        if (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
   165
        {
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
            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
   167
                free(retval);
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   168
            BAIL_MACRO(ERR_OS_ERROR, NULL);
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
        } /* if */
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
        /* 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
   172
        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
   173
        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
   174
        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
   175
        {
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
            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
   177
                free(retval);
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
            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
   179
        } /* if */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
        /* 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
   182
        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
   183
        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
   184
        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
   185
        {
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
            strcat(ptr, ":");
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
            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
   188
            free(retval);
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
        } /* if */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
        retval = ptr;
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   191
    } 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
   192
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
    return(retval);
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
} /* __PHYSFS_platformCalcBaseDir */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
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
   198
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
    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
   200
    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
   201
    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
   202
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
   203
    /* 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
   204
    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
   205
    /* apparently, -16096 specifies the username. */
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
   206
    strHandle = GetString(-16096);
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
   207
    UseResFile(origResourceFile);
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
   208
    BAIL_IF_MACRO(strHandle == NULL, ERR_OS_ERROR, NULL);
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   209
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
   210
    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
   211
    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
   212
    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
   213
    {
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
   214
        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
   215
        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
   216
    } /* 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
   217
    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
   218
    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
   219
    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
   220
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   221
    return(retval);
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   222
} /* __PHYSFS_platformGetUserName */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   223
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   224
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
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
   226
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   227
    return(NULL);  /* bah...use default behaviour, I guess. */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   228
} /* __PHYSFS_platformGetUserDir */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   229
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   230
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   231
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
   232
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   233
    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
   234
} /* __PHYSFS_platformGetThreadID */
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
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   237
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
   238
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   239
    extern int _stricmp(const char *, const char *);
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   240
    return(_stricmp(x, y));  /* (*shrug*) */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   241
} /* __PHYSFS_platformStricmp */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   242
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   243
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   244
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
   245
{
169
34829282ffe8 Fixed isDirectory and enumarateFiles (had wrong param in PBGetCatInfoSync()).
Ryan C. Gordon <icculus@icculus.org>
parents: 166
diff changeset
   246
    OSErr err;
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   247
    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
   248
    int needColon = (strchr(fname, ':')  == 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
   249
    int len = strlen(fname) + ((needColon) ? 1 : 0);
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   250
    if (len > 255)
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   251
        return(bdNamErr);
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   252
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   253
    /* !!! FIXME: What happens with relative pathnames? */
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   254
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
   255
    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
   256
    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
   257
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   258
    /* 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
   259
    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
   260
        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
   261
169
34829282ffe8 Fixed isDirectory and enumarateFiles (had wrong param in PBGetCatInfoSync()).
Ryan C. Gordon <icculus@icculus.org>
parents: 166
diff changeset
   262
    err = FSMakeFSSpec(0, 0, str255, spec);
34829282ffe8 Fixed isDirectory and enumarateFiles (had wrong param in PBGetCatInfoSync()).
Ryan C. Gordon <icculus@icculus.org>
parents: 166
diff changeset
   263
    return(err);
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   264
} /* fnameToFSSpecNoAlias */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   265
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   266
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   267
/* !!! FIXME: This code is pretty heinous. */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   268
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
   269
{
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   270
    Boolean alias = 0;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   271
    Boolean folder = 0;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   272
    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
   273
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   274
    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
   275
    {
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   276
        /* 
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   277
         * 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
   278
         *  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
   279
         *  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
   280
         */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   281
        char *ptr;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   282
        char *start;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   283
        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
   284
        strcpy(path, fname);
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   285
        ptr = strchr(path, ':');
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   286
        BAIL_IF_MACRO(!ptr, ERR_FILE_NOT_FOUND, err); /* just in case */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   287
        ptr = strchr(ptr + 1, ':');
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   288
        BAIL_IF_MACRO(!ptr, ERR_FILE_NOT_FOUND, err); /* just in case */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   289
        *ptr = '\0';
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   290
        err = fnameToFSSpecNoAlias(path, spec); /* get first dir. */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   291
        BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, err);
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   292
        start = ptr;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   293
        ptr = strchr(start + 1, ':');
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   294
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   295
        do
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   296
        {
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   297
            CInfoPBRec infoPB;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   298
            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
   299
            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
   300
            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
   301
            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
   302
            infoPB.dirInfo.ioFDirIndex = 0;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   303
            err = PBGetCatInfoSync(&infoPB);
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   304
            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
   305
                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
   306
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   307
            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
   308
                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
   309
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   310
            if (ptr != NULL)
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   311
                *ptr = '\0';
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   312
            *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
   313
            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
   314
                               (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
   315
            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
   316
                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
   317
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   318
            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
   319
            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
   320
                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
   321
            start = ptr;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   322
            if (ptr != NULL)
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   323
                ptr = strchr(start + 1, ':');                
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   324
        } while (start != NULL);
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   325
    } /* if */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   326
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   327
    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
   328
    {
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   329
        BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, err);
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   330
        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
   331
        BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, err);
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   332
    } /* else */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   333
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   334
    return(noErr);  /* w00t. */
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   335
} /* fnameToFSSpec */
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   336
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   337
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   338
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
   339
{
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   340
    FSSpec spec;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   341
    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
   342
} /* __PHYSFS_platformExists */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   343
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
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
   346
{
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   347
    OSErr err;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   348
    FSSpec spec;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   349
    Boolean a = 0;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   350
    Boolean f = 0;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   351
    CInfoPBRec infoPB;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   352
    char *ptr;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   353
    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
   354
    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
   355
    strcpy(dir, fname);
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   356
    ptr = strrchr(dir, ':');
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   357
    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
   358
        return(0);
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   359
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   360
    /* 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
   361
    *ptr = '\0';
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   362
    BAIL_IF_MACRO(fnameToFSSpec(dir, &spec) != noErr, ERR_OS_ERROR, 0);
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   363
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   364
    *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
   365
    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
   366
    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
   367
    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
   368
    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
   369
    infoPB.dirInfo.ioFDirIndex = 0;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   370
    BAIL_IF_MACRO(PBGetCatInfoSync(&infoPB) != noErr, ERR_OS_ERROR, 0);
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   371
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   372
    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
   373
                       (const unsigned char *) ptr, &spec);
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   374
    BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, 0);
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   375
    BAIL_IF_MACRO(IsAliasFile(&spec, &a, &f) != noErr, ERR_OS_ERROR, 0);
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   376
    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
   377
} /* __PHYSFS_platformIsSymlink */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   378
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   379
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   380
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
   381
{
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   382
    FSSpec spec;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   383
    CInfoPBRec infoPB;
169
34829282ffe8 Fixed isDirectory and enumarateFiles (had wrong param in PBGetCatInfoSync()).
Ryan C. Gordon <icculus@icculus.org>
parents: 166
diff changeset
   384
    OSErr err;
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   385
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   386
    BAIL_IF_MACRO(fnameToFSSpec(fname, &spec) != noErr, ERR_OS_ERROR, 0);
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   387
    memset(&infoPB, '\0', sizeof (CInfoPBRec));
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   388
    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
   389
    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
   390
    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
   391
    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
   392
    err = PBGetCatInfoSync(&infoPB);
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
   393
    BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, 0);
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   394
    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
   395
} /* __PHYSFS_platformIsDirectory */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   396
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   397
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   398
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
   399
                                      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
   400
                                      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
   401
{
162
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   402
    int len = ((prepend) ? strlen(prepend) : 0) +
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   403
              ((append) ? strlen(append) : 0) +
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   404
              strlen(dirName) + 1;
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   405
    const char *src;
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   406
    char *dst;
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   407
    char *retval = malloc(len);
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   408
    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
   409
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   410
    if (prepend != NULL)
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   411
    {
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   412
        strcpy(retval, prepend);
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   413
        dst = retval + strlen(retval);
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   414
    } /* if */
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   415
    else
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   416
    {
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   417
        *retval = '\0';
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   418
        dst = retval;
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   419
    } /* else */
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   420
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   421
    for (src = dirName; *src; src++, dst++)
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   422
        *dst = ((*src == '/') ? ':' : *src);
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   423
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   424
    *dst = '\0';
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   425
    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
   426
} /* __PHYSFS_platformCvtToDependent */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   427
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   428
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   429
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
   430
{
162
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   431
    SystemTask();
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   432
} /* __PHYSFS_platformTimeslice */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   433
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   434
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   435
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
   436
                                                  int omitSymLinks)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   437
{
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   438
    LinkedStringList *retval = NULL;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   439
    LinkedStringList *l = NULL;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   440
    LinkedStringList *prev = 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
   441
    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
   442
    UInt16 max;
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   443
    FSSpec spec;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   444
    CInfoPBRec infoPB;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   445
    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
   446
    long dirID;
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   447
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   448
    BAIL_IF_MACRO(fnameToFSSpec(dirname, &spec) != noErr, ERR_OS_ERROR, 0);
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   449
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
   450
    /* 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
   451
    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
   452
    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
   453
    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
   454
    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
   455
    infoPB.dirInfo.ioFDirIndex = 0;           /* file (not parent) info. */
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   456
    BAIL_IF_MACRO(PBGetCatInfoSync(&infoPB) != noErr, ERR_OS_ERROR, 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
   457
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   458
    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
   459
        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
   460
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   461
    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
   462
    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
   463
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   464
    for (i = 1; i <= max; i++)
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   465
    {
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   466
        FSSpec aliasspec;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   467
        Boolean alias = 0;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   468
        Boolean folder = 0;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   469
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   470
        memset(&infoPB, '\0', sizeof (CInfoPBRec));
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   471
        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
   472
        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
   473
        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
   474
        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
   475
        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
   476
        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
   477
            continue;  /* skip this file. Oh well. */
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   478
183
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   479
        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
   480
            continue;  /* skip it. */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   481
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   482
        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
   483
            continue;  /* skip it. */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   484
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   485
        if ((alias) && (omitSymLinks))
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   486
            continue;
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   487
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   488
        /* still here? Add it to the list. */
352d940a99d0 Now handles Finder aliases as if they were symlinks.
Ryan C. Gordon <icculus@icculus.org>
parents: 173
diff changeset
   489
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   490
        l = (LinkedStringList *) malloc(sizeof (LinkedStringList));
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   491
        if (l == NULL)
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   492
            break;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   493
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   494
        l->str = (char *) malloc(str255[0] + 1);
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   495
        if (l->str == NULL)
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   496
        {
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   497
            free(l);
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   498
            break;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   499
        } /* if */
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   500
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   501
        memcpy(l->str, &str255[1], str255[0]);
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   502
        l->str[str255[0]] = '\0';
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   503
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   504
        if (retval == NULL)
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   505
            retval = l;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   506
        else
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   507
            prev->next = l;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   508
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   509
        prev = l;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   510
        l->next = 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
   511
    } /* for */
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   512
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   513
    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
   514
} /* __PHYSFS_platformEnumerateFiles */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   515
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   516
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   517
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
   518
{
162
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   519
    /*
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   520
     * 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
   521
     *  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
   522
     *  so just return the base dir.
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   523
     * 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
   524
     */
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   525
    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
   526
} /* __PHYSFS_platformCurrentDir */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   527
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   528
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   529
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
   530
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   531
    /* !!! FIXME: This isn't nearly right. */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   532
    char *retval = (char *) malloc(strlen(path) + 1);
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   533
    strcpy(retval, path);
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   534
    return(retval);
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   535
} /* __PHYSFS_platformRealPath */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   536
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   537
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   538
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
   539
{
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
   540
    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
   541
    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
   542
    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
   543
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   544
    BAIL_IF_MACRO(err == noErr, ERR_FILE_EXISTS, 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
   545
    BAIL_IF_MACRO(err != fnfErr, ERR_OS_ERROR, 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
   546
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   547
    err = DirCreate(spec.vRefNum, spec.parID, spec.name, &val);
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   548
    BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, 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
   549
    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
   550
} /* __PHYSFS_platformMkDir */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   551
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   552
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
   553
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
   554
{
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   555
    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
   556
    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
   557
    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
   558
    OSErr err = fnameToFSSpec(fname, &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
   559
    BAIL_IF_MACRO((err != noErr) && (err != fnfErr), ERR_OS_ERROR, 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
   560
    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
   561
    {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   562
        BAIL_IF_MACRO(!createIfMissing, ERR_FILE_NOT_FOUND, 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
   563
        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
   564
                      procInfo.processSignature, 'BINA');
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   565
        BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, 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
   566
        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
   567
    } /* 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
   568
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   569
    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
   570
    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
   571
    {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   572
        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
   573
            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
   574
        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
   575
    } /* 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
   576
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   577
    if (HOpenDF(spec.vRefNum, spec.parID, spec.name, perm, retval) != 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
   578
    {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   579
        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
   580
        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
   581
            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
   582
        BAIL_MACRO(ERR_OS_ERROR, 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
   583
    } /* 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
   584
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   585
    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
   586
} /* 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
   587
72a59de5e6e5 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
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   589
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
   590
{
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
   591
    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
   592
    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
   593
    {
72a59de5e6e5 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
        if (SetFPos(*retval, fsFromStart, 0) != 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
   595
        {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   596
            FSClose(*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
   597
            BAIL_MACRO(ERR_OS_ERROR, 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
   598
        } /* 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
   599
    } /* 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
   600
72a59de5e6e5 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
    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
   602
} /* __PHYSFS_platformOpenRead */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   603
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   604
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   605
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
   606
{
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
   607
    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
   608
    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
   609
    {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   610
        if ((SetEOF(*retval, 0) != 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
   611
            (SetFPos(*retval, fsFromStart, 0) != 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
   612
        {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   613
            FSClose(*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
   614
            BAIL_MACRO(ERR_OS_ERROR, 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
   615
        } /* 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
   616
    } /* 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
   617
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   618
    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
   619
} /* __PHYSFS_platformOpenWrite */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   620
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   621
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   622
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
   623
{
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
   624
    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
   625
    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
   626
    {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   627
        if (SetFPos(*retval, fsFromLEOF, 0) != 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
   628
        {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   629
            FSClose(*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
   630
            BAIL_MACRO(ERR_OS_ERROR, 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
   631
        } /* 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
   632
    } /* 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
   633
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   634
    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
   635
} /* __PHYSFS_platformOpenAppend */
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
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
   639
                                    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
   640
{
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
   641
    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
   642
    SInt32 br;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   643
    PHYSFS_uint32 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
   644
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   645
    for (i = 0; i < count; 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
   646
    {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   647
        br = size;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   648
        BAIL_IF_MACRO(FSRead(ref, &br, buffer) != noErr, ERR_OS_ERROR, 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
   649
        BAIL_IF_MACRO(br != size, ERR_OS_ERROR, 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
   650
        buffer = ((PHYSFS_uint8 *) buffer) + size;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   651
    } /* for */
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   652
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   653
    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
   654
} /* __PHYSFS_platformRead */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   655
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   656
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   657
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
   658
                                     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
   659
{
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
   660
    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
   661
    SInt32 bw;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   662
    PHYSFS_uint32 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
   663
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   664
    for (i = 0; i < count; 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
   665
    {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   666
        bw = size;
72a59de5e6e5 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
        BAIL_IF_MACRO(FSWrite(ref, &bw, buffer) != noErr, ERR_OS_ERROR, 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
   668
        BAIL_IF_MACRO(bw != size, ERR_OS_ERROR, 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
   669
        buffer = ((PHYSFS_uint8 *) buffer) + size;
72a59de5e6e5 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
    } /* for */
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   671
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   672
    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
   673
} /* __PHYSFS_platformWrite */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   674
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   675
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   676
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
   677
{
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   678
    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
   679
    OSErr err = SetFPos(ref, fsFromStart, (SInt32) pos);
72a59de5e6e5 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
    BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, 0);
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   681
    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
   682
} /* __PHYSFS_platformSeek */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   683
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   684
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   685
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
   686
{
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
    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
   688
    SInt32 curPos;
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   689
    BAIL_IF_MACRO(GetFPos(ref, &curPos) != noErr, ERR_OS_ERROR, -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
   690
    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
   691
} /* __PHYSFS_platformTell */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   692
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   693
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   694
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
   695
{
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   696
    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
   697
    SInt32 eofPos;
72a59de5e6e5 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
    BAIL_IF_MACRO(GetEOF(ref, &eofPos) != noErr, ERR_OS_ERROR, -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
   699
    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
   700
} /* __PHYSFS_platformFileLength */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   701
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   702
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   703
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
   704
{
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
   705
    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
   706
    SInt32 eofPos, curPos;
72a59de5e6e5 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
    BAIL_IF_MACRO(GetEOF(ref, &eofPos) != noErr, ERR_OS_ERROR, 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
   708
    BAIL_IF_MACRO(GetFPos(ref, &curPos) != noErr, ERR_OS_ERROR, 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
   709
    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
   710
} /* __PHYSFS_platformEOF */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   711
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   712
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   713
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
   714
{
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
   715
    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
   716
    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
   717
    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
   718
    pb.ioParam.ioRefNum = ref;
72a59de5e6e5 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
    BAIL_IF_MACRO(PBFlushFileSync(&pb) != noErr, ERR_OS_ERROR, 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
    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
   721
} /* __PHYSFS_platformFlush */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   722
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   723
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   724
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
   725
{
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
    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
   727
    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
   728
    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
   729
    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
   730
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   731
    BAIL_IF_MACRO(GetVRefNum (ref, &vRefNum) != noErr, ERR_OS_ERROR, 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
   732
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   733
    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
   734
    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
   735
    hpbr.volumeParam.ioVRefNum = 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
   736
    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
   737
    BAIL_IF_MACRO(PBHGetVInfoSync(&hpbr) != noErr, ERR_OS_ERROR, 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
   738
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   739
    BAIL_IF_MACRO(FSClose(ref) != noErr, ERR_OS_ERROR, 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
   740
    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
   741
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   742
    FlushVol(volName, 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
   743
    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
   744
} /* __PHYSFS_platformClose */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   745
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   746
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   747
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
   748
{
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
   749
    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
   750
    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
   751
    BAIL_IF_MACRO(fnameToFSSpec(path, &spec) != noErr, ERR_OS_ERROR, 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
   752
    err = 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
   753
    BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, 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
   754
    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
   755
} /* __PHYSFS_platformDelete */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   756
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   757
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   758
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
   759
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   760
    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
   761
} /* __PHYSFS_platformCreateMutex */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   762
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   763
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   764
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
   765
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   766
    /* 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
   767
} /* __PHYSFS_platformDestroyMutex */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   768
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   769
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   770
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
   771
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   772
    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
   773
} /* __PHYSFS_platformGrabMutex */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   774
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   775
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   776
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
   777
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   778
    /* 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
   779
} /* __PHYSFS_platformReleaseMutex */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   780
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
   781
/* 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
   782