platform/macclassic.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 05 Apr 2002 09:04:34 +0000
changeset 173 72a59de5e6e5
parent 169 34829282ffe8
child 183 352d940a99d0
permissions -rw-r--r--
Mostly implemented (fully implemented if you don't want aliases to work like 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>
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
/*
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
 * 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
    14
 *  MacOS X at all. The code in unix.c is known to work with Darwin,
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
 *  and you may or may not be better off using that.
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
 */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
#ifdef __PHYSFS_CARBONIZED__   
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
#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
    19
#else
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
#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
    21
#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
    22
#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
    23
#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
    24
#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
    25
#include <MacMemory.h>
162
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
    26
#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
    27
#include <DriverGestalt.h>
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
#endif
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
#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
    31
#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
    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
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
    35
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
    36
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
    37
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
    38
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
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
    40
{
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
    41
    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
    42
    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
    43
    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
    44
    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
    45
    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
    46
    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
    47
    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
    48
    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
    49
    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
    50
    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
    51
} /* __PHYSFS_platformInit */
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
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
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
    55
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
    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
    57
} /* __PHYSFS_platformDeinit */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
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
    60
/* 
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
    61
 * 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
    62
 *  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
    63
 */
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
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
    65
{
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
    66
    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
    67
    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
    68
    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
    69
    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
    70
    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
    71
72a59de5e6e5 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(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
    73
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
    74
    *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
    75
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
    76
    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
    77
    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
    78
    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
    79
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
    80
    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
    81
    {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
    82
        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
    83
        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
    84
        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
    85
        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
    86
        {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
    87
            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
    88
            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
    89
            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
    90
            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
    91
            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
    92
            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
    93
            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
    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
                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
    96
                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
    97
                {
72a59de5e6e5 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
                    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
    99
                    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
   100
                    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
   101
                    {
72a59de5e6e5 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
                        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
   103
                        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
   104
                        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
   105
                        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
   106
                    } /* 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
   107
                } /* 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
   108
            } /* 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
   109
        } /* 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
   110
72a59de5e6e5 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
        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
   112
    } /* 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
   113
72a59de5e6e5 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
    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
   115
    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
   116
} /* __PHYSFS_platformDetectAvailableCDs */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
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
   120
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
    char *ptr;
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
    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
   123
    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
   124
    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
   125
    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
   126
    FSSpec spec;
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
    
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
    /* 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
   129
    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
   130
    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
   131
    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
   132
    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
   133
    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
   134
    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
   135
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
    /* 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
   137
    do
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
    {
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
        /* 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
   140
        infoPB.dirInfo.ioDrDirID = infoPB.dirInfo.ioDrParID;
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   141
        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
   142
        {
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
            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
   144
                free(retval);
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
            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
   146
        } /* if */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
        
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
        /* 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
   149
        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
   150
        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
   151
        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
   152
        {
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
            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
   154
                free(retval);
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
            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
   156
        } /* if */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
        /* 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
   159
        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
   160
        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
   161
        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
   162
        {
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
            strcat(ptr, ":");
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   164
            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
   165
            free(retval);
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
        } /* if */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
        retval = ptr;
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   168
    } 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
   169
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
    return(retval);
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
} /* __PHYSFS_platformCalcBaseDir */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   174
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
   175
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
    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
   177
    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
   178
    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
   179
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
   180
    /* 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
   181
    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
   182
    /* 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
   183
    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
   184
    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
   185
    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
   186
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
   187
    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
   188
    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
   189
    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
   190
    {
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
   191
        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
   192
        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
   193
    } /* 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
   194
    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
   195
    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
   196
    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
   197
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
    return(retval);
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
} /* __PHYSFS_platformGetUserName */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   201
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
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
   203
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
    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
   205
} /* __PHYSFS_platformGetUserDir */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
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
   209
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
    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
   211
} /* __PHYSFS_platformGetThreadID */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
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
   215
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   216
    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
   217
    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
   218
} /* __PHYSFS_platformStricmp */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   219
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   220
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   221
static OSErr fnameToFSSpec(const char *fname, FSSpec *spec)
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   222
{
169
34829282ffe8 Fixed isDirectory and enumarateFiles (had wrong param in PBGetCatInfoSync()).
Ryan C. Gordon <icculus@icculus.org>
parents: 166
diff changeset
   223
    OSErr err;
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   224
    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
   225
    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
   226
    int len = strlen(fname) + ((needColon) ? 1 : 0);
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   227
    if (len > 255)
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   228
        return(bdNamErr);
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   229
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   230
    /* !!! FIXME: What happens with relative pathnames? */
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   231
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
   232
    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
   233
    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
   234
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   235
    /* 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
   236
    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
   237
        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
   238
169
34829282ffe8 Fixed isDirectory and enumarateFiles (had wrong param in PBGetCatInfoSync()).
Ryan C. Gordon <icculus@icculus.org>
parents: 166
diff changeset
   239
    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
   240
    return(err);
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   241
} /* fnameToFSSpec */
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   242
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   243
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   244
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
   245
{
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   246
    FSSpec spec;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   247
    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
   248
} /* __PHYSFS_platformExists */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   249
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   250
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   251
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
   252
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   253
    return(0);  /* !!! FIXME: What happens if (fname) is an alias? */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   254
} /* __PHYSFS_platformIsSymlink */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   255
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   256
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   257
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
   258
{
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   259
    FSSpec spec;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   260
    CInfoPBRec infoPB;
169
34829282ffe8 Fixed isDirectory and enumarateFiles (had wrong param in PBGetCatInfoSync()).
Ryan C. Gordon <icculus@icculus.org>
parents: 166
diff changeset
   261
    OSErr err;
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   262
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   263
    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
   264
    memset(&infoPB, '\0', sizeof (CInfoPBRec));
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   265
    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
   266
    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
   267
    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
   268
    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
   269
    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
   270
    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
   271
    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
   272
} /* __PHYSFS_platformIsDirectory */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   273
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   274
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   275
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
   276
                                      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
   277
                                      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
   278
{
162
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   279
    int len = ((prepend) ? strlen(prepend) : 0) +
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   280
              ((append) ? strlen(append) : 0) +
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   281
              strlen(dirName) + 1;
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   282
    const char *src;
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   283
    char *dst;
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   284
    char *retval = malloc(len);
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   285
    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
   286
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   287
    if (prepend != NULL)
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   288
    {
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   289
        strcpy(retval, prepend);
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   290
        dst = retval + strlen(retval);
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   291
    } /* if */
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   292
    else
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   293
    {
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   294
        *retval = '\0';
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   295
        dst = retval;
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   296
    } /* else */
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   297
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   298
    for (src = dirName; *src; src++, dst++)
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   299
        *dst = ((*src == '/') ? ':' : *src);
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   300
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   301
    *dst = '\0';
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   302
    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
   303
} /* __PHYSFS_platformCvtToDependent */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   304
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   305
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   306
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
   307
{
162
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   308
    SystemTask();
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   309
} /* __PHYSFS_platformTimeslice */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   310
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   311
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   312
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
   313
                                                  int omitSymLinks)
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   314
{
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   315
    LinkedStringList *retval = NULL;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   316
    LinkedStringList *l = NULL;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   317
    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
   318
    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
   319
    UInt16 max;
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   320
    FSSpec spec;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   321
    CInfoPBRec infoPB;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   322
    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
   323
    long dirID;
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   324
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   325
    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
   326
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
   327
    /* 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
   328
    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
   329
    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
   330
    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
   331
    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
   332
    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
   333
    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
   334
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   335
    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
   336
        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
   337
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   338
    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
   339
    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
   340
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   341
    for (i = 1; i <= max; i++)
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   342
    {
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   343
        memset(&infoPB, '\0', sizeof (CInfoPBRec));
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   344
        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
   345
        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
   346
        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
   347
        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
   348
        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
   349
        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
   350
            continue;  /* skip this file. Oh well. */
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   351
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   352
        l = (LinkedStringList *) malloc(sizeof (LinkedStringList));
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   353
        if (l == NULL)
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   354
            break;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   355
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   356
        l->str = (char *) malloc(str255[0] + 1);
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   357
        if (l->str == NULL)
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   358
        {
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   359
            free(l);
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   360
            break;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   361
        } /* if */
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   362
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   363
        memcpy(l->str, &str255[1], str255[0]);
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   364
        l->str[str255[0]] = '\0';
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   365
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   366
        if (retval == NULL)
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   367
            retval = l;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   368
        else
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   369
            prev->next = l;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   370
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   371
        prev = l;
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   372
        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
   373
    } /* for */
