physfs.c
author Ryan C. Gordon <icculus@icculus.org>
Sat, 06 Apr 2002 05:18:49 +0000
changeset 186 fcabc280b29d
parent 167 fd695ca50a2c
child 193 830c165052a5
permissions -rw-r--r--
Updated.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/**
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
 * PhysicsFS; a portable, flexible file i/o abstraction.
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 *
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
 * Documentation is in physfs.h. It's verbose, honest.  :)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 *
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
 * Please see the file LICENSE in the source's root directory.
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
 *
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
 *  This file written by Ryan C. Gordon.
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
 */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
#include <stdio.h>
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
#include <stdlib.h>
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
#include <string.h>
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
    14
#include <fcntl.h>
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
    15
#include <errno.h>
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
#include <assert.h>
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
#include "physfs.h"
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    19
#define __PHYSICSFS_INTERNAL__
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    20
#include "physfs_internal.h"
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    21
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
typedef struct __PHYSFS_ERRMSGTYPE__
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
{
163
fc2b8ee5b420 Approved zeph's comments, fixed a few of my screwups.
Ryan C. Gordon <icculus@icculus.org>
parents: 160
diff changeset
    24
    PHYSFS_uint64 tid;
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
    int errorAvailable;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
    char errorString[80];
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
    struct __PHYSFS_ERRMSGTYPE__ *next;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
} ErrMsg;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
    30
typedef struct __PHYSFS_DIRINFO__
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
{
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
    char *dirName;
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
    33
    DirHandle *dirHandle;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
    34
    struct __PHYSFS_DIRINFO__ *next;
150
221f15a7cb08 Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
    35
} PhysDirInfo;
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    37
typedef struct __PHYSFS_FILEHANDLELIST__
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    38
{
27
e1d3292769b2 Rewrote the file closing routines to not be so gay. Cleaned up the opening
Ryan C. Gordon <icculus@icculus.org>
parents: 25
diff changeset
    39
    PHYSFS_file handle;
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    40
    struct __PHYSFS_FILEHANDLELIST__ *next;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    41
} FileHandleList;
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    43
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    44
/* The various i/o drivers... */
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    46
#if (defined PHYSFS_SUPPORTS_ZIP)
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    47
extern const PHYSFS_ArchiveInfo   __PHYSFS_ArchiveInfo_ZIP;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    48
extern const DirFunctions         __PHYSFS_DirFunctions_ZIP;
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    49
#endif
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    50
22
49f6101707b4 More tweaks; GRP completely implemented. Everything builds clean.
Ryan C. Gordon <icculus@icculus.org>
parents: 21
diff changeset
    51
#if (defined PHYSFS_SUPPORTS_GRP)
49f6101707b4 More tweaks; GRP completely implemented. Everything builds clean.
Ryan C. Gordon <icculus@icculus.org>
parents: 21
diff changeset
    52
extern const PHYSFS_ArchiveInfo   __PHYSFS_ArchiveInfo_GRP;
49f6101707b4 More tweaks; GRP completely implemented. Everything builds clean.
Ryan C. Gordon <icculus@icculus.org>
parents: 21
diff changeset
    53
extern const DirFunctions         __PHYSFS_DirFunctions_GRP;
49f6101707b4 More tweaks; GRP completely implemented. Everything builds clean.
Ryan C. Gordon <icculus@icculus.org>
parents: 21
diff changeset
    54
#endif
49f6101707b4 More tweaks; GRP completely implemented. Everything builds clean.
Ryan C. Gordon <icculus@icculus.org>
parents: 21
diff changeset
    55
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    56
extern const DirFunctions  __PHYSFS_DirFunctions_DIR;
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    57
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    58
static const PHYSFS_ArchiveInfo *supported_types[] =
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
{
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
#if (defined PHYSFS_SUPPORTS_ZIP)
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    61
    &__PHYSFS_ArchiveInfo_ZIP,
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
#endif
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
21
b1ea58d70a56 Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
    64
#if (defined PHYSFS_SUPPORTS_GRP)
b1ea58d70a56 Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
    65
    &__PHYSFS_ArchiveInfo_GRP,
b1ea58d70a56 Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
    66
#endif
b1ea58d70a56 Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
    67
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
    NULL
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
};
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    71
static const DirFunctions *dirFunctions[] =
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    72
{
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    73
#if (defined PHYSFS_SUPPORTS_ZIP)
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    74
    &__PHYSFS_DirFunctions_ZIP,
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    75
#endif
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    76
21
b1ea58d70a56 Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
    77
#if (defined PHYSFS_SUPPORTS_GRP)
b1ea58d70a56 Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
    78
    &__PHYSFS_DirFunctions_GRP,
b1ea58d70a56 Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
    79
#endif
b1ea58d70a56 Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
    80
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    81
    &__PHYSFS_DirFunctions_DIR,
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    82
    NULL
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    83
};
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    84
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    87
/* General PhysicsFS state ... */
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    88
static int initialized = 0;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    89
static ErrMsg *errorMessages = NULL;
150
221f15a7cb08 Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
    90
static PhysDirInfo *searchPath = NULL;
221f15a7cb08 Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
    91
static PhysDirInfo *writeDir = NULL;
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    92
static FileHandleList *openWriteList = NULL;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    93
static FileHandleList *openReadList = NULL;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    94
static char *baseDir = NULL;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    95
static char *userDir = NULL;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    96
static int allowSymLinks = 0;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    97
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
    98
/* mutexes ... */
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
    99
