archivers/grp.c
author Ryan C. Gordon <icculus@icculus.org>
Wed, 03 Apr 2002 07:40:27 +0000
changeset 163 fc2b8ee5b420
parent 161 4fcc863fdc5f
child 175 45e423c38ff8
permissions -rw-r--r--
Approved zeph's comments, fixed a few of my screwups.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/*
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
 * GRP support routines for PhysicsFS.
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 *
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
 * This driver handles BUILD engine archives ("groupfiles"). This format
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 *  (but not this driver) was put together by Ken Silverman.
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
 *
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
 * The format is simple enough. In Ken's words:
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
 *
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
 *    What's the .GRP file format?
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
 *
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
 *     The ".grp" file format is just a collection of a lot of files stored
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
 *     into 1 big one. I tried to make the format as simple as possible: The
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
 *     first 12 bytes contains my name, "KenSilverman". The next 4 bytes is
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
 *     the number of files that were compacted into the group file. Then for
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
 *     each file, there is a 16 byte structure, where the first 12 bytes are
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
 *     the filename, and the last 4 bytes are the file's size. The rest of
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
 *     the group file is just the raw data packed one after the other in the
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
 *     same order as the list of files.
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
 *
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
 * (That info is from http://www.advsys.net/ken/build.htm ...)
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
 *
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
 * As it was never a concern in the DOS-based Duke Nukem days, I treat these
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
 *  archives as CASE-INSENSITIVE. Opening "myfile.txt" and "MYFILE.TXT" both
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
 *  work, and get the same file.
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
 *
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
 * Please see the file LICENSE in the source's root directory.
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
 *
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
 *  This file written by Ryan C. Gordon.
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
 */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
#include <stdio.h>
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
#include <stdlib.h>
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
#include <string.h>
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
#include <errno.h>
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
#include <fcntl.h>
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
#include <assert.h>
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
#include "physfs.h"
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
#define __PHYSICSFS_INTERNAL__
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
#include "physfs_internal.h"
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
#if (!defined PHYSFS_SUPPORTS_GRP)
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
#error PHYSFS_SUPPORTS_GRP must be defined.
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
#endif
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
typedef struct
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
{
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
    48
    void *handle;
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
    49
    char *filename;
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
    50
    PHYSFS_uint32 totalEntries;
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
} GRPinfo;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
typedef struct
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
{
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
    55
    void *handle;
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
    56
    PHYSFS_uint64 startPos;
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
    57
    PHYSFS_uint64 size;
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
} GRPfileinfo;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
93
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    61
static void GRP_dirClose(DirHandle *h);
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
    62
static PHYSFS_sint64 GRP_read(FileHandle *handle, void *buffer,
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
    63
                              PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
93
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    64
static int GRP_eof(FileHandle *handle);
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
    65
static PHYSFS_sint64 GRP_tell(FileHandle *handle);
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
    66
static int GRP_seek(FileHandle *handle, PHYSFS_uint64 offset);
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
    67
static PHYSFS_sint64 GRP_fileLength(FileHandle *handle);
93
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    68
static int GRP_fileClose(FileHandle *handle);
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    69
static int GRP_isArchive(const char *filename, int forWriting);
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    70
static DirHandle *GRP_openArchive(const char *name, int forWriting);
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    71
static LinkedStringList *GRP_enumerateFiles(DirHandle *h,
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    72
                                            const char *dirname,
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    73
                                            int omitSymLinks);
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    74
static int GRP_exists(DirHandle *h, const char *name);
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    75
static int GRP_isDirectory(DirHandle *h, const char *name);
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    76
static int GRP_isSymLink(DirHandle *h, const char *name);
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    77
static FileHandle *GRP_openRead(DirHandle *h, const char *name);
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    78
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    79
static const FileFunctions __PHYSFS_FileFunctions_GRP =
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    80
{
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    81
    GRP_read,       /* read() method       */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    82
    NULL,           /* write() method      */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    83
    GRP_eof,        /* eof() method        */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    84
    GRP_tell,       /* tell() method       */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    85
    GRP_seek,       /* seek() method       */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    86
    GRP_fileLength, /* fileLength() method */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    87
    GRP_fileClose   /* fileClose() method  */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    88
};
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    89
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    90
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    91
const DirFunctions __PHYSFS_DirFunctions_GRP =
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    92
{
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    93
    GRP_isArchive,          /* isArchive() method      */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    94
    GRP_openArchive,        /* openArchive() method    */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    95
    GRP_enumerateFiles,     /* enumerateFiles() method */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    96
    GRP_exists,             /* exists() method         */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    97
    GRP_isDirectory,        /* isDirectory() method    */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    98
    GRP_isSymLink,          /* isSymLink() method      */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    99
    GRP_openRead,           /* openRead() method       */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   100
    NULL,                   /* openWrite() method      */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   101
    NULL,                   /* openAppend() method     */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   102
    NULL,                   /* remove() method         */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   103
    NULL,                   /* mkdir() method          */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   104
    GRP_dirClose            /* dirClose() method       */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   105
};
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   106
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   107
const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_GRP =
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   108
{
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   109
    "GRP",
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   110
    "Build engine Groupfile format",
95
215a06fc87eb Changed author credits to wrap email addresses in "<>" and not "()" chars.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   111
    "Ryan C. Gordon <icculus@clutteredmind.org>",
93
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   112
    "http://www.icculus.org/physfs/",
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   113
};
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   114
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   115
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   116
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   117
static void GRP_dirClose(DirHandle *h)
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   118
{
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   119
    __PHYSFS_platformClose( ((GRPinfo *) h->opaque)->handle );
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   120
    free(((GRPinfo *) h->opaque)->filename);
93
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   121
    free(h->opaque);
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   122
    free(h);
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   123
} /* GRP_dirClose */
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   126
static PHYSFS_sint64 GRP_read(FileHandle *handle, void *buffer,
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   127
                              PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
{
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
    GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   130
    void *fh = finfo->handle;
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   131
    PHYSFS_sint64 curPos = __PHYSFS_platformTell(fh);
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   132
    PHYSFS_uint64 bytesLeft = (finfo->startPos + finfo->size) - curPos;
163
fc2b8ee5b420 Approved zeph's comments, fixed a few of my screwups.
Ryan C. Gordon <icculus@icculus.org>
parents: 161
diff changeset
   133
    PHYSFS_uint64 objsLeft = (bytesLeft / objSize);
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
    if (objsLeft < objCount)
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
        objCount = objsLeft;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   138
    return(__PHYSFS_platformRead(fh, buffer, objSize, objCount));
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
} /* GRP_read */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
static int GRP_eof(FileHandle *handle)
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
{
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
    GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   145
    void *fh = finfo->handle;
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   146
    return(__PHYSFS_platformTell(fh) >= finfo->startPos + finfo->size);
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
} /* GRP_eof */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   150
static PHYSFS_sint64 GRP_tell(FileHandle *handle)
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
{
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
    GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   153
    return(__PHYSFS_platformTell(finfo->handle) - finfo->startPos);
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
} /* GRP_tell */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   157
static int GRP_seek(FileHandle *handle, PHYSFS_uint64 offset)
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
{
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
    GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
163
fc2b8ee5b420 Approved zeph's comments, fixed a few of my screwups.
Ryan C. Gordon <icculus@icculus.org>
parents: 161
diff changeset
   160
    PHYSFS_uint64 newPos = (finfo->startPos + offset);
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
    BAIL_IF_MACRO(offset < 0, ERR_INVALID_ARGUMENT, 0);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
    BAIL_IF_MACRO(newPos > finfo->startPos + finfo->size, ERR_PAST_EOF, 0);
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   164
    return(__PHYSFS_platformSeek(finfo->handle, newPos));
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
} /* GRP_seek */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   168
static PHYSFS_sint64 GRP_fileLength(FileHandle *handle)
28
529214f57d1b Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents: 26
diff changeset
   169
{
529214f57d1b Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents: 26
diff changeset
   170
    GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
529214f57d1b Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents: 26
diff changeset
   171
    return(finfo->size);
529214f57d1b Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents: 26
diff changeset
   172
} /* GRP_fileLength */
529214f57d1b Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents: 26
diff changeset
   173
529214f57d1b Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents: 26
diff changeset
   174
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
static int GRP_fileClose(FileHandle *handle)
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
{
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   177
    GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   178
    BAIL_IF_MACRO(__PHYSFS_platformClose(finfo->handle), NULL, 0);
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   179
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
    free(handle->opaque);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
    free(handle);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
    return(1);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
} /* GRP_fileClose */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   186
static int openGrp(const char *filename, int forWriting,
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   187
                    void **fh, PHYSFS_sint32 *count)
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   188
{
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   189
    PHYSFS_uint8 buf[12];
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   191
    *fh = NULL;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
    BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   194
    *fh = __PHYSFS_platformOpenRead(filename);
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   195
    BAIL_IF_MACRO(*fh == NULL, NULL, 0);
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
    
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   197
    if (__PHYSFS_platformRead(*fh, buf, 12, 1) != 1)
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   198
        goto openGrp_failed;
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   200
    if (memcmp(buf, "KenSilverman", 12) != 0)
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   201
    {
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   202
        __PHYSFS_setError(ERR_UNSUPPORTED_ARCHIVE);
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   203
        goto openGrp_failed;
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   204
    } /* if */
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   205
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   206
    if (__PHYSFS_platformRead(*fh, count, sizeof (PHYSFS_sint32), 1) != 1)
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   207
        goto openGrp_failed;
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   209
    return(1);
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   210
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   211
openGrp_failed:
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   212
    if (*fh != NULL)
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   213
        __PHYSFS_platformClose(*fh);
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   214
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   215
    *count = -1;
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   216
    *fh = NULL;
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   217
    return(0);
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   218
} /* openGrp */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   219
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   220
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   221
static int GRP_isArchive(const char *filename, int forWriting)
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   222
{
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   223
    void *fh;
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   224
    int fileCount;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
    int retval = openGrp(filename, forWriting, &fh, &fileCount);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   226
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   227
    if (fh != NULL)
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   228
        __PHYSFS_platformClose(fh);
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   229
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   230
    return(retval);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   231
} /* GRP_isArchive */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   232
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   233
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   234
static DirHandle *GRP_openArchive(const char *name, int forWriting)
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   235
{
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   236
    void *fh = NULL;
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   237
    int fileCount;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   238
    DirHandle *retval = malloc(sizeof (DirHandle));
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   239
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   240
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   241
    retval->opaque = malloc(sizeof (GRPinfo));
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   242
    if (retval->opaque == NULL)
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   243
    {
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   244
        __PHYSFS_setError(ERR_OUT_OF_MEMORY);
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   245
        goto GRP_openArchive_failed;
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   246
    } /* if */
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   247
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   248
    ((GRPinfo *) retval->opaque)->filename = (char *) malloc(strlen(name) + 1);
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   249
    if (((GRPinfo *) retval->opaque)->filename == NULL)
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   250
    {
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   251
        __PHYSFS_setError(ERR_OUT_OF_MEMORY);
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   252
        goto GRP_openArchive_failed;
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   253
    } /* if */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   254
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   255
    if (!openGrp(name, forWriting, &fh, &fileCount))
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   256
        goto GRP_openArchive_failed;
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   257
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   258
    strcpy(((GRPinfo *) retval->opaque)->filename, name);
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   259
    ((GRPinfo *) retval->opaque)->handle = fh;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   260
    ((GRPinfo *) retval->opaque)->totalEntries = fileCount;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   261
    retval->funcs = &__PHYSFS_DirFunctions_GRP;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   262
    return(retval);
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   263
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   264
GRP_openArchive_failed:
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   265
    if (retval != NULL)
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   266
    {
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   267
        if (retval->opaque != NULL)
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   268
        {
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   269
            if ( ((GRPinfo *) retval->opaque)->filename != NULL )
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   270
                free( ((GRPinfo *) retval->opaque)->filename );
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   271
            free(retval->opaque);
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   272
        } /* if */
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   273
        free(retval);
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   274
    } /* if */
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   275
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   276
    if (fh != NULL)
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   277
        __PHYSFS_platformClose(fh);
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   278
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   279
    return(NULL);
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   280
} /* GRP_openArchive */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   281
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   282
41
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   283
static LinkedStringList *GRP_enumerateFiles(DirHandle *h,
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   284
                                            const char *dirname,
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   285
                                            int omitSymLinks)
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   286
{
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   287
    PHYSFS_uint8 buf[16];
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   288
    GRPinfo *g = (GRPinfo *) (h->opaque);
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   289
    void *fh = g->handle;
161
4fcc863fdc5f -Added type casting that Ryan needs to approve.
Gregory S. Read <zeph@clutteredmind.org>
parents: 150
diff changeset
   290
    PHYSFS_uint32 i;
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   291
    LinkedStringList *retval = NULL;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   292
    LinkedStringList *l = NULL;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   293
    LinkedStringList *prev = NULL;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   294
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   295
    /* !!! FIXME: Does this consider "/" ? */
31
41c23ac35615 Fixed GRP_enumerateFiles() so that it will only list files in the root of
Ryan C. Gordon <icculus@icculus.org>
parents: 29
diff changeset
   296
    if (*dirname != '\0')   /* no directories in GRP files. */
41c23ac35615 Fixed GRP_enumerateFiles() so that it will only list files in the root of
Ryan C. Gordon <icculus@icculus.org>
parents: 29
diff changeset
   297
        return(NULL);
41c23ac35615 Fixed GRP_enumerateFiles() so that it will only list files in the root of
Ryan C. Gordon <icculus@icculus.org>
parents: 29
diff changeset
   298
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   299
        /* jump to first file entry... */
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   300
    BAIL_IF_MACRO(!__PHYSFS_platformSeek(fh, 16), NULL, NULL);
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   301
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   302
    for (i = 0; i < g->totalEntries; i++)
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   303
    {
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   304
        BAIL_IF_MACRO(__PHYSFS_platformRead(fh, buf, 16, 1) != 1, NULL, retval);
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   305
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   306
        buf[12] = '\0';  /* FILENAME.EXT is all you get. */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   307
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   308
        l = (LinkedStringList *) malloc(sizeof (LinkedStringList));
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
   309
        if (l == NULL)
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   310
            break;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   311
150
221f15a7cb08 Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents: 139
diff changeset
   312
        l->str = (char *) malloc(strlen((const char *) buf) + 1);
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   313
        if (l->str == NULL)
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   314
        {
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   315
            free(l);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   316
            break;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   317
        } /* if */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   318
150
221f15a7cb08 Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents: 139
diff changeset
   319
        strcpy(l->str, (const char *) buf);
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
   320
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   321
        if (retval == NULL)
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   322
            retval = l;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   323
        else
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   324
            prev->next = l;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   325
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   326
        prev = l;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   327
        l->next = NULL;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   328
    } /* for */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   329
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   330
    return(retval);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   331
} /* GRP_enumerateFiles */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   332
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   333
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   334
static PHYSFS_sint32 getFileEntry(DirHandle *h, const char *name,
150
221f15a7cb08 Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents: 139
diff changeset
   335
                                  PHYSFS_uint32 *size)
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   336
{
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   337
    PHYSFS_uint8 buf[16];
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   338
    GRPinfo *g = (GRPinfo *) (h->opaque);
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   339
    void *fh = g->handle;
161
4fcc863fdc5f -Added type casting that Ryan needs to approve.
Gregory S. Read <zeph@clutteredmind.org>
parents: 150
diff changeset
   340
    PHYSFS_uint32 i;
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   341
    char *ptr;
26
575e03541d5e Logic fixes; seems to work rather well with KenBuild, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
   342
    int retval = (g->totalEntries + 1) * 16; /* offset of raw file data */
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   343
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   344
    /* Rule out filenames to avoid unneeded file i/o... */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   345
    if (strchr(name, '/') != NULL)  /* no directories in groupfiles. */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   346
        return(-1);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   347
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   348
    ptr = strchr(name, '.');
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   349
    if ((ptr) && (strlen(ptr) > 4))   /* 3 char extension at most. */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   350
        return(-1);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   351
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   352
    if (strlen(name) > 12)
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   353
        return(-1);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   354
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   355
    /* jump to first file entry... */
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   356
    BAIL_IF_MACRO(!__PHYSFS_platformSeek(fh, 16), NULL, -1);
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   357
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   358
    for (i = 0; i < g->totalEntries; i++)
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   359
    {
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   360
        PHYSFS_sint32 l = 0;
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   361
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   362
        BAIL_IF_MACRO(__PHYSFS_platformRead(fh, buf, 12, 1) != 1, NULL, -1);
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   363
        BAIL_IF_MACRO(__PHYSFS_platformRead(fh, &l, sizeof (l), 1) != 1, NULL, -1);
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   364
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   365
        buf[12] = '\0';  /* FILENAME.EXT is all you get. */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   366
150
221f15a7cb08 Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents: 139
diff changeset
   367
        if (__PHYSFS_platformStricmp((const char *) buf, name) == 0)
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   368
        {
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   369
            if (size != NULL)
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   370
                *size = l;
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   371
            return(retval);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   372
        } /* if */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   373
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   374
        retval += l;
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   375
    } /* for */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   376
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   377
    return(-1);  /* not found. */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   378
} /* getFileEntry */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   379
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   380
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   381
static int GRP_exists(DirHandle *h, const char *name)
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   382
{
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   383
    return(getFileEntry(h, name, NULL) != -1);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   384
} /* GRP_exists */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   385
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   386
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   387
static int GRP_isDirectory(DirHandle *h, const char *name)
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   388
{
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   389
    return(0);  /* never directories in a groupfile. */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   390
} /* GRP_isDirectory */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   391
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   392
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   393
static int GRP_isSymLink(DirHandle *h, const char *name)
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   394
{
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   395
    return(0);  /* never symlinks in a groupfile. */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   396
} /* GRP_isSymLink */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   397
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   398
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   399
static FileHandle *GRP_openRead(DirHandle *h, const char *name)
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   400
{
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   401
    const char *filename = ((GRPinfo *) h->opaque)->filename;
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   402
    FileHandle *retval;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   403
    GRPfileinfo *finfo;
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   404
    PHYSFS_uint32 size;
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   405
    PHYSFS_sint32 offset;
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   406
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   407
    offset = getFileEntry(h, name, &size);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   408
    BAIL_IF_MACRO(offset == -1, ERR_NO_SUCH_FILE, NULL);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   409
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   410
    retval = (FileHandle *) malloc(sizeof (FileHandle));
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   411
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   412
    finfo = (GRPfileinfo *) malloc(sizeof (GRPfileinfo));
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   413
    if (finfo == NULL)
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   414
    {
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   415
        free(retval);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   416
        BAIL_IF_MACRO(1, ERR_OUT_OF_MEMORY, NULL);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   417
    } /* if */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   418
139
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   419
    finfo->handle = __PHYSFS_platformOpenRead(filename);
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   420
    if ( (finfo->handle == NULL) ||
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   421
         (!__PHYSFS_platformSeek(finfo->handle, offset)) )
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   422
    {
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   423
        free(finfo);
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   424
        free(retval);
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   425
        return(NULL);
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   426
    } /* if */
616420dc210c Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   427
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   428
    finfo->startPos = offset;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   429
    finfo->size = size;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   430
    retval->opaque = (void *) finfo;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   431
    retval->funcs = &__PHYSFS_FileFunctions_GRP;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   432
    retval->dirHandle = h;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   433
    return(retval);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   434
} /* GRP_openRead */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   435
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   436
/* end of grp.c ... */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   437