physfs.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 08 Jul 2001 05:27:05 +0000
changeset 21 b1ea58d70a56
parent 20 efdde0d21521
child 22 49f6101707b4
permissions -rw-r--r--
Archive implementation (Build Groupfiles), other tweaks.
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>
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
#include <assert.h>
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
#include "physfs.h"
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    17
#define __PHYSICSFS_INTERNAL__
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    18
#include "physfs_internal.h"
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    19
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
typedef struct __PHYSFS_ERRMSGTYPE__
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
{
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
    int tid;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
    int errorAvailable;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
    char errorString[80];
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
    struct __PHYSFS_ERRMSGTYPE__ *next;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
} ErrMsg;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
    28
typedef struct __PHYSFS_DIRINFO__
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
{
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
    char *dirName;
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
    31
    DirHandle *dirHandle;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
    32
    struct __PHYSFS_DIRINFO__ *next;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
    33
} DirInfo;
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    35
typedef struct __PHYSFS_FILEHANDLELIST__
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    36
{
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
    37
    PHYSFS_file *handle;
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    38
    struct __PHYSFS_FILEHANDLELIST__ *next;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    39
} FileHandleList;
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    41
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    42
/* The various i/o drivers... */
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    44
#if (defined PHYSFS_SUPPORTS_ZIP)
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    45
extern const PHYSFS_ArchiveInfo   __PHYSFS_ArchiveInfo_ZIP;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    46
extern const DirFunctions         __PHYSFS_DirFunctions_ZIP;
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    47
#endif
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    48
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    49
extern const DirFunctions  __PHYSFS_DirFunctions_DIR;
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    50
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    51
static const PHYSFS_ArchiveInfo *supported_types[] =
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
{
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
#if (defined PHYSFS_SUPPORTS_ZIP)
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    54
    &__PHYSFS_ArchiveInfo_ZIP,
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
#endif
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
21
b1ea58d70a56 Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
    57
#if (defined PHYSFS_SUPPORTS_GRP)
b1ea58d70a56 Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
    58
    &__PHYSFS_ArchiveInfo_GRP,
b1ea58d70a56 Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
    59
#endif
b1ea58d70a56 Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
    60
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
    NULL
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
};
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    64
static const DirFunctions *dirFunctions[] =
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    65
{
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    66
#if (defined PHYSFS_SUPPORTS_ZIP)
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    67
    &__PHYSFS_DirFunctions_ZIP,
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    68
#endif
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    69
21
b1ea58d70a56 Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
    70
#if (defined PHYSFS_SUPPORTS_GRP)
b1ea58d70a56 Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
    71
    &__PHYSFS_DirFunctions_GRP,
b1ea58d70a56 Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
    72
#endif
b1ea58d70a56 Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
    73
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    74
    &__PHYSFS_DirFunctions_DIR,
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    75
    NULL
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    76
};
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    77
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    80
/* General PhysicsFS state ... */
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    81
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    82
static int initialized = 0;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    83
static ErrMsg *errorMessages = NULL;
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
    84
static DirInfo *searchPath = NULL;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
    85
static DirInfo *writeDir = NULL;
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    86
static FileHandleList *openWriteList = NULL;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    87
static FileHandleList *openReadList = NULL;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    88
static char *baseDir = NULL;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    89
static char *userDir = NULL;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    90
static int allowSymLinks = 0;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    91
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    92
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    93
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
    94