static void *errorLock = NULL;     /* protects error message list.        */
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   100
static void *stateLock = NULL;     /* protects other PhysFS static state. */
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   101
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   102
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   103
/* functions ... */
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
static ErrMsg *findErrorForCurrentThread(void)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
{
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
    ErrMsg *i;
163
fc2b8ee5b420 Approved zeph's comments, fixed a few of my screwups.
Ryan C. Gordon <icculus@icculus.org>
parents: 160
diff changeset
   108
    PHYSFS_uint64 tid;
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   109
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   110
    __PHYSFS_platformGrabMutex(errorLock);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
    if (errorMessages != NULL)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
    {
163
fc2b8ee5b420 Approved zeph's comments, fixed a few of my screwups.
Ryan C. Gordon <icculus@icculus.org>
parents: 160
diff changeset
   113
        tid = __PHYSFS_platformGetThreadID();
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
        for (i = errorMessages; i != NULL; i = i->next)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
        {
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
            if (i->tid == tid)
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   118
            {
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   119
                __PHYSFS_platformReleaseMutex(errorLock);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
                return(i);
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   121
            } /* if */
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
        } /* for */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
    } /* if */
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   124
    __PHYSFS_platformReleaseMutex(errorLock);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
    return(NULL);   /* no error available. */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
} /* findErrorForCurrentThread */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   130
void __PHYSFS_setError(const char *str)
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
{
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   132
    ErrMsg *err;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   133
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   134
    if (str == NULL)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   135
        return;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   136
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   137
    err = findErrorForCurrentThread();
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
    if (err == NULL)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
    {
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
        err = (ErrMsg *) malloc(sizeof (ErrMsg));
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
        if (err == NULL)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
            return;   /* uhh...? */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
57
1ec888db3df9 Safety memset when creating error information for a new thread.
Ryan C. Gordon <icculus@icculus.org>
parents: 51
diff changeset
   145
        memset((void *) err, '\0', sizeof (ErrMsg));
163
fc2b8ee5b420 Approved zeph's comments, fixed a few of my screwups.
Ryan C. Gordon <icculus@icculus.org>
parents: 160
diff changeset
   146
        err->tid = __PHYSFS_platformGetThreadID();
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   147
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   148
        __PHYSFS_platformGrabMutex(errorLock);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
        err->next = errorMessages;
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   150
        errorMessages = err;
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   151
        __PHYSFS_platformReleaseMutex(errorLock);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
    } /* if */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
    err->errorAvailable = 1;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
    strncpy(err->errorString, str, sizeof (err->errorString));
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
    err->errorString[sizeof (err->errorString) - 1] = '\0';
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   157
} /* __PHYSFS_setError */
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
const char *PHYSFS_getLastError(void)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
{
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
    ErrMsg *err = findErrorForCurrentThread();
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   164
    if ((err == NULL) || (!err->errorAvailable))
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
        return(NULL);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
    err->errorAvailable = 0;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   168
    return(err->errorString);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
} /* PHYSFS_getLastError */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   172
/* MAKE SURE that errorLock is held before calling this! */
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   173
static void freeErrorMessages(void)
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   174
{
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   175
    ErrMsg *i;
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   176
    ErrMsg *next;
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   177
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   178
    for (i = errorMessages; i != NULL; i = next)
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   179
    {
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   180
        next = i->next;
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   181
        free(i);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   182
    } /* for */
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   183
} /* freeErrorMessages */
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   184
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   185
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
void PHYSFS_getLinkedVersion(PHYSFS_Version *ver)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
{
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   188
    if (ver != NULL)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
    {
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
        ver->major = PHYSFS_VER_MAJOR;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   191
        ver->minor = PHYSFS_VER_MINOR;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
        ver->patch = PHYSFS_VER_PATCH;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
    } /* if */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
} /* PHYSFS_getLinkedVersion */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   197
static DirHandle *openDirectory(const char *d, int forWriting)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   198
{
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   199
    const DirFunctions **i;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   200
44
534901592376 Non-existant archives/directories report a more correct error, and a call
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   201
    BAIL_IF_MACRO(!__PHYSFS_platformExists(d), ERR_NO_SUCH_FILE, NULL);
534901592376 Non-existant archives/directories report a more correct error, and a call
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   202
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   203
    for (i = dirFunctions; *i != NULL; i++)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   204
    {
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   205
        if ((*i)->isArchive(d, forWriting))
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   206
            return( (*i)->openArchive(d, forWriting) );
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   207
    } /* for */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   208
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   209
    __PHYSFS_setError(ERR_UNSUPPORTED_ARCHIVE);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   210
    return(NULL);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   211
} /* openDirectory */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   212
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   213
150
221f15a7cb08 Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
   214
static PhysDirInfo *buildDirInfo(const char *newDir, int forWriting)
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   215
{
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   216
    DirHandle *dirHandle = NULL;
150
221f15a7cb08 Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
   217
    PhysDirInfo *di = NULL;
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   218
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   219
    BAIL_IF_MACRO(newDir == NULL, ERR_INVALID_ARGUMENT, 0);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   220
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   221
    dirHandle = openDirectory(newDir, forWriting);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   222
    BAIL_IF_MACRO(dirHandle == NULL, NULL, 0);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   223
150
221f15a7cb08 Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
   224
    di = (PhysDirInfo *) malloc(sizeof (PhysDirInfo));
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   225
    if (di == NULL)
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   226
    {
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 19
diff changeset
   227
        dirHandle->funcs->dirClose(dirHandle);
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   228
        BAIL_IF_MACRO(di == NULL, ERR_OUT_OF_MEMORY, 0);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   229
    } /* if */
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   230
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   231
    di->dirName = (char *) malloc(strlen(newDir) + 1);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   232
    if (di->dirName == NULL)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   233
    {
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   234
        free(di);
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 19
diff changeset
   235
        dirHandle->funcs->dirClose(dirHandle);
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   236
        BAIL_MACRO(ERR_OUT_OF_MEMORY, 0);
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   237
    } /* if */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   238
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   239
    di->next = NULL;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   240
    di->dirHandle = dirHandle;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   241
    strcpy(di->dirName, newDir);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   242
    return(di);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   243
} /* buildDirInfo */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   244
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   245
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   246
/* MAKE SURE you've got the stateLock held before calling this! */
150
221f15a7cb08 Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
   247