166
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   374
ed10fe7cb16e More work. More to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 162
diff changeset
   375
    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
   376
} /* __PHYSFS_platformEnumerateFiles */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   377
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
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
   380
{
162
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   381
    /*
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   382
     * 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
   383
     *  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
   384
     *  so just return the base dir.
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   385
     * 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
   386
     */
06ed1dc94f73 Implemented platformTimeslice, platformGetCurrentDir, and platformCvtToDependent.
Ryan C. Gordon <icculus@icculus.org>
parents: 158
diff changeset
   387
    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
   388
} /* __PHYSFS_platformCurrentDir */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   389
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   390
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   391
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
   392
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   393
    /* !!! 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
   394
    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
   395
    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
   396
    return(retval);
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   397
} /* __PHYSFS_platformRealPath */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   398
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   399
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   400
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
   401
{
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
   402
    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
   403
    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
   404
    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
   405
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   406
    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
   407
    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
   408
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   409
    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
   410
    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
   411
    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
   412
} /* __PHYSFS_platformMkDir */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   413
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   414
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
   415
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
   416
{
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   417
    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
   418
    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
   419
    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
   420
    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
   421
    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
   422
    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
   423
    {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   424
        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
   425
        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
   426
                      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
   427
        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
   428
        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
   429
    } /* 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
   430
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   431
    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
   432
    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
   433
    {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   434
        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
   435
            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
   436
        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
   437
    } /* 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
   438
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   439
    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
   440
    {
72a59de5e6e5 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
        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
   442
        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
   443
            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
   444
        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
   445
    } /* 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
   446
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   447
    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
   448
} /* 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
   449
72a59de5e6e5 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
157
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   451
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
   452
{
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
   453
    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
   454
    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
   455
    {
72a59de5e6e5 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
        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
   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
            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
   459
            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
   460
        } /* 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
   461
    } /* 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
   462
72a59de5e6e5 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
    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
   464
} /* __PHYSFS_platformOpenRead */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   465
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   466
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   467
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
   468
{
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
   469
    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
   470
    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
   471
    {
72a59de5e6e5 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
        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
   473
            (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
   474
        {
72a59de5e6e5 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
            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
   476
            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
   477
        } /* 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
   478
    } /* 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
   479
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   480
    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
   481
} /* __PHYSFS_platformOpenWrite */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   482
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   483
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   484
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
   485
{
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
   486
    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
   487
    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
   488
    {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   489
        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
   490
        {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   491
            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
   492
            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
   493
        } /* 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
   494
    } /* 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
   495
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   496
    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
   497
} /* __PHYSFS_platformOpenAppend */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   498
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   499
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   500
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
   501
                                    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
   502
{
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
   503
    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
   504
    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
   505
    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
   506
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   507
    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
   508
    {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   509
        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
   510
        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
   511
        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
   512
        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
   513
    } /* 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
   514
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   515
    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
   516
} /* __PHYSFS_platformRead */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   517
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   518
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   519
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
   520
                                     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
   521
{
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
   522
    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
   523
    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
   524
    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
   525
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   526
    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
   527
    {
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   528
        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
   529
        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
   530
        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
   531
        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
   532
    } /* 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
   533
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   534
    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
   535
} /* __PHYSFS_platformWrite */
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_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
   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
    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
   541
    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
   542
    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
   543
    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
   544
} /* __PHYSFS_platformSeek */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   545
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   546
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   547
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
   548
{
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
   549
    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
   550
    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
   551
    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
   552
    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
   553
} /* __PHYSFS_platformTell */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   554
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   555
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   556
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
   557
{
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
   558
    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
   559
    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
   560
    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
   561
    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
   562
} /* __PHYSFS_platformFileLength */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   563
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   564
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   565
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
   566
{
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
   567
    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
   568
    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
   569
    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
   570
    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
   571
    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
   572
} /* __PHYSFS_platformEOF */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   573
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   574
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   575
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
   576
{
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
   577
    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
   578
    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
   579
    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
   580
    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
   581
    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
   582
    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
   583
} /* __PHYSFS_platformFlush */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   584
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   585
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   586
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
   587
{
173
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   588
    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
   589
    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
   590
    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
   591
    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
   592
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   593
    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
   594
72a59de5e6e5 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
    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
   596
    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
   597
    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
   598
    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
   599
    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
   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
    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
   602
    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
   603
72a59de5e6e5 Mostly implemented (fully implemented if you don't want aliases to work like symlinks).
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   604
    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
   605
    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
   606
} /* __PHYSFS_platformClose */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   607
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   608
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   609
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
   610
{
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
   611
    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
   612
    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
   613
    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
   614
    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
   615
    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
   616
    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
   617
} /* __PHYSFS_platformDelete */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   618
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   619
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   620
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
   621
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   622
    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
   623
} /* __PHYSFS_platformCreateMutex */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   624
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   625
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   626
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
   627
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   628
    /* 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
   629
} /* __PHYSFS_platformDestroyMutex */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   630
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   631
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   632
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
   633
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   634
    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
   635
} /* __PHYSFS_platformGrabMutex */
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
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
   639
{
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   640
    /* 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
   641
} /* __PHYSFS_platformReleaseMutex */
916ee05fe0db Initial add. Not nearly complete, but enough to get through PHYSFS_init().
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   642
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
   643
/* 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
   644