/* functions ... */
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
static ErrMsg *findErrorForCurrentThread(void)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
{
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
    ErrMsg *i;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
    int tid;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
    if (errorMessages != NULL)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
    {
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
        tid = __PHYSFS_platformGetThreadID();
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
        for (i = errorMessages; i != NULL; i = i->next)
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
            if (i->tid == tid)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
                return(i);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   109
        } /* for */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
    } /* if */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
    return(NULL);   /* no error available. */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
} /* findErrorForCurrentThread */
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
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   116
void __PHYSFS_setError(const char *str)
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
{
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   118
    ErrMsg *err;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   119
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   120
    if (str == NULL)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   121
        return;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   122
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   123
    err = findErrorForCurrentThread();
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
    if (err == NULL)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
    {
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
        err = (ErrMsg *) malloc(sizeof (ErrMsg));
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
        if (err == NULL)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
            return;   /* uhh...? */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   131
        err->tid = __PHYSFS_platformGetThreadID();
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
        err->next = errorMessages;
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   133
        errorMessages = err;
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
    } /* if */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
    err->errorAvailable = 1;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
    strncpy(err->errorString, str, sizeof (err->errorString));
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
    err->errorString[sizeof (err->errorString) - 1] = '\0';
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   139
} /* __PHYSFS_setError */
5
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
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   142
static void freeErrorMessages(void)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   143
{
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   144
    ErrMsg *i;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   145
    ErrMsg *next;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   146
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   147
    for (i = errorMessages; i != NULL; i = next)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   148
    {
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   149
        next = i;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   150
        free(i);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   151
    } /* for */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   152
} /* freeErrorMessages */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   153
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   154
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
const char *PHYSFS_getLastError(void)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
{
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
    ErrMsg *err = findErrorForCurrentThread();
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
    if ((err == NULL) || (!err->errorAvailable))
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
        return(NULL);
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
    err->errorAvailable = 0;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
    return(err->errorString);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   164
} /* PHYSFS_getLastError */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
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
void PHYSFS_getLinkedVersion(PHYSFS_Version *ver)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   168
{
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
    if (ver != NULL)
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
        ver->major = PHYSFS_VER_MAJOR;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
        ver->minor = PHYSFS_VER_MINOR;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
        ver->patch = PHYSFS_VER_PATCH;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   174
    } /* if */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
} /* PHYSFS_getLinkedVersion */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   178
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
   179
{
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   180
    const DirFunctions **i;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   181
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   182
    for (i = dirFunctions; *i != NULL; i++)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   183
    {
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   184
        if ((*i)->isArchive(d, forWriting))
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   185
            return( (*i)->openArchive(d, forWriting) );
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   186
    } /* for */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   187
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   188
    __PHYSFS_setError(ERR_UNSUPPORTED_ARCHIVE);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   189
    return(NULL);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   190
} /* openDirectory */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   191
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   192
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   193
static DirInfo *buildDirInfo(const char *newDir, int forWriting)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   194
{
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   195
    DirHandle *dirHandle = NULL;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   196
    DirInfo *di = NULL;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   197
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   198
    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
   199
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   200
    dirHandle = openDirectory(newDir, forWriting);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   201
    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
   202
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   203
    di = (DirInfo *) malloc(sizeof (DirInfo));
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   204
    if (di == NULL)
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 19
diff changeset
   205
        dirHandle->funcs->dirClose(dirHandle);
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   206
    BAIL_IF_MACRO(di == NULL, ERR_OUT_OF_MEMORY, 0);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   207
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   208
    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
   209
    if (di->dirName == NULL)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   210
    {
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   211
        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
   212
        dirHandle->funcs->dirClose(dirHandle);
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   213
        __PHYSFS_setError(ERR_OUT_OF_MEMORY);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   214
        return(0);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   215
    } /* if */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   216
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   217
    di->next = NULL;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   218
    di->dirHandle = dirHandle;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   219
    strcpy(di->dirName, newDir);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   220
    return(di);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   221
} /* buildDirInfo */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   222
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   223
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   224
static int freeDirInfo(DirInfo *di, FileHandleList *openList)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   225
{
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   226
    FileHandleList *i;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   227
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   228
    if (di == NULL)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   229
        return(1);
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
    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
   232
    {
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   233
        const DirHandle *h = ((FileHandle *) i->handle->opaque)->dirHandle;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   234
        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
   235
    } /* for */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   236
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 19
diff changeset
   237
    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
   238
    free(di->dirName);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   239
    free(di);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   240
    return(1);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   241
} /* freeDirInfo */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   242
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   243
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   244
static char *calculateUserDir(void)
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   245
{
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   246
    char *retval = NULL;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   247
    const char *str = NULL;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   248
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   249
    str = __PHYSFS_platformGetUserDir();
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   250
    if (str != NULL)
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   251
        retval = (char *) str;
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   252
    else
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   253
    {
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   254
        const char *dirsep = PHYSFS_getDirSeparator();
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   255
        const char *uname = __PHYSFS_platformGetUserName();
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   256
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   257
        str = (uname != NULL) ? uname : "default";
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   258
        retval = (char *) malloc(strlen(baseDir) + strlen(str) +
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   259
                                 (strlen(dirsep) * 2) + 6);
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   260
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   261
        if (retval == NULL)
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   262
            __PHYSFS_setError(ERR_OUT_OF_MEMORY);
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   263
        else
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   264
            sprintf(retval, "%s%susers%s%s", baseDir, dirsep, dirsep, str);
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   265
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   266
        if (uname != NULL)
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   267
            free((void *) uname);
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   268
    } /* else */
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   269
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   270
    return(retval);
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   271
} /* calculateUserDir */
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   272
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   273
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   274
static char *calculateBaseDir(const char *argv0)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   275
{
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   276
assert(0); return(NULL);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   277
} /* calculateBaseDir */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   278
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   279
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   280
int PHYSFS_init(const char *argv0)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   281
{
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   282
    BAIL_IF_MACRO(initialized, ERR_IS_INITIALIZED, 0);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   283
    BAIL_IF_MACRO(argv0 == NULL, ERR_INVALID_ARGUMENT, 0);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   284
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   285
    baseDir = calculateBaseDir(argv0);
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   286
    BAIL_IF_MACRO(baseDir == NULL, NULL, 0);
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   287
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   288
    userDir = calculateUserDir();
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   289
    if (userDir == NULL)
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   290
    {
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   291
        free(baseDir);
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   292
        baseDir = NULL;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   293
        return(0);
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   294
    } /* if */
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   295
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   296
    initialized = 1;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   297
    return(1);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   298
} /* PHYSFS_init */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   299
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   300
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   301
static int closeFileHandleList(FileHandleList **list)
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   302
{
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   303
    FileHandleList *i;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   304
    FileHandleList *next = NULL;
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   305
    FileHandle *h;
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   306
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   307
    for (i = *list; i != NULL; i = next)
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   308
    {
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   309
        next = i->next;
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   310
        h = (FileHandle *) (i->handle->opaque);
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 19
diff changeset
   311
        if (!h->funcs->fileClose(i->handle->opaque))
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   312
        {
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   313
            *list = i;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   314
            return(0);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   315
        } /* if */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   316
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   317
        free(i->handle);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   318
        free(i);
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   319
    } /* for */
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   320
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   321
    *list = NULL;
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   322
    return(1);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   323
} /* closeFileHandleList */
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   324
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   325
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   326
static void freeSearchPath(void)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   327
{
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   328
    DirInfo *i;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   329
    DirInfo *next = NULL;
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   330
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   331
    closeFileHandleList(&openReadList);
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   332
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   333
    if (searchPath != NULL)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   334
    {
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   335
        for (i = searchPath; i != NULL; i = next)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   336
        {
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   337
            next = i;
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   338
            freeDirInfo(i, openReadList);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   339
        } /* for */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   340
        searchPath = NULL;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   341
    } /* if */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   342
} /* freeSearchPath */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   343
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   344
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   345
int PHYSFS_deinit(void)
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   346
{
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   347
    BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   348
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   349
    closeFileHandleList(&openWriteList);
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   350
    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
   351
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   352
    freeSearchPath();
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   353
    freeErrorMessages();
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   354
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   355
    if (baseDir != NULL)
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   356
    {
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   357
        free(baseDir);
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   358
        baseDir = NULL;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   359
    } /* if */
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   360
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   361
    if (userDir != NULL)
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   362
    {
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   363
        free(userDir);
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   364
        userDir = NULL;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   365
    } /* if */
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   366
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   367
    allowSymLinks = 0;
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   368
    initialized = 0;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   369
    return(1);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   370
} /* PHYSFS_deinit */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   371
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   372
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   373
const PHYSFS_ArchiveInfo **PHYSFS_supportedArchiveTypes(void)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   374
{
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   375
    return(supported_types);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   376
} /* PHYSFS_supportedArchiveTypes */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   377
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   378
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   379
void PHYSFS_freeList(void *list)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   380
{
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   381
    void **i;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   382
    for (i = (void **) list; *i != NULL; i++)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   383
        free(*i);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   384
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   385
    free(list);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   386
} /* PHYSFS_freeList */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   387
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   388
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   389
const char *PHYSFS_getDirSeparator(void)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   390
{
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   391
    return(__PHYSFS_platformDirSeparator);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   392
} /* PHYSFS_getDirSeparator */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   393
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   394
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   395
char **PHYSFS_getCdRomDirs(void)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   396
{
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   397
    return(__PHYSFS_platformDetectAvailableCDs());
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   398
} /* PHYSFS_getCdRomDirs */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   399
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   400
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   401
const char *PHYSFS_getBaseDir(void)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   402
{
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   403
    return(baseDir);   /* this is calculated in PHYSFS_init()... */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   404
} /* PHYSFS_getBaseDir */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   405
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   406
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   407
const char *PHYSFS_getUserDir(void)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   408
{
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   409
    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
   410
} /* PHYSFS_getUserDir */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   411
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   412
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   413
const char *PHYSFS_getWriteDir(void)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   414
{
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   415
    if (writeDir == NULL)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   416
        return(NULL);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   417
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   418
    return(writeDir->dirName);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   419
} /* PHYSFS_getWriteDir */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   420
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   421
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   422
int PHYSFS_setWriteDir(const char *newDir)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   423
{
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   424
    if (writeDir != NULL)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   425
    {
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   426
        BAIL_IF_MACRO(!freeDirInfo(writeDir, openWriteList), NULL, 0);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   427
        writeDir = NULL;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   428
    } /* if */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   429
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   430
    if (newDir != NULL)
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   431
    {
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   432
        writeDir = buildDirInfo(newDir, 1);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   433
        return(writeDir != NULL);
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   434
    } /* if */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   435
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   436
    return(1);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   437
} /* PHYSFS_setWriteDir */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   438
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   439
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   440
int PHYSFS_addToSearchPath(const char *newDir, int appendToPath)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   441
{
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   442
    DirInfo *di = buildDirInfo(newDir, 0);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   443
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   444
    BAIL_IF_MACRO(di == NULL, NULL, 0);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   445
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   446
    if (appendToPath)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   447
    {
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   448
        di->next = searchPath;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   449
        searchPath = di;
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   450
    } /* if */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   451
    else
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   452
    {
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   453
        DirInfo *i = searchPath;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   454
        DirInfo *prev = NULL;
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   455
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   456
        di->next = NULL;
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   457
        while (i != NULL)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   458
            prev = i;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   459
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   460
        if (prev == NULL)
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   461
            searchPath = di;
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   462
        else
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   463
            prev->next = di;
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   464
    } /* else */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   465
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   466
    return(1);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   467
} /* PHYSFS_addToSearchPath */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   468
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   469
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   470
int PHYSFS_removeFromSearchPath(const char *oldDir)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   471
{
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   472
    DirInfo *i;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   473
    DirInfo *prev = NULL;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   474
    DirInfo *next = NULL;
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   475
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   476
    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
   477
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   478
    for (i = searchPath; i != NULL; i = i->next)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   479
    {
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   480
        if (strcmp(i->dirName, oldDir) == 0)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   481
        {
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   482
            next = i->next;
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   483
            BAIL_IF_MACRO(!freeDirInfo(i, openReadList), NULL, 0);
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   484
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   485
            if (prev == NULL)
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   486
                searchPath = next;
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   487
            else
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   488
                prev->next = next;
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   489
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   490
            return(1);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   491
        } /* if */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   492
        prev = i;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   493
    } /* for */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   494
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   495
    __PHYSFS_setError(ERR_NOT_IN_SEARCH_PATH);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   496
    return(0);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   497
} /* PHYSFS_removeFromSearchPath */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   498
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   499
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   500
char **PHYSFS_getSearchPath(void)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   501
{
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   502
    int count = 1;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   503
    int x;
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   504
    DirInfo *i;
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   505
    char **retval;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   506
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   507
    for (i = searchPath; i != NULL; i = i->next)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   508
        count++;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   509
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   510
    retval = (char **) malloc(sizeof (char *) * count);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   511
    BAIL_IF_MACRO(!retval, ERR_OUT_OF_MEMORY, NULL);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   512
    count--;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   513
    retval[count] = NULL;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   514
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   515
    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
   516
    {
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   517
        retval[x] = (char *) malloc(strlen(i->dirName) + 1);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   518
        if (retval[x] == NULL)  /* this is friggin' ugly. */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   519
        {
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   520
            while (x > 0)
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
                x--;
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   523
                free(retval[x]);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   524
            } /* while */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   525
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   526
            free(retval);
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   527
            __PHYSFS_setError(ERR_OUT_OF_MEMORY);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   528
            return(NULL);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   529
        } /* if */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   530
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   531
        strcpy(retval[x], i->dirName);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   532
    } /* for */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   533
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   534
    return(retval);
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   535
} /* PHYSFS_getSearchPath */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   536
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   537
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   538
int PHYSFS_setSaneConfig(const char *appName, const char *archiveExt,
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   539
                         int includeCdRoms, int archivesFirst)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   540
{
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   541
    const char *basedir = PHYSFS_getBaseDir();
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   542
    const char *userdir = PHYSFS_getUserDir();
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   543
    const char *dirsep = PHYSFS_getDirSeparator();
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   544
    char *str;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   545
    int rc;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   546
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   547
        /* set write dir... */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   548
    str = malloc(strlen(userdir) + (strlen(appName) * 2) +
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   549
                 (strlen(dirsep) * 2) + 2);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   550
    BAIL_IF_MACRO(str == NULL, ERR_OUT_OF_MEMORY, 0);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   551
    sprintf(str, "%s%s.%s", userdir, dirsep, appName);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   552
    rc = PHYSFS_setWriteDir(str);
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   553
    BAIL_IF_MACRO(!rc, NULL, 0);
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   554
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   555
        /* Put write dir related dirs on search path... */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   556
    PHYSFS_addToSearchPath(str, 1);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   557
    PHYSFS_mkdir(appName); /* don't care if this fails. */
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   558
    strcat(str, dirsep);
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   559
    strcat(str, appName);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   560
    PHYSFS_addToSearchPath(str, 1);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   561
    free(str);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   562
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   563
        /* Put base path stuff on search path... */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   564
    PHYSFS_addToSearchPath(basedir, 1);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   565
    str = malloc(strlen(basedir) + (strlen(appName) * 2) +
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   566
                 (strlen(dirsep) * 2) + 2);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   567
    if (str != NULL)
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   568
    {
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   569
        sprintf(str, "%s%s.%s", basedir, dirsep, appName);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   570
        PHYSFS_addToSearchPath(str, 1);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   571
        free(str);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   572
    } /* if */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   573
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   574
        /* handle CD-ROMs... */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   575
    if (includeCdRoms)
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   576
    {
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   577
        char **cds = PHYSFS_getCdRomDirs();
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   578
        char **i;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   579
        for (i = cds; *i != NULL; i++)
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   580
        {
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   581
            PHYSFS_addToSearchPath(*i, 1);
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   582
            str = malloc(strlen(*i) + strlen(appName) + strlen(dirsep) + 1);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   583
            if (str != NULL)
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   584
            {
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   585
                sprintf(str, "%s%s%s", *i, dirsep, appName);
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   586
                PHYSFS_addToSearchPath(str, 1);
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   587
                free(str);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   588
            } /* if */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   589
        } /* for */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   590
        PHYSFS_freeList(cds);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   591
    } /* if */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   592
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   593
        /* Root out archives, and add them to search path... */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   594
    if (archiveExt != NULL)
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   595
    {
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   596
        char **rc = PHYSFS_enumerateFiles("");
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   597
        char **i;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   598
        int extlen = strlen(archiveExt);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   599
        char *ext;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   600
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   601
        for (i = rc; *i != NULL; i++)
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   602
        {
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   603
            int l = strlen(*i);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   604
            if ((l > extlen) && ((*i)[l - extlen - 1] == '.'));
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   605
            {
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   606
                ext = (*i) + (l - extlen);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   607
                if (__PHYSFS_platformStricmp(ext, archiveExt) == 0)
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   608
                {
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   609
                    const char *d = PHYSFS_getRealDir(*i);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   610
                    str = malloc(strlen(d) + strlen(dirsep) + l + 1);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   611
                    if (str != NULL)
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   612
                    {
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   613
                        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
   614
                        PHYSFS_addToSearchPath(str, archivesFirst == 0);
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   615
                        free(str);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   616
                    } /* if */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   617
                } /* if */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   618
            } /* if */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   619
        } /* for */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   620
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   621
        PHYSFS_freeList(rc);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   622
    } /* if */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   623
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   624
    return(1);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   625
} /* PHYSFS_setSaneConfig */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   626
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   627
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   628
void PHYSFS_permitSymbolicLinks(int allow)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   629
{
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   630
    allowSymLinks = allow;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   631
} /* PHYSFS_permitSymbolicLinks */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   632
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   633
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   634
/* string manipulation in C makes my ass itch. */
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 19
diff changeset
   635