static int freeDirInfo(PhysDirInfo *di, FileHandleList *openList)
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   248
{
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   249
    FileHandleList *i;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   250
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   251
    if (di == NULL)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   252
        return(1);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   253
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   254
    for (i = openList; i != NULL; i = i->next)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   255
    {
27
e1d3292769b2 Rewrote the file closing routines to not be so gay. Cleaned up the opening
Ryan C. Gordon <icculus@icculus.org>
parents: 25
diff changeset
   256
        const DirHandle *h = ((FileHandle *) &(i->handle.opaque))->dirHandle;
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   257
        BAIL_IF_MACRO(h == di->dirHandle, ERR_FILES_STILL_OPEN, 0);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   258
    } /* for */
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   259
    
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 19
diff changeset
   260
    di->dirHandle->funcs->dirClose(di->dirHandle);
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   261
    free(di->dirName);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   262
    free(di);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   263
    return(1);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   264
} /* freeDirInfo */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   265
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   266
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   267
static char *calculateUserDir(void)
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   268
{
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   269
    char *retval = NULL;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   270
    const char *str = NULL;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   271
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   272
    str = __PHYSFS_platformGetUserDir();
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   273
    if (str != NULL)
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   274
        retval = (char *) str;
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   275
    else
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   276
    {
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   277
        const char *dirsep = PHYSFS_getDirSeparator();
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   278
        const char *uname = __PHYSFS_platformGetUserName();
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   279
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   280
        str = (uname != NULL) ? uname : "default";
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   281
        retval = (char *) malloc(strlen(baseDir) + strlen(str) +
155
54fee85d9c26 Fixed calculateUserDir() to prevent extra dir separator insertion in default case.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
   282
                                 strlen(dirsep) + 6);
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   283
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   284
        if (retval == NULL)
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   285
            __PHYSFS_setError(ERR_OUT_OF_MEMORY);
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   286
        else
155
54fee85d9c26 Fixed calculateUserDir() to prevent extra dir separator insertion in default case.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
   287
            sprintf(retval, "%susers%s%s", baseDir, dirsep, str);
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   288
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   289
        if (uname != NULL)
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   290
            free((void *) uname);
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   291
    } /* else */
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   292
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   293
    return(retval);
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   294
} /* calculateUserDir */
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   295
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   296
23
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   297
static int appendDirSep(char **dir)
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   298
{
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   299
    const char *dirsep = PHYSFS_getDirSeparator();
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   300
    char *ptr;
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   301
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   302
    if (strcmp((*dir + strlen(*dir)) - strlen(dirsep), dirsep) == 0)
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   303
        return(1);
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   304
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   305
    ptr = realloc(*dir, strlen(*dir) + strlen(dirsep) + 1);
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   306
    if (!ptr)
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   307
    {
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   308
        free(*dir);
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   309
        return(0);
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   310
    } /* if */
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   311
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   312
    strcat(ptr, dirsep);
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   313
    *dir = ptr;
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   314
    return(1);
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   315
} /* appendDirSep */
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   316
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   317
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   318
static char *calculateBaseDir(const char *argv0)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   319
{
23
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   320
    const char *dirsep = PHYSFS_getDirSeparator();
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   321
    char *retval;
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   322
    char *ptr;
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   323
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   324
    /*
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   325
     * See if the platform driver wants to handle this for us...
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   326
     */
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   327
    retval = __PHYSFS_platformCalcBaseDir(argv0);
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   328
    if (retval != NULL)
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   329
        return(retval);
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   330
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   331
    /*
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   332
     * Determine if there's a path on argv0. If there is, that's the base dir.
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   333
     */
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   334
    ptr = strstr(argv0, dirsep);
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   335
    if (ptr != NULL)
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   336
    {
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   337
        char *p = ptr;
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   338
        size_t size;
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   339
        while (p != NULL)
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   340
        {
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   341
            ptr = p;
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   342
            p = strstr(p + 1, dirsep);
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   343
        } /* while */
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   344
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   345
        size = (size_t) (ptr - argv0);  /* !!! is this portable? */
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   346
        retval = (char *) malloc(size + 1);
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   347
        BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   348
        memcpy(retval, argv0, size);
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   349
        retval[size] = '\0';
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   350
        return(retval);
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   351
    } /* if */
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   352
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   353
    /*
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   354
     * Last ditch effort: it's the current working directory. (*shrug*)
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   355
     */
100
d2f04ab4b412 Patches from David Hedbor to handle missing current working directories.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   356
    retval = __PHYSFS_platformCurrentDir();
d2f04ab4b412 Patches from David Hedbor to handle missing current working directories.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   357
    if(retval != NULL) {
d2f04ab4b412 Patches from David Hedbor to handle missing current working directories.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   358
	return(retval);
d2f04ab4b412 Patches from David Hedbor to handle missing current working directories.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   359
    }
d2f04ab4b412 Patches from David Hedbor to handle missing current working directories.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   360
d2f04ab4b412 Patches from David Hedbor to handle missing current working directories.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   361
    /*
d2f04ab4b412 Patches from David Hedbor to handle missing current working directories.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   362
     * Ok, current directory doesn't exist, use the root directory.
d2f04ab4b412 Patches from David Hedbor to handle missing current working directories.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   363
     * Not a good alternative, but it only happens if the current
d2f04ab4b412 Patches from David Hedbor to handle missing current working directories.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   364
     * directory was deleted from under the program.
d2f04ab4b412 Patches from David Hedbor to handle missing current working directories.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   365
     */
d2f04ab4b412 Patches from David Hedbor to handle missing current working directories.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   366
    retval = (char *) malloc(strlen(dirsep) + 1);
d2f04ab4b412 Patches from David Hedbor to handle missing current working directories.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   367
    strcpy(retval, dirsep);
d2f04ab4b412 Patches from David Hedbor to handle missing current working directories.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   368
    return(retval);
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   369
} /* calculateBaseDir */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   370
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   371
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   372
static int initializeMutexes(void)
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   373
{
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   374
    errorLock = __PHYSFS_platformCreateMutex();
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   375
    if (errorLock == NULL)
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   376
        goto initializeMutexes_failed;
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   377
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   378
    stateLock = __PHYSFS_platformCreateMutex();
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   379
    if (stateLock == NULL)
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   380
        goto initializeMutexes_failed;
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   381
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   382
    return(1);  /* success. */
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   383
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   384
initializeMutexes_failed:
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   385
    if (errorLock != NULL)
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   386
        __PHYSFS_platformDestroyMutex(errorLock);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   387
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   388
    if (stateLock != NULL)
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   389
        __PHYSFS_platformDestroyMutex(stateLock);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   390
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   391
    errorLock = stateLock = NULL;
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   392
    return(0);  /* failed. */
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   393
} /* initializeMutexes */
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   394
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   395
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   396
int PHYSFS_init(const char *argv0)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   397
{
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   398
    char *ptr;
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   399
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   400
    BAIL_IF_MACRO(initialized, ERR_IS_INITIALIZED, 0);
130
2deec3eb7430 Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents: 126
diff changeset
   401
    BAIL_IF_MACRO(!__PHYSFS_platformInit(), NULL, 0);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   402
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   403
    BAIL_IF_MACRO(!initializeMutexes(), NULL, 0);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   404
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   405
    baseDir = calculateBaseDir(argv0);
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   406
    BAIL_IF_MACRO(baseDir == NULL, NULL, 0);
186
fcabc280b29d Updated.
Ryan C. Gordon <icculus@icculus.org>
parents: 167
diff changeset
   407
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   408
    ptr = __PHYSFS_platformRealPath(baseDir);
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   409
    free(baseDir);
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   410
    BAIL_IF_MACRO(ptr == NULL, NULL, 0);
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   411
    baseDir = ptr;
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   412
23
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   413
    BAIL_IF_MACRO(!appendDirSep(&baseDir), NULL, 0);
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   414
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   415
    userDir = calculateUserDir();
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   416
    if (userDir != NULL)
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   417
    {
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   418
        ptr = __PHYSFS_platformRealPath(userDir);
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   419
        free(userDir);
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   420
        userDir = ptr;
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   421
    } /* if */
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   422
23
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   423
    if ((userDir == NULL) || (!appendDirSep(&userDir)))
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   424
    {
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   425
        free(baseDir);
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   426
        baseDir = NULL;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   427
        return(0);
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   428
    } /* if */
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   429
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   430
    initialized = 1;
167
fd695ca50a2c Error subsystem does basic initialization during PHYSFS_init(), now.
Ryan C. Gordon <icculus@icculus.org>
parents: 163
diff changeset
   431
fd695ca50a2c Error subsystem does basic initialization during PHYSFS_init(), now.
Ryan C. Gordon <icculus@icculus.org>
parents: 163
diff changeset
   432
    /* This makes sure that the error subsystem is initialized. */
fd695ca50a2c Error subsystem does basic initialization during PHYSFS_init(), now.
Ryan C. Gordon <icculus@icculus.org>
parents: 163
diff changeset
   433
    __PHYSFS_setError(PHYSFS_getLastError());
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   434
    return(1);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   435
} /* PHYSFS_init */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   436
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   437
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   438
/* MAKE SURE you hold stateLock before calling this! */
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   439
static int closeFileHandleList(FileHandleList **list)
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   440
{
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   441
    FileHandleList *i;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   442
    FileHandleList *next = NULL;
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   443
    FileHandle *h;
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   444
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   445
    for (i = *list; i != NULL; i = next)
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   446
    {
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   447
        next = i->next;
27
e1d3292769b2 Rewrote the file closing routines to not be so gay. Cleaned up the opening
Ryan C. Gordon <icculus@icculus.org>
parents: 25
diff changeset
   448
        h = (FileHandle *) (i->handle.opaque);
e1d3292769b2 Rewrote the file closing routines to not be so gay. Cleaned up the opening
Ryan C. Gordon <icculus@icculus.org>
parents: 25
diff changeset
   449
        if (!h->funcs->fileClose(h))
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   450
        {
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   451
            *list = i;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   452
            return(0);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   453
        } /* if */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   454
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   455
        free(i);
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   456
    } /* for */
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   457
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   458
    *list = NULL;
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   459
    return(1);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   460
} /* closeFileHandleList */
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   461
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   462
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   463
/* MAKE SURE you hold the stateLock before calling this! */
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   464
static void freeSearchPath(void)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   465
{
150
221f15a7cb08 Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
   466
    PhysDirInfo *i;
221f15a7cb08 Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
   467
    PhysDirInfo *next = NULL;
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   468
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   469
    closeFileHandleList(&openReadList);
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   470
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   471
    if (searchPath != NULL)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   472
    {
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   473
        for (i = searchPath; i != NULL; i = next)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   474
        {
25
96b32c0fd7f3 Bugfix for infinite loop/touching free()'d memory during PHYSFS_deinit().
Ryan C. Gordon <icculus@icculus.org>
parents: 23
diff changeset
   475
            next = i->next;
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   476
            freeDirInfo(i, openReadList);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   477
        } /* for */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   478
        searchPath = NULL;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   479
    } /* if */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   480
} /* freeSearchPath */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   481
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   482
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   483
int PHYSFS_deinit(void)
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   484
{
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   485
    BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
130
2deec3eb7430 Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents: 126
diff changeset
   486
    BAIL_IF_MACRO(!__PHYSFS_platformDeinit(), NULL, 0);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   487
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   488
    closeFileHandleList(&openWriteList);
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   489
    BAIL_IF_MACRO(!PHYSFS_setWriteDir(NULL), ERR_FILES_STILL_OPEN, 0);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   490
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   491
    freeSearchPath();
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   492
    freeErrorMessages();
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   493
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   494
    if (baseDir != NULL)
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   495
    {
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   496
        free(baseDir);
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   497
        baseDir = NULL;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   498
    } /* if */
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   499
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   500
    if (userDir != NULL)
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   501
    {
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   502
        free(userDir);
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   503
        userDir = NULL;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   504
    } /* if */
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   505
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   506
    allowSymLinks = 0;
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   507
    initialized = 0;
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   508
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   509
    __PHYSFS_platformDestroyMutex(errorLock);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   510
    __PHYSFS_platformDestroyMutex(stateLock);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   511
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   512
    errorLock = stateLock = NULL;
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   513
    return(1);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   514
} /* PHYSFS_deinit */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   515
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   516
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   517
const PHYSFS_ArchiveInfo **PHYSFS_supportedArchiveTypes(void)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   518
{
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   519
    return(supported_types);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   520
} /* PHYSFS_supportedArchiveTypes */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   521
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   522
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   523
void PHYSFS_freeList(void *list)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   524
{
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   525
    void **i;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   526
    for (i = (void **) list; *i != NULL; i++)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   527
        free(*i);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   528
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   529
    free(list);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   530
} /* PHYSFS_freeList */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   531
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   532
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   533
const char *PHYSFS_getDirSeparator(void)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   534
{
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   535
    return(__PHYSFS_platformDirSeparator);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   536
} /* PHYSFS_getDirSeparator */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   537
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   538
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   539
char **PHYSFS_getCdRomDirs(void)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   540
{
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   541
    return(__PHYSFS_platformDetectAvailableCDs());
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   542
} /* PHYSFS_getCdRomDirs */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   543
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   544
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   545
const char *PHYSFS_getBaseDir(void)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   546
{
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   547
    return(baseDir);   /* this is calculated in PHYSFS_init()... */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   548
} /* PHYSFS_getBaseDir */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   549
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   550
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   551
const char *PHYSFS_getUserDir(void)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   552
{
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   553
    return(userDir);   /* this is calculated in PHYSFS_init()... */
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   554
} /* PHYSFS_getUserDir */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   555
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   556
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   557
const char *PHYSFS_getWriteDir(void)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   558
{
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   559
    const char *retval = NULL;
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   560
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   561
    __PHYSFS_platformGrabMutex(stateLock);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   562
    if (writeDir != NULL)
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   563
        retval = writeDir->dirName;
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   564
    __PHYSFS_platformReleaseMutex(stateLock);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   565
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   566
    return(retval);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   567
} /* PHYSFS_getWriteDir */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   568
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   569
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   570
int PHYSFS_setWriteDir(const char *newDir)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   571
{
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   572
    int retval = 1;
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   573
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   574
    __PHYSFS_platformGrabMutex(stateLock);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   575
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   576
    if (writeDir != NULL)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   577
    {
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   578
        BAIL_IF_MACRO_MUTEX(!freeDirInfo(writeDir, openWriteList), NULL, 
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   579
                            stateLock, 0);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   580
        writeDir = NULL;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   581
    } /* if */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   582
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   583
    if (newDir != NULL)
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   584
    {
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   585
        writeDir = buildDirInfo(newDir, 1);
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   586
        retval = (writeDir != NULL);
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   587
    } /* if */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   588
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   589
    __PHYSFS_platformReleaseMutex(stateLock);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   590
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   591
    return(retval);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   592
} /* PHYSFS_setWriteDir */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   593
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   594
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   595
int PHYSFS_addToSearchPath(const char *newDir, int appendToPath)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   596
{
150
221f15a7cb08 Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
   597
    PhysDirInfo *di;
221f15a7cb08 Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
   598
    PhysDirInfo *prev = NULL;
221f15a7cb08 Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
   599
    PhysDirInfo *i;
51
42f4befc1d0b Cleaned up PHYSFS_openRead() a little. PHYSFS_addToSearchPath() now
Ryan C. Gordon <icculus@icculus.org>
parents: 48
diff changeset
   600
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   601
    __PHYSFS_platformGrabMutex(stateLock);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   602
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   603
    for (i = searchPath; i != NULL; i = i->next)
51
42f4befc1d0b Cleaned up PHYSFS_openRead() a little. PHYSFS_addToSearchPath() now
Ryan C. Gordon <icculus@icculus.org>
parents: 48
diff changeset
   604
    {
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   605
        /* already in search path? */
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   606
        BAIL_IF_MACRO_MUTEX(strcmp(newDir, i->dirName)==0, NULL, stateLock, 1);
51
42f4befc1d0b Cleaned up PHYSFS_openRead() a little. PHYSFS_addToSearchPath() now
Ryan C. Gordon <icculus@icculus.org>
parents: 48
diff changeset
   607
        prev = i;
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   608
    } /* for */
51
42f4befc1d0b Cleaned up PHYSFS_openRead() a little. PHYSFS_addToSearchPath() now
Ryan C. Gordon <icculus@icculus.org>
parents: 48
diff changeset
   609
42f4befc1d0b Cleaned up PHYSFS_openRead() a little. PHYSFS_addToSearchPath() now
Ryan C. Gordon <icculus@icculus.org>
parents: 48
diff changeset
   610
    di = buildDirInfo(newDir, 0);
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   611
    BAIL_IF_MACRO_MUTEX(di == NULL, NULL, stateLock, 0);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   612
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   613
    if (appendToPath)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   614
    {
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   615
        di->next = NULL;
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   616
        if (prev == NULL)
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   617
            searchPath = di;
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   618
        else
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   619
            prev->next = di;
23
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   620
    } /* if */
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   621
    else
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   622
    {
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   623
        di->next = searchPath;
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   624
        searchPath = di;
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   625
    } /* else */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   626
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   627
    __PHYSFS_platformReleaseMutex(stateLock);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   628
    return(1);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   629
} /* PHYSFS_addToSearchPath */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   630
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   631
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   632
int PHYSFS_removeFromSearchPath(const char *oldDir)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   633
{
150
221f15a7cb08 Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
   634
    PhysDirInfo *i;
221f15a7cb08 Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
   635
    PhysDirInfo *prev = NULL;
221f15a7cb08 Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
   636
    PhysDirInfo *next = NULL;
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   637
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   638
    BAIL_IF_MACRO(oldDir == NULL, ERR_INVALID_ARGUMENT, 0);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   639
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   640
    __PHYSFS_platformGrabMutex(stateLock);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   641
    for (i = searchPath; i != NULL; i = i->next)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   642
    {
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   643
        if (strcmp(i->dirName, oldDir) == 0)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   644
        {
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   645
            next = i->next;
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   646
            BAIL_IF_MACRO_MUTEX(!freeDirInfo(i, openReadList), NULL,
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   647
                                stateLock, 0);
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   648
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   649
            if (prev == NULL)
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   650
                searchPath = next;
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   651
            else
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   652
                prev->next = next;
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   653
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   654
            BAIL_MACRO_MUTEX(NULL, stateLock, 1);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   655
        } /* if */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   656
        prev = i;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   657
    } /* for */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   658
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   659
    BAIL_MACRO_MUTEX(ERR_NOT_IN_SEARCH_PATH, stateLock, 0);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   660
} /* PHYSFS_removeFromSearchPath */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   661
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   662
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   663
char **PHYSFS_getSearchPath(void)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   664
{
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   665
    int count = 1;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   666
    int x;
150
221f15a7cb08 Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
   667
    PhysDirInfo *i;
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   668
    char **retval;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   669
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   670
    __PHYSFS_platformGrabMutex(stateLock);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   671
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   672
    for (i = searchPath; i != NULL; i = i->next)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   673
        count++;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   674
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   675
    retval = (char **) malloc(sizeof (char *) * count);
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   676
    BAIL_IF_MACRO_MUTEX(!retval, ERR_OUT_OF_MEMORY, stateLock, NULL);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   677
    count--;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   678
    retval[count] = NULL;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   679
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   680
    for (i = searchPath, x = 0; x < count; i = i->next, x++)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   681
    {
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   682
        retval[x] = (char *) malloc(strlen(i->dirName) + 1);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   683
        if (retval[x] == NULL)  /* this is friggin' ugly. */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   684
        {
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   685
            while (x > 0)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   686
            {
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   687
                x--;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   688
                free(retval[x]);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   689
            } /* while */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   690
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   691
            free(retval);
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   692
            BAIL_MACRO_MUTEX(ERR_OUT_OF_MEMORY, stateLock, NULL);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   693
        } /* if */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   694
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   695
        strcpy(retval[x], i->dirName);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   696
    } /* for */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   697
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   698
    __PHYSFS_platformReleaseMutex(stateLock);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   699
    return(retval);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   700
} /* PHYSFS_getSearchPath */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   701
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   702
101
bd18e17ad6ad Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   703
int PHYSFS_setSaneConfig(const char *organization, const char *appName,
bd18e17ad6ad Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   704
                         const char *archiveExt, int includeCdRoms,
bd18e17ad6ad Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   705
                         int archivesFirst)
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   706
{
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   707
    const char *basedir = PHYSFS_getBaseDir();
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   708
    const char *userdir = PHYSFS_getUserDir();
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   709
    const char *dirsep = PHYSFS_getDirSeparator();
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   710
    char *str;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   711
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   712
    BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   713
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   714
        /* set write dir... */
101
bd18e17ad6ad Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   715
    str = malloc(strlen(userdir) + (strlen(organization) * 2) +
bd18e17ad6ad Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   716
                 (strlen(appName) * 2) + (strlen(dirsep) * 3) + 2);
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   717
    BAIL_IF_MACRO(str == NULL, ERR_OUT_OF_MEMORY, 0);
101
bd18e17ad6ad Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   718
    sprintf(str, "%s.%s%s%s", userdir, organization, dirsep, appName);
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   719
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   720
    if (!PHYSFS_setWriteDir(str))
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   721
    {
122
402ee2bf165c Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
   722
        int no_write = 0;
402ee2bf165c Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
   723
        sprintf(str, ".%s/%s", organization, appName);
103
cb5f60383994 PHYSFS_setSaneConfig() fixes: set write dir correctly, and put it at start
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   724
        if ( (PHYSFS_setWriteDir(userdir)) &&
122
402ee2bf165c Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
   725
             (PHYSFS_mkdir(str)) )
103
cb5f60383994 PHYSFS_setSaneConfig() fixes: set write dir correctly, and put it at start
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   726
        {
122
402ee2bf165c Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
   727
            sprintf(str, "%s.%s%s%s", userdir, organization, dirsep, appName);
402ee2bf165c Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
   728
            if (!PHYSFS_setWriteDir(str))
402ee2bf165c Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
   729
                no_write = 1;
103
cb5f60383994 PHYSFS_setSaneConfig() fixes: set write dir correctly, and put it at start
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   730
        } /* if */
cb5f60383994 PHYSFS_setSaneConfig() fixes: set write dir correctly, and put it at start
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   731
        else
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   732
        {
122
402ee2bf165c Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
   733
                no_write = 1;
402ee2bf165c Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
   734
        } /* else */
402ee2bf165c Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
   735
402ee2bf165c Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
   736
        if (no_write)
402ee2bf165c Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
   737
        {
402ee2bf165c Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
   738
            PHYSFS_setWriteDir(NULL);   /* just in case. */
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   739
            free(str);
122
402ee2bf165c Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
   740
            BAIL_MACRO(ERR_CANT_SET_WRITE_DIR, 0);
402ee2bf165c Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
   741
        } /* if */
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   742
    } /* if */
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   743
103
cb5f60383994 PHYSFS_setSaneConfig() fixes: set write dir correctly, and put it at start
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   744
    /* Put write dir first in search path... */
cb5f60383994 PHYSFS_setSaneConfig() fixes: set write dir correctly, and put it at start
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   745
    PHYSFS_addToSearchPath(str, 0);
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   746
    free(str);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   747
101
bd18e17ad6ad Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   748
        /* Put base path on search path... */
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   749
    PHYSFS_addToSearchPath(basedir, 1);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   750
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   751
        /* handle CD-ROMs... */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   752
    if (includeCdRoms)
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   753
    {
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   754
        char **cds = PHYSFS_getCdRomDirs();
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   755
        char **i;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   756
        for (i = cds; *i != NULL; i++)
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   757
            PHYSFS_addToSearchPath(*i, 1);
101
bd18e17ad6ad Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   758
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   759
        PHYSFS_freeList(cds);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   760
    } /* if */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   761
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   762
        /* Root out archives, and add them to search path... */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   763
    if (archiveExt != NULL)
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   764
    {
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   765
        char **rc = PHYSFS_enumerateFiles("");
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   766
        char **i;
93
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 74
diff changeset
   767
        size_t extlen = strlen(archiveExt);
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   768
        char *ext;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   769
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   770
        for (i = rc; *i != NULL; i++)
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   771
        {
93
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 74
diff changeset
   772
            size_t l = strlen(*i);
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 74
diff changeset
   773
            if ((l > extlen) && ((*i)[l - extlen - 1] == '.'))
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   774
            {
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   775
                ext = (*i) + (l - extlen);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   776
                if (__PHYSFS_platformStricmp(ext, archiveExt) == 0)
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   777
                {
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   778
                    const char *d = PHYSFS_getRealDir(*i);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   779
                    str = malloc(strlen(d) + strlen(dirsep) + l + 1);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   780
                    if (str != NULL)
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   781
                    {
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   782
                        sprintf(str, "%s%s%s", d, dirsep, *i);
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   783
                        PHYSFS_addToSearchPath(str, archivesFirst == 0);
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   784
                        free(str);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   785
                    } /* if */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   786
                } /* if */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   787
            } /* if */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   788
        } /* for */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   789
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   790
        PHYSFS_freeList(rc);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   791
    } /* if */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   792
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   793
    return(1);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   794
} /* PHYSFS_setSaneConfig */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   795
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   796
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   797
void PHYSFS_permitSymbolicLinks(int allow)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   798
{
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   799
    allowSymLinks = allow;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   800
} /* PHYSFS_permitSymbolicLinks */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   801
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   802
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   803
/* string manipulation in C makes my ass itch. */
74
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 66
diff changeset
   804
