archivers/grp.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 24 Mar 2002 19:47:33 +0000
changeset 132 b53fa5093749
parent 107 4fd38db4d6ab
child 139 616420dc210c
permissions -rw-r--r--
Added typedefs and platform-specific i/o.
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
107
4fd38db4d6ab Put a FIXME in place.
Ryan C. Gordon <icculus@icculus.org>
parents: 95
diff changeset
    46
/* !!! FIXME: Using the same file handle for all reads is a RACE CONDITION! */
4fd38db4d6ab Put a FIXME in place.
Ryan C. Gordon <icculus@icculus.org>
parents: 95
diff changeset
    47
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
typedef struct
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
{
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
    FILE *handle;
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
    51
    PHYSFS_uint32 totalEntries;
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
} GRPinfo;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
typedef struct
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
{
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
    56
    PHYSFS_uint32 startPos;
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
    57
    PHYSFS_uint32 curPos;
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
    58
    PHYSFS_uint32 size;
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
} GRPfileinfo;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
93
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    62
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
    63
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
    64
                              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
    65
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
    66
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
    67
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
    68
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
    69
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
    70
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
    71
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
    72
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
    73
                                            const char *dirname,
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    74
                                            int omitSymLinks);
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    75
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
    76
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
    77
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
    78
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
    79
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    80
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
    81
{
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    82
    GRP_read,       /* read() method       */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    83
    NULL,           /* write() method      */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    84
    GRP_eof,        /* eof() method        */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    85
    GRP_tell,       /* tell() method       */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    86
    GRP_seek,       /* seek() method       */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    87
    GRP_fileLength, /* fileLength() method */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    88
    GRP_fileClose   /* fileClose() method  */
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
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    92
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
    93
{
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    94
    GRP_isArchive,          /* isArchive() method      */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    95
    GRP_openArchive,        /* openArchive() method    */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    96
    GRP_enumerateFiles,     /* enumerateFiles() method */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    97
    GRP_exists,             /* exists() method         */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    98
    GRP_isDirectory,        /* isDirectory() method    */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    99
    GRP_isSymLink,          /* isSymLink() method      */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   100
    GRP_openRead,           /* openRead() method       */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   101
    NULL,                   /* openWrite() method      */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   102
    NULL,                   /* openAppend() method     */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   103
    NULL,                   /* remove() method         */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   104
    NULL,                   /* mkdir() method          */
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   105
    GRP_dirClose            /* dirClose() method       */
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
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   108
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
   109
{
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   110
    "GRP",
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   111
    "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
   112
    "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
   113
    "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
   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
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   118
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
   119
{
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   120
    fclose( ((GRPinfo *) h->opaque)->handle );
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);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
    FILE *fh = (FILE *) (((GRPinfo *) (handle->dirHandle->opaque))->handle);
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   131
    PHYSFS_uint32 bytesLeft = (finfo->startPos + finfo->size) - finfo->curPos;
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   132
    PHYSFS_uint32 objsLeft = bytesLeft / objSize;
93
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   133
    size_t retval = 0;
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
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
    errno = 0;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
    BAIL_IF_MACRO(fseek(fh,finfo->curPos,SEEK_SET) == -1,strerror(errno),-1);
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
    errno = 0;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
    retval = fread(buffer, objSize, objCount, fh);
26
575e03541d5e Logic fixes; seems to work rather well with KenBuild, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
   143
    finfo->curPos += (retval * objSize);
93
74d1df359be3 Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   144
    BAIL_IF_MACRO((retval < (size_t) objCount) && (ferror(fh)),
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   145
                   strerror(errno), (PHYSFS_sint64) retval);
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   147
    return((PHYSFS_sint64) retval);
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
} /* GRP_read */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
static int GRP_eof(FileHandle *handle)
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
{
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
    GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
    return(finfo->curPos >= finfo->startPos + finfo->size);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
} /* GRP_eof */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   158
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
   159
{
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
    GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
    return(finfo->curPos - finfo->startPos);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
} /* GRP_tell */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   164
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   165
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
   166
{
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
    GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
26
575e03541d5e Logic fixes; seems to work rather well with KenBuild, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
   168
    int newPos = finfo->startPos + offset;
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
    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
   171
    BAIL_IF_MACRO(newPos > finfo->startPos + finfo->size, ERR_PAST_EOF, 0);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
    finfo->curPos = newPos;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
    return(1);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   174
} /* GRP_seek */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   177
static PHYSFS_sint64 GRP_fileLength(FileHandle *handle)
28
529214f57d1b Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents: 26
diff changeset
   178
{
529214f57d1b Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents: 26
diff changeset
   179
    GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
529214f57d1b Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents: 26
diff changeset
   180
    return(finfo->size);
529214f57d1b Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents: 26
diff changeset
   181
} /* GRP_fileLength */
529214f57d1b Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents: 26
diff changeset
   182
529214f57d1b Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents: 26
diff changeset
   183
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
static int GRP_fileClose(FileHandle *handle)
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
{
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
    free(handle->opaque);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
    free(handle);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   188
    return(1);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
} /* GRP_fileClose */
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
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   192
static int openGrp(const char *filename, int forWriting, FILE **fh, PHYSFS_sint32 *count)
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
{
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
    char buf[12];
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
    *fh = NULL;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
    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
   198
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
    errno = 0;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
    *fh = fopen(filename, "rb");
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   201
    BAIL_IF_MACRO(*fh == NULL, strerror(errno), 0);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
    
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
    errno = 0;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
    BAIL_IF_MACRO(fread(buf, 12, 1, *fh) != 1, strerror(errno), 0);
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   205
    BAIL_IF_MACRO(memcmp(buf, "KenSilverman", 12) != 0,
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
                    ERR_UNSUPPORTED_ARCHIVE, 0);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   208
    if (fread(count, sizeof (PHYSFS_sint32), 1, *fh) != 1)
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   209
        *count = 0;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
    return(1);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
} /* openGrp */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
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
   216
{
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217
    FILE *fh;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   218
    int fileCount;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   219
    int retval = openGrp(filename, forWriting, &fh, &fileCount);
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
    if (fh != NULL)
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   222
        fclose(fh);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   223
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   224
    return(retval);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
} /* GRP_isArchive */
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
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   228
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
   229
{
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   230
    FILE *fh;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   231
    int fileCount;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   232
    DirHandle *retval = malloc(sizeof (DirHandle));
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
    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
   235
    retval->opaque = malloc(sizeof (GRPinfo));
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   236
    if (retval->opaque == NULL)
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   237
    {
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   238
        free(retval);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   239
        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
   240
    } /* if */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   241
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   242
    if (!openGrp(name, forWriting, &fh, &fileCount))
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   243
    {
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   244
        if (fh != NULL)
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   245
            fclose(fh);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   246
        free(retval->opaque);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   247
        free(retval);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   248
    } /* if */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   249
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   250
    ((GRPinfo *) retval->opaque)->handle = fh;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   251
    ((GRPinfo *) retval->opaque)->totalEntries = fileCount;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   252
    retval->funcs = &__PHYSFS_DirFunctions_GRP;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   253
    return(retval);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   254
} /* GRP_openArchive */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   255
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   256
41
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   257
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
   258
                                            const char *dirname,
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   259
                                            int omitSymLinks)
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   260
{
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   261
    char buf[16];
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   262
    GRPinfo *g = (GRPinfo *) (h->opaque);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   263
    FILE *fh = g->handle;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   264
    int i;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   265
    LinkedStringList *retval = NULL;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   266
    LinkedStringList *l = NULL;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   267
    LinkedStringList *prev = NULL;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   268
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
   269
    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
   270
        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
   271
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   272
        /* jump to first file entry... */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   273
    errno = 0;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   274
    BAIL_IF_MACRO(fseek(fh, 16, SEEK_SET) == -1, strerror(errno), NULL);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   275
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   276
    for (i = 0; i < g->totalEntries; i++)
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   277
    {
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   278
        errno = 0;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   279
        BAIL_IF_MACRO(fread(buf, 16, 1, fh) != 1, strerror(errno), retval);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   280
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   281
        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
   282
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   283
        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
   284
        if (l == NULL)
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   285
            break;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   286
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   287
        l->str = (char *) malloc(strlen(buf) + 1);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   288
        if (l->str == NULL)
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   289
        {
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   290
            free(l);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   291
            break;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   292
        } /* if */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   293
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
   294
        strcpy(l->str, buf);
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
   295
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   296
        if (retval == NULL)
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   297
            retval = l;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   298
        else
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   299
            prev->next = l;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   300
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   301
        prev = l;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   302
        l->next = NULL;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   303
    } /* for */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   304
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   305
    return(retval);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   306
} /* GRP_enumerateFiles */
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
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   309
static PHYSFS_sint32 getFileEntry(DirHandle *h, const char *name,
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   310
                                  PHYSFS_sint32 *size)
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   311
{
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   312
    char buf[16];
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   313
    GRPinfo *g = (GRPinfo *) (h->opaque);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   314
    FILE *fh = g->handle;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   315
    int i;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   316
    char *ptr;
26
575e03541d5e Logic fixes; seems to work rather well with KenBuild, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
   317
    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
   318
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   319
    /* 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
   320
    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
   321
        return(-1);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   322
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   323
    ptr = strchr(name, '.');
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   324
    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
   325
        return(-1);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   326
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   327
    if (strlen(name) > 12)
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   328
        return(-1);
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
        /* jump to first file entry... */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   331
    errno = 0;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   332
    BAIL_IF_MACRO(fseek(fh, 16, SEEK_SET) == -1, strerror(errno), -1);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   333
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   334
    for (i = 0; i < g->totalEntries; i++)
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   335
    {
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   336
        PHYSFS_sint32 l = 0;
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   337
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   338
        errno = 0;
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   339
        BAIL_IF_MACRO(fread(buf, 12, 1, fh) != 1, strerror(errno), -1);
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   340
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   341
        errno = 0;
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   342
        BAIL_IF_MACRO(fread(&l, sizeof (l), 1, fh) != 1, strerror(errno), -1);
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
        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
   345
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   346
        if (__PHYSFS_platformStricmp(buf, name) == 0)
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
            if (size != NULL)
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   349
                *size = l;
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   350
            return(retval);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   351
        } /* if */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   352
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   353
        retval += l;
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   354
    } /* for */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   355
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   356
    return(-1);  /* not found. */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   357
} /* getFileEntry */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   358
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   359
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   360
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
   361
{
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   362
    return(getFileEntry(h, name, NULL) != -1);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   363
} /* GRP_exists */
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
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   366
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
   367
{
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   368
    return(0);  /* never directories in a groupfile. */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   369
} /* GRP_isDirectory */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   370
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   371
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   372
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
   373
{
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   374
    return(0);  /* never symlinks in a groupfile. */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   375
} /* GRP_isSymLink */
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
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   378
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
   379
{
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   380
    FileHandle *retval;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   381
    GRPfileinfo *finfo;
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   382
    PHYSFS_sint32 size;
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 107
diff changeset
   383
    PHYSFS_sint32 offset;
24
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   384
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   385
    offset = getFileEntry(h, name, &size);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   386
    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
   387
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   388
    retval = (FileHandle *) malloc(sizeof (FileHandle));
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   389
    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
   390
    finfo = (GRPfileinfo *) malloc(sizeof (GRPfileinfo));
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   391
    if (finfo == NULL)
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
        free(retval);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   394
        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
   395
    } /* if */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   396
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   397
    finfo->startPos = offset;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   398
    finfo->curPos = offset;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   399
    finfo->size = size;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   400
    retval->opaque = (void *) finfo;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   401
    retval->funcs = &__PHYSFS_FileFunctions_GRP;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   402
    retval->dirHandle = h;
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   403
    return(retval);
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   404
} /* GRP_openRead */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   405
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   406
/* end of grp.c ... */
b050804123a3 Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   407