src/physfs_archiver_dir.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 17 May 2020 01:41:52 -0400
changeset 1691 c66c9326b05d
parent 1620 f3459eaad51b
permissions -rw-r--r--
7z: Make error handling a little more robust.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/*
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
 * Standard directory I/O support routines for PhysicsFS.
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 *
809
116b8fe30371 Renamed LICENSE to LICENSE.txt
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
     4
 * Please see the file LICENSE.txt in the source's root directory.
17
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 *
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
 *  This file written by Ryan C. Gordon.
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
 */
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
#define __PHYSICSFS_INTERNAL__
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
#include "physfs_internal.h"
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
1118
2e09fc635fdd Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 1113
diff changeset
    12
/* There's no PHYSFS_Io interface here. Use __PHYSFS_createNativeIo(). */
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    13
1226
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
    14
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
    15
1424
1114f181e444 Replaced sprintf() calls with snprintf().
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    16
static char *cvtToDependent(const char *prepend, const char *path,
1114f181e444 Replaced sprintf() calls with snprintf().
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    17
                            char *buf, const size_t buflen)
1226
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
    18
{
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1373
diff changeset
    19
    BAIL_IF(buf == NULL, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
1424
1114f181e444 Replaced sprintf() calls with snprintf().
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    20
    snprintf(buf, buflen, "%s%s", prepend ? prepend : "", path);
1226
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
    21
1581
ad04b99afb88 Fixed some warnings that Xcode brought up.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    22
    #if !__PHYSFS_STANDARD_DIRSEP
ad04b99afb88 Fixed some warnings that Xcode brought up.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    23
    assert(__PHYSFS_platformDirSeparator != '/');
1226
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
    24
    {
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
    25
        char *p;
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
    26
        for (p = strchr(buf, '/'); p != NULL; p = strchr(p + 1, '/'))
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
    27
            *p = __PHYSFS_platformDirSeparator;
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
    28
    } /* if */
1581
ad04b99afb88 Fixed some warnings that Xcode brought up.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    29
    #endif
1226
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
    30
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
    31
    return buf;
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
    32
} /* cvtToDependent */
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
    33
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
    34
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
    35
#define CVT_TO_DEPENDENT(buf, pre, dir) { \
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
    36
    const size_t len = ((pre) ? strlen((char *) pre) : 0) + strlen(dir) + 1; \
1424
1114f181e444 Replaced sprintf() calls with snprintf().
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    37
    buf = cvtToDependent((char*)pre,dir,(char*)__PHYSFS_smallAlloc(len),len); \
1226
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
    38
}
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
    39
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
    40
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
    41
1571
fbd9698219c1 Archivers can now specify whether an archive definitely was intended for them.
Ryan C. Gordon <icculus@icculus.org>
parents: 1559
diff changeset
    42