char *__PHYSFS_convertToDependent(const char *prepend,
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 19
diff changeset
   636
                                  const char *dirName,
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 19
diff changeset
   637
                                  const char *append)
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   638
{
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   639
    const char *dirsep = PHYSFS_getDirSeparator();
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   640
    int sepsize = strlen(dirsep);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   641
    char *str;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   642
    char *i1;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   643
    char *i2;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   644
    size_t allocSize;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   645
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   646
    allocSize = strlen(dirName) + 1;
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   647
    if (prepend != NULL)
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   648
        allocSize += strlen(prepend) + sepsize;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   649
    if (append != NULL)
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   650
        allocSize += strlen(append) + sepsize;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   651
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   652
        /* 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
   653
    if (sepsize > 1)
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   654
    {
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   655
        str = (char *) dirName;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   656
        do
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   657
        {
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   658
            str = strchr(str, '/');
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   659
            if (str != NULL)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   660
            {
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   661
                allocSize += (sepsize - 1);
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   662
                str++;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   663
            } /* if */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   664
        } while (str != NULL);
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   665
    } /* if */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   666
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   667
    str = (char *) malloc(allocSize);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   668
    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
   669
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 19
diff changeset
   670
    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
   671
        *str = '\0';
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 19
diff changeset
   672
    else
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   673
    {
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   674
        strcpy(str, prepend);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   675
        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
   676
    } /* else */
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   677
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   678
    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
   679
    {
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   680
        if (*i1 == '/')
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   681
        {
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   682
            strcpy(i2, dirsep);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   683
            i2 += sepsize;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   684
        } /* if */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   685
        else
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   686
        {
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   687
            *i2 = *i1;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   688
        } /* else */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   689
    } /* for */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   690
    *i2 = '\0';
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   691
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   692
    if (append)
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   693
    {
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   694
        strcat(str, dirsep);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   695
        strcpy(str, append);
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   696
    } /* if */
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   697
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   698
    return(str);
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   699
} /* __PHYSFS_convertToDependentNotation */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   700
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   701
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   702
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
   703
{
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   704
    int retval = 1;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   705
    char *start;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   706
    char *end;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   707
    char *str;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   708
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   709
    start = str = malloc(strlen(fname) + 1);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   710
    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
   711
    strcpy(str, fname);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   712
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   713
    while (1)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   714
    {
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   715
        end = strchr(start, '/');
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   716
        if (end != NULL)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   717
            *end = '\0';
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   718
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   719
        if ( (strcmp(start, ".") == 0) ||
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   720
             (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
   721
             (strchr(start, '\\') != NULL) ||
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   722
             (strchr(start, ':') != NULL) )
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   723
        {
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   724
            __PHYSFS_setError(ERR_INSECURE_FNAME);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   725
            retval = 0;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   726
            break;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   727
        } /* if */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   728
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   729
        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
   730
        {
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   731
            __PHYSFS_setError(ERR_SYMLINK_DISALLOWED);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   732
            retval = 0;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   733
            break;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   734
        } /* if */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   735
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   736
        if (end == NULL)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   737
            break;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   738
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   739
        *end = '/';
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   740
        start = end + 1;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   741
    } /* while */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   742
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   743
    free(str);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   744
    return(retval);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   745
} /* __PHYSFS_verifySecurity */
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   746
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   747
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   748
int PHYSFS_mkdir(const char *dirName)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   749
{
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   750
    DirHandle *h;
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   751
    char *str;
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   752
    char *start;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   753
    char *end;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   754
    int retval = 0;
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   755
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   756
    BAIL_IF_MACRO(writeDir == NULL, ERR_NO_WRITE_DIR, 0);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   757
    h = writeDir->dirHandle;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   758
    BAIL_IF_MACRO(h->funcs->mkdir == NULL, ERR_NOT_SUPPORTED, 0);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   759
    BAIL_IF_MACRO(!__PHYSFS_verifySecurity(h, dirName), NULL, 0);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   760
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   761
    start = str = malloc(strlen(dirName) + 1);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   762
    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
   763
    strcpy(str, dirName);
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   764
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   765
    while (1)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   766
    {
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   767
        end = strchr(start, '/');
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   768
        if (end != NULL)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   769
            *end = '\0';
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   770
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   771
        retval = h->funcs->mkdir(h, str);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   772
        if (!retval)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   773
            break;
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   774
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   775
        if (end == NULL)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   776
            break;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   777
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   778
        *end = '/';
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   779
        start = end + 1;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   780
    } /* while */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   781
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   782
    free(str);
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   783
    return(retval);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   784
} /* PHYSFS_mkdir */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   785
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   786
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   787
int PHYSFS_delete(const char *fname)
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   788
{
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   789
    DirHandle *h;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   790
    BAIL_IF_MACRO(writeDir == NULL, ERR_NO_WRITE_DIR, 0);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   791
    h = writeDir->dirHandle;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   792
    BAIL_IF_MACRO(h->funcs->remove == NULL, ERR_NOT_SUPPORTED, 0);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   793
    BAIL_IF_MACRO(!__PHYSFS_verifySecurity(h, fname), NULL, 0);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   794
    return(h->funcs->remove(h, fname));
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   795
} /* PHYSFS_delete */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   796
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   797
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   798
const char *PHYSFS_getRealDir(const char *filename)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   799
{
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   800
    DirInfo *i;
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
    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
   803
    {
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   804
        DirHandle *h = i->dirHandle;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   805
        if (__PHYSFS_verifySecurity(h, filename))
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   806
        {
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   807
            if (h->funcs->exists(h, filename))
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   808
                return(i->dirName);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   809
        } /* if */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   810
    } /* for */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   811
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   812
    return(NULL);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   813
} /* PHYSFS_getRealDir */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   814
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   815
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   816
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
   817
{
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   818
    int retval = 0;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   819
    LinkedStringList *i;
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   820
12
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   821
    assert(list != NULL);
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   822
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   823
    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
   824
        retval++;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   825
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   826
    return(retval);
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   827
} /* countList */
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   828
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   829
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   830
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
   831
{
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   832
    int i;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   833
    LinkedStringList *next = NULL;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   834
    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
   835
    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
   836
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   837
    if (retval == NULL)
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   838
        __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
   839
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   840
    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
   841
    {
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   842
        next = finalList->next;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   843
        if (retval == NULL)
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   844
            free(finalList->str);
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   845
        else
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   846
            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
   847
        free(finalList);
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   848
        finalList = next;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   849
    } /* for */
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   850
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   851
    if (retval != NULL);
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   852
        retval[i] = NULL;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   853
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   854
    return(retval);
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   855
} /* convertStringListToPhysFSList */
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   856
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   857
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   858
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
   859
                                 LinkedStringList *item)
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   860
{
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   861
    LinkedStringList *i;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   862
    LinkedStringList *prev = NULL;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   863
    int rc;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   864
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   865
    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
   866
    {
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   867
        rc = strcmp(i->str, item->str);
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   868
        if (rc == 0)      /* already in list. */
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   869
        {
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   870
            free(item->str);
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   871
            free(item);
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   872
            return;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   873
        } /* if */
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   874
        else if (rc > 0)  /* insertion point. */
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   875
        {
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   876
            if (prev == NULL)
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   877
                *final = item;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   878
            else
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   879
                prev->next = item;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   880
            item->next = i;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   881
            return;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   882
        } /* else if */
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   883
        prev = i;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   884
    } /* for */
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   885
} /* insertStringListItem */
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   886
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   887
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   888
/* 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
   889
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
   890
                                    LinkedStringList *newList)
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   891
{
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   892
    LinkedStringList *next = NULL;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   893
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   894
    while (newList != NULL)
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   895
    {
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   896
        next = newList->next;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   897
        insertStringListItem(final, newList);
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   898
        newList = next;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   899
    } /* while */
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   900
} /* interpolateStringLists */
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   901
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   902
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   903
char **PHYSFS_enumerateFiles(const char *path)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   904
{
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   905
    DirInfo *i;
12
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   906
    char **retval = NULL;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   907
    LinkedStringList *rc;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   908
    LinkedStringList *finalList = NULL;
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   909
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   910
    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
   911
    {
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   912
        DirHandle *h = i->dirHandle;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   913
        if (__PHYSFS_verifySecurity(h, path))
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
            rc = h->funcs->enumerateFiles(h, path);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   916
            interpolateStringLists(&finalList, rc);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   917
        } /* if */
12
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   918
    } /* for */
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   919
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   920
    retval = convertStringListToPhysFSList(finalList);