char * __PHYSFS_convertToDependent(const char *prepend,
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 66
diff changeset
   805
                                              const char *dirName,
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 66
diff changeset
   806
                                              const char *append)
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   807
{
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   808
    const char *dirsep = __PHYSFS_platformDirSeparator;
93
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 74
diff changeset
   809
    size_t sepsize = strlen(dirsep);
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   810
    char *str;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   811
    char *i1;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   812
    char *i2;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   813
    size_t allocSize;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   814
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   815
    while (*dirName == '/')
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   816
        dirName++;
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   817
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   818
    allocSize = strlen(dirName) + 1;
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   819
    if (prepend != NULL)
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   820
        allocSize += strlen(prepend) + sepsize;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   821
    if (append != NULL)
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   822
        allocSize += strlen(append) + sepsize;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   823
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   824
        /* make sure there's enough space if the dir separator is bigger. */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   825
    if (sepsize > 1)
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   826
    {
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   827
        str = (char *) dirName;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   828
        do
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   829
        {
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   830
            str = strchr(str, '/');
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   831
            if (str != NULL)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   832
            {
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   833
                allocSize += (sepsize - 1);
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   834
                str++;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   835
            } /* if */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   836
        } while (str != NULL);
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   837
    } /* if */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   838
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   839
    str = (char *) malloc(allocSize);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   840
    BAIL_IF_MACRO(str == NULL, ERR_OUT_OF_MEMORY, NULL);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   841
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 19
diff changeset
   842
    if (prepend == NULL)
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 19
diff changeset
   843
        *str = '\0';
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 19
diff changeset
   844
    else
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   845
    {
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   846
        strcpy(str, prepend);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   847
        strcat(str, dirsep);
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 19
diff changeset
   848
    } /* else */
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   849
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   850
    for (i1 = (char *) dirName, i2 = str + strlen(str); *i1; i1++, i2++)
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   851
    {
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   852
        if (*i1 == '/')
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   853
        {
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   854
            strcpy(i2, dirsep);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   855
            i2 += sepsize;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   856
        } /* if */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   857
        else
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   858
        {
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   859
            *i2 = *i1;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   860
        } /* else */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   861
    } /* for */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   862
    *i2 = '\0';
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   863
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   864
    if (append)
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   865
    {
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   866
        strcat(str, dirsep);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   867
        strcpy(str, append);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   868
    } /* if */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   869
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   870
    return(str);
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   871
} /* __PHYSFS_convertToDependent */
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   872
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   873
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   874
int __PHYSFS_verifySecurity(DirHandle *h, const char *fname)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   875
{
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   876
    int retval = 1;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   877
    char *start;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   878
    char *end;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   879
    char *str;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   880
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   881
    start = str = malloc(strlen(fname) + 1);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   882
    BAIL_IF_MACRO(str == NULL, ERR_OUT_OF_MEMORY, 0);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   883
    strcpy(str, fname);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   884
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   885
    while (1)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   886
    {
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   887
        end = strchr(start, '/');
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   888
        if (end != NULL)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   889
            *end = '\0';
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   890
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   891
        if ( (strcmp(start, ".") == 0) ||
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   892
             (strcmp(start, "..") == 0) ||
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 19
diff changeset
   893
             (strchr(start, '\\') != NULL) ||
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   894
             (strchr(start, ':') != NULL) )
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   895
        {
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   896
            __PHYSFS_setError(ERR_INSECURE_FNAME);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   897
            retval = 0;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   898
            break;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   899
        } /* if */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   900
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   901
        if ((!allowSymLinks) && (h->funcs->isSymLink(h, str)))
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   902
        {
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   903
            __PHYSFS_setError(ERR_SYMLINK_DISALLOWED);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   904
            retval = 0;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   905
            break;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   906
        } /* if */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   907
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   908
        if (end == NULL)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   909
            break;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   910
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   911
        *end = '/';
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   912
        start = end + 1;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   913
    } /* while */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   914
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   915
    free(str);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   916
    return(retval);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   917
} /* __PHYSFS_verifySecurity */
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   918
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   919
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   920
int PHYSFS_mkdir(const char *dname)
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   921
{
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   922
    DirHandle *h;
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   923
    char *str;
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   924
    char *start;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   925
    char *end;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   926
    int retval = 0;
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   927
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   928
    BAIL_IF_MACRO(dname == NULL, ERR_INVALID_ARGUMENT, 0);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   929
    while (*dname == '/')
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   930
        dname++;
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   931
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   932
    __PHYSFS_platformGrabMutex(stateLock);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   933
    BAIL_IF_MACRO_MUTEX(writeDir == NULL, ERR_NO_WRITE_DIR, stateLock, 0);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   934
    h = writeDir->dirHandle;
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   935
    BAIL_IF_MACRO_MUTEX(!h->funcs->mkdir, ERR_NOT_SUPPORTED, stateLock, 0);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   936
    BAIL_IF_MACRO_MUTEX(!__PHYSFS_verifySecurity(h, dname), NULL, stateLock, 0);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   937
    start = str = malloc(strlen(dname) + 1);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   938
    BAIL_IF_MACRO_MUTEX(str == NULL, ERR_OUT_OF_MEMORY, stateLock, 0);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   939
    strcpy(str, dname);
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   940
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   941
    while (1)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   942
    {
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   943
        end = strchr(start, '/');
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   944
        if (end != NULL)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   945
            *end = '\0';
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   946
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   947
        retval = h->funcs->mkdir(h, str);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   948
        if (!retval)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   949
            break;
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   950
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   951
        if (end == NULL)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   952
            break;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   953
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   954
        *end = '/';
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   955
        start = end + 1;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   956
    } /* while */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   957
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   958
    __PHYSFS_platformReleaseMutex(stateLock);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   959
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   960
    free(str);
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   961
    return(retval);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   962
} /* PHYSFS_mkdir */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   963
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   964
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   965
int PHYSFS_delete(const char *fname)
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   966
{
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   967
    int retval;
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   968
    DirHandle *h;
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   969
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   970
    BAIL_IF_MACRO(fname == NULL, ERR_INVALID_ARGUMENT, 0);
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   971
    while (*fname == '/')
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   972
        fname++;
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   973
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   974
    __PHYSFS_platformGrabMutex(stateLock);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   975
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   976
    BAIL_IF_MACRO_MUTEX(writeDir == NULL, ERR_NO_WRITE_DIR, stateLock, 0);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   977
    h = writeDir->dirHandle;
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   978
    BAIL_IF_MACRO_MUTEX(!h->funcs->remove, ERR_NOT_SUPPORTED, stateLock, 0);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   979
    BAIL_IF_MACRO_MUTEX(!__PHYSFS_verifySecurity(h, fname), NULL, stateLock, 0);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   980
    retval = h->funcs->remove(h, fname);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   981
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   982
    __PHYSFS_platformReleaseMutex(stateLock);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   983
    return(retval);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   984
} /* PHYSFS_delete */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   985
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   986
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   987
const char *PHYSFS_getRealDir(const char *filename)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   988
{
150
221f15a7cb08 Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
   989
    PhysDirInfo *i;
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   990
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   991
    while (*filename == '/')
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   992
        filename++;
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   993
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   994
    __PHYSFS_platformGrabMutex(stateLock);
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   995
    for (i = searchPath; i != NULL; i = i->next)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   996
    {
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   997
        DirHandle *h = i->dirHandle;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   998
        if (__PHYSFS_verifySecurity(h, filename))
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   999
        {
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1000
            if (h->funcs->exists(h, filename))
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
  1001
            {
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
  1002
                __PHYSFS_platformReleaseMutex(stateLock);
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1003
                return(i->dirName);
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
  1004
            } /* if */
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1005
        } /* if */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1006
    } /* for */
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
  1007
    __PHYSFS_platformReleaseMutex(stateLock);
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1008
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1009
    return(NULL);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1010
} /* PHYSFS_getRealDir */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1011
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1012
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1013
static int countList(LinkedStringList *list)
12
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1014
{
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1015
    int retval = 0;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1016
    LinkedStringList *i;
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1017
12
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1018
    for (i = list; i != NULL; i = i->next)
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1019
        retval++;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1020
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1021
    return(retval);
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1022
} /* countList */
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1023
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1024
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1025
static char **convertStringListToPhysFSList(LinkedStringList *finalList)
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1026
{
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1027
    int i;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1028
    LinkedStringList *next = NULL;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1029
    int len = countList(finalList);
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1030
    char **retval = (char **) malloc((len + 1) * sizeof (char *));
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1031
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1032
    if (retval == NULL)
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1033
        __PHYSFS_setError(ERR_OUT_OF_MEMORY);
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1034
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1035
    for (i = 0; i < len; i++)
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1036
    {
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1037
        next = finalList->next;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1038
        if (retval == NULL)
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1039
            free(finalList->str);
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1040
        else
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1041
            retval[i] = finalList->str;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1042
        free(finalList);
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1043
        finalList = next;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1044
    } /* for */
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1045
93
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 74
diff changeset
  1046
    if (retval != NULL)
12
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1047
        retval[i] = NULL;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1048
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1049
    return(retval);
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1050
} /* convertStringListToPhysFSList */
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1051
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1052
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1053
static void insertStringListItem(LinkedStringList **final,
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1054
                                 LinkedStringList *item)
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1055
{
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1056
    LinkedStringList *i;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1057
    LinkedStringList *prev = NULL;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1058
    int rc;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1059
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1060
    for (i = *final; i != NULL; i = i->next)
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1061
    {
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1062
        rc = strcmp(i->str, item->str);
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
  1063
        if (rc > 0)  /* insertion point. */
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
  1064
            break;
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
  1065
        else if (rc == 0)      /* already in list. */
12
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1066
        {
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1067
            free(item->str);
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1068
            free(item);
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1069
            return;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1070
        } /* else if */
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1071
        prev = i;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1072
    } /* for */
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
  1073
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
  1074
        /*
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
  1075
         * If we are here, we are either at the insertion point.
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
  1076
         *  This may be the end of the list, or the list may be empty, too.
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
  1077
         */
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
  1078
    if (prev == NULL)
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
  1079
        *final = item;
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
  1080
    else
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
  1081
        prev->next = item;
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
  1082
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
  1083
    item->next = i;
12
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1084
} /* insertStringListItem */
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1085
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1086
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1087
/* if we run out of memory anywhere in here, we give back what we can. */
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1088
static void interpolateStringLists(LinkedStringList **final,
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1089
                                    LinkedStringList *newList)
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1090
{
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1091
    LinkedStringList *next = NULL;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1092
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1093
    while (newList != NULL)
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1094
    {
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1095
        next = newList->next;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1096
        insertStringListItem(final, newList);
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1097
        newList = next;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1098
    } /* while */
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1099
} /* interpolateStringLists */
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1100
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1101
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1102
char **PHYSFS_enumerateFiles(const char *path)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1103
{
150
221f15a7cb08 Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
  1104
    PhysDirInfo *i;
12
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1105
    char **retval = NULL;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1106
    LinkedStringList *rc;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1107
    LinkedStringList *finalList = NULL;
41
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
  1108
    int omitSymLinks = !allowSymLinks;
12
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1109
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
  1110
    BAIL_IF_MACRO(path == NULL, ERR_INVALID_ARGUMENT, NULL);
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
  1111
    while (*path == '/')
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
  1112
        path++;
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
  1113
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
  1114
    __PHYSFS_platformGrabMutex(stateLock);
12
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1115
    for (i = searchPath; i != NULL; i = i->next)
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1116
    {
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1117
        DirHandle *h = i->dirHandle;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1118
        if (__PHYSFS_verifySecurity(h, path))
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1119
        {
41
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
  1120
            rc = h->funcs->enumerateFiles(h, path, omitSymLinks);
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1121
            interpolateStringLists(&finalList, rc);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1122
        } /* if */
12
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1123
    } /* for */
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
  1124
    __PHYSFS_platformReleaseMutex(stateLock);
12
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1125
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1126
    retval = convertStringListToPhysFSList(finalList);
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
  1127
    return(retval);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1128
} /* PHYSFS_enumerateFiles */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1129
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1130
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1131
int PHYSFS_exists(const char *fname)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1132
{
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
  1133
    BAIL_IF_MACRO(fname == NULL, ERR_INVALID_ARGUMENT, 0);
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
  1134
    while (*fname == '/')
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
  1135
        fname++;
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
  1136
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1137
    return(PHYSFS_getRealDir(fname) != NULL);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1138
} /* PHYSFS_exists */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1139
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1140
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1141
int PHYSFS_isDirectory(const char *fname)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1142
{
150
221f15a7cb08 Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
  1143
    PhysDirInfo *i;
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1144
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
  1145
    BAIL_IF_MACRO(fname == NULL, ERR_INVALID_ARGUMENT, 0);
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
  1146
    while (*fname == '/')
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
  1147
        fname++;
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
  1148
44
534901592376 Non-existant archives/directories report a more correct error, and a call
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
  1149
    if (*fname == '\0')
534901592376 Non-existant archives/directories report a more correct error, and a call
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
  1150
        return(1);
534901592376 Non-existant archives/directories report a more correct error, and a call
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
  1151
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
  1152
    __PHYSFS_platformGrabMutex(stateLock);
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1153
    for (i = searchPath; i != NULL; i = i->next)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1154
    {
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1155
        DirHandle *h = i->dirHandle;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1156
        if (__PHYSFS_verifySecurity(h, fname))
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1157
        {
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1158
            if (h->funcs->exists(h, fname))
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
  1159
            {
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
  1160
                int retval = h->funcs->isDirectory(h, fname);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
  1161
                __PHYSFS_platformReleaseMutex(stateLock);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
  1162
                return(retval);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
  1163
            } /* if */
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1164
        } /* if */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1165
    } /* for */
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
  1166
    __PHYSFS_platformReleaseMutex(stateLock);
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1167
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1168
    return(0);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1169
} /* PHYSFS_isDirectory */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1170
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1171
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1172
int PHYSFS_isSymbolicLink(const char *fname)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1173
{
150
221f15a7cb08 Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
  1174
    PhysDirInfo *i;
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1175
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1176
    if (!allowSymLinks)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1177
        return(0);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1178
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@i