static void *DIR_openArchive(PHYSFS_Io *io, const char *name,
fbd9698219c1 Archivers can now specify whether an archive definitely was intended for them.
Ryan C. Gordon <icculus@icculus.org>
parents: 1559
diff changeset
    43
                             int forWriting, int *claimed)
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    44
{
1240
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1226
diff changeset
    45
    PHYSFS_Stat st;
1225
671d4ea47c13 Make __PHYSFS_platformDirSeparator into a single char.
Ryan C. Gordon <icculus@icculus.org>
parents: 1219
diff changeset
    46
    const char dirsep = __PHYSFS_platformDirSeparator;
648
5c993684b8f2 Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
    47
    char *retval = NULL;
1118
2e09fc635fdd Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 1113
diff changeset
    48
    const size_t namelen = strlen(name);
1225
671d4ea47c13 Make __PHYSFS_platformDirSeparator into a single char.
Ryan C. Gordon <icculus@icculus.org>
parents: 1219
diff changeset
    49
    const size_t seplen = 1;
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    50
1118
2e09fc635fdd Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 1113
diff changeset
    51
    assert(io == NULL);  /* shouldn't create an Io for these. */
1620
f3459eaad51b Fixed mounting a symlink to a real directory.
Ryan C. Gordon <icculus@icculus.org>
parents: 1591
diff changeset
    52
    BAIL_IF_ERRPASS(!__PHYSFS_platformStat(name, &st, 1), NULL);
f3459eaad51b Fixed mounting a symlink to a real directory.
Ryan C. Gordon <icculus@icculus.org>
parents: 1591
diff changeset
    53
1240
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1226
diff changeset
    54
    if (st.filetype != PHYSFS_FILETYPE_DIRECTORY)
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1373
diff changeset
    55
        BAIL(PHYSFS_ERR_UNSUPPORTED, NULL);
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    56
1571
fbd9698219c1 Archivers can now specify whether an archive definitely was intended for them.
Ryan C. Gordon <icculus@icculus.org>
parents: 1559
diff changeset
    57
    *claimed = 1;
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 658
diff changeset
    58
    retval = allocator.Malloc(namelen + seplen + 1);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1373
diff changeset
    59
    BAIL_IF(retval == NULL, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    60
1225
671d4ea47c13 Make __PHYSFS_platformDirSeparator into a single char.
Ryan C. Gordon <icculus@icculus.org>
parents: 1219
diff changeset
    61
    strcpy(retval, name);
671d4ea47c13 Make __PHYSFS_platformDirSeparator into a single char.
Ryan C. Gordon <icculus@icculus.org>
parents: 1219
diff changeset
    62
1118
2e09fc635fdd Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 1113
diff changeset
    63
    /* make sure there's a dir separator at the end of the string */
1225
671d4ea47c13 Make __PHYSFS_platformDirSeparator into a single char.
Ryan C. Gordon <icculus@icculus.org>
parents: 1219
diff changeset
    64
    if (retval[namelen - 1] != dirsep)
671d4ea47c13 Make __PHYSFS_platformDirSeparator into a single char.
Ryan C. Gordon <icculus@icculus.org>
parents: 1219
diff changeset
    65
    {
671d4ea47c13 Make __PHYSFS_platformDirSeparator into a single char.
Ryan C. Gordon <icculus@icculus.org>
parents: 1219
diff changeset
    66
        retval[namelen] = dirsep;
671d4ea47c13 Make __PHYSFS_platformDirSeparator into a single char.
Ryan C. Gordon <icculus@icculus.org>
parents: 1219
diff changeset
    67
        retval[namelen + 1] = '\0';
671d4ea47c13 Make __PHYSFS_platformDirSeparator into a single char.
Ryan C. Gordon <icculus@icculus.org>
parents: 1219
diff changeset
    68
    } /* if */
110
203bd958330d The DirHandle->funcs pointer wasn't getting set?!
Ryan C. Gordon <icculus@icculus.org>
parents: 106
diff changeset
    69
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    70
    return retval;
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    71
} /* DIR_openArchive */
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    72
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    73
1591
97d3641bfba3 Make PHYSFS_EnumerateCallback return an enum instead of an int.
Ryan C. Gordon <icculus@icculus.org>
parents: 1581
diff changeset
    74
static PHYSFS_EnumerateCallbackResult DIR_enumerate(void *opaque,
97d3641bfba3 Make PHYSFS_EnumerateCallback return an enum instead of an int.
Ryan C. Gordon <icculus@icculus.org>
parents: 1581
diff changeset
    75
                         const char *dname, PHYSFS_EnumerateCallback cb,
1559
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1507
diff changeset
    76
                         const char *origdir, void *callbackdata)
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    77
{
1226
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
    78
    char *d;
1591
97d3641bfba3 Make PHYSFS_EnumerateCallback return an enum instead of an int.
Ryan C. Gordon <icculus@icculus.org>
parents: 1581
diff changeset
    79
    PHYSFS_EnumerateCallbackResult retval;
1226
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
    80
    CVT_TO_DEPENDENT(d, opaque, dname);
1591
97d3641bfba3 Make PHYSFS_EnumerateCallback return an enum instead of an int.
Ryan C. Gordon <icculus@icculus.org>
parents: 1581
diff changeset
    81
    BAIL_IF_ERRPASS(!d, PHYSFS_ENUM_ERROR);
1559
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1507
diff changeset
    82
    retval = __PHYSFS_platformEnumerate(d, cb, origdir, callbackdata);
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1507
diff changeset
    83
    __PHYSFS_smallFree(d);
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1507
diff changeset
    84
    return retval;
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1507
diff changeset
    85
} /* DIR_enumerate */
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    86
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    87
1327
998351d485d9 Cleaned out the "exists" nonsense in the stat() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1326
diff changeset
    88
static PHYSFS_Io *doOpen(void *opaque, const char *name, const int mode)
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    89
{
1118
2e09fc635fdd Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 1113
diff changeset
    90
    PHYSFS_Io *io = NULL;
1327
998351d485d9 Cleaned out the "exists" nonsense in the stat() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1326
diff changeset
    91
    char *f = NULL;
1118
2e09fc635fdd Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 1113
diff changeset
    92
1226
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
    93
    CVT_TO_DEPENDENT(f, opaque, name);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1373
diff changeset
    94
    BAIL_IF_ERRPASS(!f, NULL);
1226
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
    95
1118
2e09fc635fdd Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 1113
diff changeset
    96
    io = __PHYSFS_createNativeIo(f, mode);
2e09fc635fdd Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 1113
diff changeset
    97
    if (io == NULL)
467
99664d9842cb Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
    98
    {
1248
632895970ed6 Cleaned up some FIXMEs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1241
diff changeset
    99
        const PHYSFS_ErrorCode err = PHYSFS_getLastErrorCode();
632895970ed6 Cleaned up some FIXMEs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1241
diff changeset
   100
        PHYSFS_Stat statbuf;
1620
f3459eaad51b Fixed mounting a symlink to a real directory.
Ryan C. Gordon <icculus@icculus.org>
parents: 1591
diff changeset
   101
        __PHYSFS_platformStat(f, &statbuf, 0);  /* !!! FIXME: why are we stating here? */
1328
a5314f07614a Remove __PHYSFS_setError(), use the new public API instead.
Ryan C. Gordon <icculus@icculus.org>
parents: 1327
diff changeset
   102
        PHYSFS_setErrorCode(err);
467
99664d9842cb Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   103
    } /* if */
99664d9842cb Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   104
1226
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
   105
    __PHYSFS_smallFree(f);
1219
f479c6b1e7f7 Fixed dereference of free()'d memory.
Ryan C. Gordon <icculus@icculus.org>
parents: 1199
diff changeset
   106
1118
2e09fc635fdd Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 1113
diff changeset
   107
    return io;
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   108
} /* doOpen */
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   109
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   110
1329
919f885155d8 Cleaned out "exists" nonsense in openRead() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1328
diff changeset
   111
static PHYSFS_Io *DIR_openRead(void *opaque, const char *filename)
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   112
{
1327
998351d485d9 Cleaned out the "exists" nonsense in the stat() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1326
diff changeset
   113
    return doOpen(opaque, filename, 'r');
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   114
} /* DIR_openRead */
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   115
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   116
1322
5476917b8ddf Allow application-supplied archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1320
diff changeset
   117
static PHYSFS_Io *DIR_openWrite(void *opaque, const char *filename)
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   118
{
1327
998351d485d9 Cleaned out the "exists" nonsense in the stat() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1326
diff changeset
   119
    return doOpen(opaque, filename, 'w');
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   120
} /* DIR_openWrite */
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   121
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   122
1322
5476917b8ddf Allow application-supplied archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1320
diff changeset
   123
static PHYSFS_Io *DIR_openAppend(void *opaque, const char *filename)
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   124
{
1327
998351d485d9 Cleaned out the "exists" nonsense in the stat() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1326
diff changeset
   125
    return doOpen(opaque, filename, 'a');
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   126
} /* DIR_openAppend */
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   127
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   128
1322
5476917b8ddf Allow application-supplied archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1320
diff changeset
   129
static int DIR_remove(void *opaque, const char *name)
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   130
{
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   131
    int retval;
1226
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
   132
    char *f;
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   133
1226
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
   134
    CVT_TO_DEPENDENT(f, opaque, name);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1373
diff changeset
   135
    BAIL_IF_ERRPASS(!f, 0);
137
66bddb94b6e0 Abstracted file deletion, so we don't rely on C library for it anymore.
Ryan C. Gordon <icculus@icculus.org>
parents: 135
diff changeset
   136
    retval = __PHYSFS_platformDelete(f);
1226
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
   137
    __PHYSFS_smallFree(f);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   138
    return retval;
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   139
} /* DIR_remove */
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   140
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   141
1322
5476917b8ddf Allow application-supplied archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1320
diff changeset
   142
static int DIR_mkdir(void *opaque, const char *name)
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   143
{
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   144
    int retval;
1226
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
   145
    char *f;
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   146
1226
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
   147
    CVT_TO_DEPENDENT(f, opaque, name);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1373
diff changeset
   148
    BAIL_IF_ERRPASS(!f, 0);
69
546a95cc5591 Updates, corrections and enhancements to get this ported to win32.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   149
    retval = __PHYSFS_platformMkDir(f);
1226
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
   150
    __PHYSFS_smallFree(f);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   151
    return retval;
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   152
} /* DIR_mkdir */
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   153
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   154
1322
5476917b8ddf Allow application-supplied archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1320
diff changeset
   155
static void DIR_closeArchive(void *opaque)
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   156
{
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 658
diff changeset
   157
    allocator.Free(opaque);
1270
f8d3f58561b1 Renamed PHYSFS_Archiver::dirClose() to PHYSFS_Archiver::closeArchive().
Ryan C. Gordon <icculus@icculus.org>
parents: 1259
diff changeset
   158
} /* DIR_closeArchive */
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   159
658
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   160
1327
998351d485d9 Cleaned out the "exists" nonsense in the stat() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1326
diff changeset
   161
static int DIR_stat(void *opaque, const char *name, PHYSFS_Stat *stat)
1054
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   162
{
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   163
    int retval = 0;
1226
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
   164
    char *d;
1054
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   165
1226
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
   166
    CVT_TO_DEPENDENT(d, opaque, name);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1373
diff changeset
   167
    BAIL_IF_ERRPASS(!d, 0);
1620
f3459eaad51b Fixed mounting a symlink to a real directory.
Ryan C. Gordon <icculus@icculus.org>
parents: 1591
diff changeset
   168
    retval = __PHYSFS_platformStat(d, stat, 0);
1226
3ea51c799aba Removed __PHYSFS_platformCvtToDependent().
Ryan C. Gordon <icculus@icculus.org>
parents: 1225
diff changeset
   169
    __PHYSFS_smallFree(d);
1054
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   170
    return retval;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   171
} /* DIR_stat */
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   172
658
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   173
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   174
const PHYSFS_Archiver __PHYSFS_Archiver_DIR =
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   175
{
1322
5476917b8ddf Allow application-supplied archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1320
diff changeset
   176
    CURRENT_PHYSFS_ARCHIVER_API_VERSION,
1281
cd136b8d3b1a Moved PHYSFS_ArchiveInfo into PHYSFS_Archiver.
Ryan C. Gordon <icculus@icculus.org>
parents: 1276
diff changeset
   177
    {
cd136b8d3b1a Moved PHYSFS_ArchiveInfo into PHYSFS_Archiver.
Ryan C. Gordon <icculus@icculus.org>
parents: 1276
diff changeset
   178
        "",
cd136b8d3b1a Moved PHYSFS_ArchiveInfo into PHYSFS_Archiver.
Ryan C. Gordon <icculus@icculus.org>
parents: 1276
diff changeset
   179
        "Non-archive, direct filesystem I/O",
cd136b8d3b1a Moved PHYSFS_ArchiveInfo into PHYSFS_Archiver.
Ryan C. Gordon <icculus@icculus.org>
parents: 1276
diff changeset
   180
        "Ryan C. Gordon <icculus@icculus.org>",
1373
527ef3c6a2d6 HTTPS all the things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1331
diff changeset
   181
        "https://icculus.org/physfs/",
1326
ac0fac4fe6d6 Moved supportsSymlinks into PHYSFS_ArchiveInfo.
Ryan C. Gordon <icculus@icculus.org>
parents: 1324
diff changeset
   182
        1,  /* supportsSymlinks */
1281
cd136b8d3b1a Moved PHYSFS_ArchiveInfo into PHYSFS_Archiver.
Ryan C. Gordon <icculus@icculus.org>
parents: 1276
diff changeset
   183
    },
1330
ce6b4a66b3eb Removed comments added by Captain Obvious.
Ryan C. Gordon <icculus@icculus.org>
parents: 1329
diff changeset
   184
    DIR_openArchive,
1559
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1507
diff changeset
   185
    DIR_enumerate,
1330
ce6b4a66b3eb Removed comments added by Captain Obvious.
Ryan C. Gordon <icculus@icculus.org>
parents: 1329
diff changeset
   186
    DIR_openRead,
ce6b4a66b3eb Removed comments added by Captain Obvious.
Ryan C. Gordon <icculus@icculus.org>
parents: 1329
diff changeset
   187
    DIR_openWrite,
ce6b4a66b3eb Removed comments added by Captain Obvious.
Ryan C. Gordon <icculus@icculus.org>
parents: 1329
diff changeset
   188
    DIR_openAppend,
ce6b4a66b3eb Removed comments added by Captain Obvious.
Ryan C. Gordon <icculus@icculus.org>
parents: 1329
diff changeset
   189
    DIR_remove,
ce6b4a66b3eb Removed comments added by Captain Obvious.
Ryan C. Gordon <icculus@icculus.org>
parents: 1329
diff changeset
   190
    DIR_mkdir,
1331
eb06a37afa7e Rearranged PHYSFS_Archiver struct.
Ryan C. Gordon <icculus@icculus.org>
parents: 1330
diff changeset
   191
    DIR_stat,
eb06a37afa7e Rearranged PHYSFS_Archiver struct.
Ryan C. Gordon <icculus@icculus.org>
parents: 1330
diff changeset
   192
    DIR_closeArchive
658
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   193
};
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   194
1507
8953b8a171e7 Update filename comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 1506
diff changeset
   195
/* end of physfs_archiver_dir.c ... */
17
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196