a4041c91d715 Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   921
    return(retval);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   922
} /* PHYSFS_enumerateFiles */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   923
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   924
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   925
int PHYSFS_exists(const char *fname)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   926
{
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   927
    return(PHYSFS_getRealDir(fname) != NULL);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   928
} /* PHYSFS_exists */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   929
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   930
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   931
int PHYSFS_isDirectory(const char *fname)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   932
{
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   933
    DirInfo *i;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   934
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   935
    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
   936
    {
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   937
        DirHandle *h = i->dirHandle;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   938
        if (__PHYSFS_verifySecurity(h, fname))
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   939
        {
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   940
            if (h->funcs->exists(h, fname))
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   941
                return(h->funcs->isDirectory(h, fname));
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   942
        } /* if */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   943
    } /* for */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   944
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   945
    return(0);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   946
} /* PHYSFS_isDirectory */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   947
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   948
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   949
int PHYSFS_isSymbolicLink(const char *fname)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   950
{
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   951
    DirInfo *i;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   952
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   953
    if (!allowSymLinks)
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   954
        return(0);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   955
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   956
    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
   957
    {
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   958
        DirHandle *h = i->dirHandle;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   959
        if (__PHYSFS_verifySecurity(h, fname))
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   960
        {
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   961
            if (h->funcs->exists(h, fname))
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   962
                return(h->funcs->isSymLink(h, fname));
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   963
        } /* if */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   964
    } /* for */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   965
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   966
    return(0);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   967
} /* PHYSFS_isSymbolicLink */
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   968
19
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   969
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   970
static PHYSFS_file *doOpenWrite(const char *fname, int appending)
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   971
{
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   972
    PHYSFS_file *retval = (PHYSFS_file *) malloc(sizeof (PHYSFS_file));
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   973
    FileHandle *rc = NULL;
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   974
    DirHandle *h = (writeDir == NULL) ? NULL : writeDir->dirHandle;
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   975
    const DirFunctions *f = (h == NULL) ? NULL : h->funcs;
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   976
    FileHandleList *list;
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   977
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   978
    BAIL_IF_MACRO(!retval, ERR_OUT_OF_MEMORY, NULL);
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   979
    BAIL_IF_MACRO(!h, ERR_NO_WRITE_DIR, NULL);
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   980
    BAIL_IF_MACRO(!__PHYSFS_verifySecurity(h, fname), NULL, NULL);
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   981
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   982
    list = (FileHandleList *) malloc(sizeof (FileHandleList));
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   983
    BAIL_IF_MACRO(!list, ERR_OUT_OF_MEMORY, NULL);
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   984
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   985
    rc = (appending) ? f->openAppend(h, fname) : f->openWrite(h, fname);
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   986
    if (rc == NULL)
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   987
    {
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   988
        free(list);
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   989
        free(retval);
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   990
        retval = NULL;
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   991
    } /* if */
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   992
    else
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   993
    {
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   994
        retval->opaque = (void *) rc;
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   995
        list->handle = retval;
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   996
        list->next = openWriteList;
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   997
        openWriteList = list;
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   998
    } /* else */
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
   999
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1000
    return(retval);
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1001
} /* doOpenWrite */
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1002
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1003
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1004
PHYSFS_file *PHYSFS_openWrite(const char *filename)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1005
{
19
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1006
    return(doOpenWrite(filename, 0));
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1007
} /* PHYSFS_openWrite */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1008
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1009
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1010
PHYSFS_file *PHYSFS_openAppend(const char *filename)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1011
{
19
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1012
    return(doOpenWrite(filename, 1));
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1013
} /* PHYSFS_openAppend */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1014
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1015
19
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1016
PHYSFS_file *PHYSFS_openRead(const char *fname)
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1017
{
19
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1018
    PHYSFS_file *retval = (PHYSFS_file *) malloc(sizeof (PHYSFS_file));
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1019
    FileHandle *rc = NULL;
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1020
    FileHandleList *list;
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1021
    DirInfo *i;
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1022
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1023
    BAIL_IF_MACRO(!retval, ERR_OUT_OF_MEMORY, NULL);
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1024
    list = (FileHandleList *) malloc(sizeof (FileHandleList));
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1025
    BAIL_IF_MACRO(!list, ERR_OUT_OF_MEMORY, NULL);
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1026
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1027
    for (i = searchPath; i != NULL; i = i->next)
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1028
    {
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1029
        DirHandle *h = i->dirHandle;
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1030
        if (__PHYSFS_verifySecurity(h, fname))
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1031
        {
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1032
            rc = h->funcs->openRead(h, fname);
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1033
            if (rc != NULL)
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1034
                break;
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1035
        } /* if */
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1036
    } /* for */
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1037
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1038
    if (rc == NULL)
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1039
    {
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1040
        free(list);
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1041
        free(retval);
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1042
        retval = NULL;
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1043
    } /* if */
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1044
    else
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1045
    {
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1046
        retval->opaque = (void *) rc;
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1047
        list->handle = retval;
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1048
        list->next = openReadList;
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1049
        openReadList = list;
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1050
    } /* else */
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1051
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1052
    return(retval);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1053
} /* PHYSFS_openRead */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1054
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1055
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1056
int PHYSFS_close(PHYSFS_file *handle)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1057
{
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
  1058
    FileHandle *h = (FileHandle *) handle->opaque;
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1059
    FileHandleList *i;
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1060
    FileHandleList *prev;
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1061
    FileHandleList **_lists[] = { &openWriteList, &openReadList, NULL };
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1062
    FileHandleList ***lists = _lists;  /* gay. */
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1063
    int rc;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1064
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1065
    while (lists != NULL)
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1066
    {
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1067
        for (i = *(*lists), prev = NULL; i != NULL; prev = i, i = i->next)
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1068
        {
19
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1069
            if (i->handle == handle)
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1070
            {
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 19
diff changeset
  1071
                rc = h->funcs->fileClose(h);
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1072
                if (!rc)
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1073
                    return(0);
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1074
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1075
                if (prev == NULL)
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1076
                    *(*lists) = i->next;
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1077
                else
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1078
                    prev->next = i->next;
19
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1079
a0279b57398c Base implementation is now complete. Now to fill in archive/platform drivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 15
diff changeset
  1080
                free(handle);
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1081
                free(i);
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1082
                return(1);
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1083
            } /* if */
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1084
        } /* for */
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1085
        lists++;
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1086
    } /* while */
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1087
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1088
    __PHYSFS_setError(ERR_NOT_A_HANDLE);
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1089
    return(0);
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1090
} /* PHYSFS_close */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1091
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1092
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1093
int PHYSFS_read(PHYSFS_file *handle, void *buffer,
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1094
                unsigned int objSize, unsigned int objCount)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1095
{
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
  1096
    FileHandle *h = (FileHandle *) handle->opaque;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
  1097
    assert(h != NULL);
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1098
    assert(h->funcs != NULL);
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1099
    BAIL_IF_MACRO(h->funcs->read == NULL, ERR_NOT_SUPPORTED, -1);
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1100
    return(h->funcs->read(h, buffer, objSize, objCount));
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1101
} /* PHYSFS_read */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1102
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1103
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1104
int PHYSFS_write(PHYSFS_file *handle, void *buffer,
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1105
                 unsigned int objSize, unsigned int objCount)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1106
{
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
  1107
    FileHandle *h = (FileHandle *) handle->opaque;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
  1108
    assert(h != NULL);
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1109
    assert(h->funcs != NULL);
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1110
    BAIL_IF_MACRO(h->funcs->write == NULL, ERR_NOT_SUPPORTED, -1);
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1111
    return(h->funcs->write(h, buffer, objSize, objCount));
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1112
} /* PHYSFS_write */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1113
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1114
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1115
int PHYSFS_eof(PHYSFS_file *handle)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1116
{
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
  1117
    FileHandle *h = (FileHandle *) handle->opaque;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
  1118
    assert(h != NULL);
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1119
    assert(h->funcs != NULL);
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1120
    BAIL_IF_MACRO(h->funcs->eof == NULL, ERR_NOT_SUPPORTED, -1);
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1121
    return(h->funcs->eof(h));
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1122
} /* PHYSFS_eof */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1123
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1124
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1125
int PHYSFS_tell(PHYSFS_file *handle)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1126
{
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
  1127
    FileHandle *h = (FileHandle *) handle->opaque;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
  1128
    assert(h != NULL);
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1129
    assert(h->funcs != NULL);
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1130
    BAIL_IF_MACRO(h->funcs->tell == NULL, ERR_NOT_SUPPORTED, -1);
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1131
    return(h->funcs->tell(h));
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1132
} /* PHYSFS_tell */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1133
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1134
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1135
int PHYSFS_seek(PHYSFS_file *handle, int pos)
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1136
{
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
  1137
    FileHandle *h = (FileHandle *) handle->opaque;
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
  1138
    assert(h != NULL);
11
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1139
    assert(h->funcs != NULL);
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1140
    BAIL_IF_MACRO(h->funcs->seek == NULL, ERR_NOT_SUPPORTED, 0);
677e01f5109e Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
  1141
    return(h->funcs->seek(h, pos));
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1142
} /* PHYSFS_seek */
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1143
15
418eacc97ac8 Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
  1144
7
07d5e6e8259d More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
  1145
/* end of physfs.c ... */
5
055ddaaabf85 Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1146