archivers/qpak.c
author Ryan C. Gordon <icculus@icculus.org>
Mon, 23 Mar 2009 01:43:05 -0400
branchstable-1.0
changeset 966 816a83f04a27
parent 927 8867d6c60ebf
child 1144 a39b2d2f50b9
permissions -rw-r--r--
Updated version to 1.0.2 in configure.in ...
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
581
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/*
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
 * QPAK support routines for PhysicsFS.
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 *
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
 *  This archiver handles the archive format utilized by Quake 1 and 2.
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 *  Quake3-based games use the PkZip/Info-Zip format (which our zip.c
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
 *  archiver handles).
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
 *
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
 *  ========================================================================
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
 *
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
 *  This format info (in more detail) comes from:
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
 *     http://debian.fmi.uni-sofia.bg/~sergei/cgsr/docs/pak.txt
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
 *
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
 *  Quake PAK Format
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
 *
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
 *  Header
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
 *   (4 bytes)  signature = 'PACK'
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
 *   (4 bytes)  directory offset
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
 *   (4 bytes)  directory length
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
 *
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
 *  Directory
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
 *   (56 bytes) file name
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
 *   (4 bytes)  file position
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
 *   (4 bytes)  file length
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
 *
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
 *  ========================================================================
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
 *
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
 * Please see the file LICENSE in the source's root directory.
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
 *
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
 *  This file written by Ryan C. Gordon.
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
 */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
#if HAVE_CONFIG_H
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
#  include <config.h>
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
#endif
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
#if (defined PHYSFS_SUPPORTS_QPAK)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
#include <stdio.h>
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
#include <stdlib.h>
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
#include <string.h>
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
#include "physfs.h"
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
#define __PHYSICSFS_INTERNAL__
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
#include "physfs_internal.h"
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
597
e84664806f86 Made QPAK archiver case insensitive again.
Ryan C. Gordon <icculus@icculus.org>
parents: 589
diff changeset
    46
#if 1  /* Make this case insensitive? */
e84664806f86 Made QPAK archiver case insensitive again.
Ryan C. Gordon <icculus@icculus.org>
parents: 589
diff changeset
    47
#define QPAK_strcmp(x, y) __PHYSFS_platformStricmp(x, y)
e84664806f86 Made QPAK archiver case insensitive again.
Ryan C. Gordon <icculus@icculus.org>
parents: 589
diff changeset
    48
#define QPAK_strncmp(x, y, z) __PHYSFS_platformStrnicmp(x, y, z)
e84664806f86 Made QPAK archiver case insensitive again.
Ryan C. Gordon <icculus@icculus.org>
parents: 589
diff changeset
    49
#else
e84664806f86 Made QPAK archiver case insensitive again.
Ryan C. Gordon <icculus@icculus.org>
parents: 589
diff changeset
    50
#define QPAK_strcmp(x, y) strcmp(x, y)
e84664806f86 Made QPAK archiver case insensitive again.
Ryan C. Gordon <icculus@icculus.org>
parents: 589
diff changeset
    51
#define QPAK_strncmp(x, y, z) strncmp(x, y, z)
e84664806f86 Made QPAK archiver case insensitive again.
Ryan C. Gordon <icculus@icculus.org>
parents: 589
diff changeset
    52
#endif
e84664806f86 Made QPAK archiver case insensitive again.
Ryan C. Gordon <icculus@icculus.org>
parents: 589
diff changeset
    53
e84664806f86 Made QPAK archiver case insensitive again.
Ryan C. Gordon <icculus@icculus.org>
parents: 589
diff changeset
    54
581
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
typedef struct
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
    char name[56];
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
    PHYSFS_uint32 startPos;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
    PHYSFS_uint32 size;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
} QPAKentry;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
typedef struct
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
    char *filename;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
    PHYSFS_sint64 last_mod_time;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
    PHYSFS_uint32 entryCount;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
    QPAKentry *entries;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
} QPAKinfo;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
typedef struct
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
    void *handle;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
    QPAKentry *entry;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
    PHYSFS_uint32 curPos;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
} QPAKfileinfo;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
/* Magic numbers... */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
#define QPAK_SIGNATURE 0x4b434150   /* "PACK" in ASCII. */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
static void QPAK_dirClose(DirHandle *h);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
static PHYSFS_sint64 QPAK_read(FileHandle *handle, void *buffer,
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
                              PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
static PHYSFS_sint64 QPAK_write(FileHandle *handle, const void *buffer,
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
                               PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
static int QPAK_eof(FileHandle *handle);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
static PHYSFS_sint64 QPAK_tell(FileHandle *handle);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
static int QPAK_seek(FileHandle *handle, PHYSFS_uint64 offset);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
static PHYSFS_sint64 QPAK_fileLength(FileHandle *handle);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
static int QPAK_fileClose(FileHandle *handle);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
static int QPAK_isArchive(const char *filename, int forWriting);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
static DirHandle *QPAK_openArchive(const char *name, int forWriting);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
static LinkedStringList *QPAK_enumerateFiles(DirHandle *h,
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
                                            const char *dirname,
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
                                            int omitSymLinks);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
static int QPAK_exists(DirHandle *h, const char *name);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
static int QPAK_isDirectory(DirHandle *h, const char *name, int *fileExists);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
static int QPAK_isSymLink(DirHandle *h, const char *name, int *fileExists);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
static PHYSFS_sint64 QPAK_getLastModTime(DirHandle *h, const char *n, int *e);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
static FileHandle *QPAK_openRead(DirHandle *h, const char *name, int *exist);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
static FileHandle *QPAK_openWrite(DirHandle *h, const char *name);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
static FileHandle *QPAK_openAppend(DirHandle *h, const char *name);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
static int QPAK_remove(DirHandle *h, const char *name);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
static int QPAK_mkdir(DirHandle *h, const char *name);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_QPAK =
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
    "PAK",
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   109
    QPAK_ARCHIVE_DESCRIPTION,
766
3970811e14f4 Changed my email address.
Ryan C. Gordon <icculus@icculus.org>
parents: 597
diff changeset
   110
    "Ryan C. Gordon <icculus@icculus.org>",
581
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
    "http://icculus.org/physfs/",
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
};
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
static const FileFunctions __PHYSFS_FileFunctions_QPAK =
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
    QPAK_read,       /* read() method       */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
    QPAK_write,      /* write() method      */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
    QPAK_eof,        /* eof() method        */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
    QPAK_tell,       /* tell() method       */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
    QPAK_seek,       /* seek() method       */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
    QPAK_fileLength, /* fileLength() method */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
    QPAK_fileClose   /* fileClose() method  */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
};
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
const DirFunctions __PHYSFS_DirFunctions_QPAK =
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
    &__PHYSFS_ArchiveInfo_QPAK,
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
    QPAK_isArchive,          /* isArchive() method      */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
    QPAK_openArchive,        /* openArchive() method    */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
    QPAK_enumerateFiles,     /* enumerateFiles() method */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
    QPAK_exists,             /* exists() method         */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
    QPAK_isDirectory,        /* isDirectory() method    */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
    QPAK_isSymLink,          /* isSymLink() method      */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
    QPAK_getLastModTime,     /* getLastModTime() method */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
    QPAK_openRead,           /* openRead() method       */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
    QPAK_openWrite,          /* openWrite() method      */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
    QPAK_openAppend,         /* openAppend() method     */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
    QPAK_remove,             /* remove() method         */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
    QPAK_mkdir,              /* mkdir() method          */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
    QPAK_dirClose            /* dirClose() method       */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
};
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
static void QPAK_dirClose(DirHandle *h)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
    QPAKinfo *info = ((QPAKinfo *) h->opaque);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
    free(info->filename);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
    free(info->entries);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
    free(info);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
    free(h);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
} /* QPAK_dirClose */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
static PHYSFS_sint64 QPAK_read(FileHandle *handle, void *buffer,
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
                              PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
    QPAKfileinfo *finfo = (QPAKfileinfo *) (handle->opaque);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
    QPAKentry *entry = finfo->entry;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
    PHYSFS_uint32 bytesLeft = entry->size - finfo->curPos;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
    PHYSFS_uint32 objsLeft = (bytesLeft / objSize);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   164
    PHYSFS_sint64 rc;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
    if (objsLeft < objCount)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
        objCount = objsLeft;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   168
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
    rc = __PHYSFS_platformRead(finfo->handle, buffer, objSize, objCount);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
    if (rc > 0)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
        finfo->curPos += (PHYSFS_uint32) (rc * objSize);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
    return(rc);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   174
} /* QPAK_read */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
static PHYSFS_sint64 QPAK_write(FileHandle *handle, const void *buffer,
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
                               PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   179
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
    BAIL_MACRO(ERR_NOT_SUPPORTED, -1);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
} /* QPAK_write */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
static int QPAK_eof(FileHandle *handle)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
    QPAKfileinfo *finfo = (QPAKfileinfo *) (handle->opaque);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
    QPAKentry *entry = finfo->entry;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   188
    return(finfo->curPos >= entry->size);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
} /* QPAK_eof */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   191
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
static PHYSFS_sint64 QPAK_tell(FileHandle *handle)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
    return(((QPAKfileinfo *) (handle->opaque))->curPos);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
} /* QPAK_tell */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
static int QPAK_seek(FileHandle *handle, PHYSFS_uint64 offset)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
    QPAKfileinfo *finfo = (QPAKfileinfo *) (handle->opaque);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   201
    QPAKentry *entry = finfo->entry;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
    int rc;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
    BAIL_IF_MACRO(offset < 0, ERR_INVALID_ARGUMENT, 0);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
    BAIL_IF_MACRO(offset >= entry->size, ERR_PAST_EOF, 0);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
    rc = __PHYSFS_platformSeek(finfo->handle, entry->startPos + offset);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
    if (rc)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
        finfo->curPos = (PHYSFS_uint32) offset;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   209
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
    return(rc);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
} /* QPAK_seek */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
static PHYSFS_sint64 QPAK_fileLength(FileHandle *handle)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   216
    QPAKfileinfo *finfo = ((QPAKfileinfo *) handle->opaque);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217
    return((PHYSFS_sint64) finfo->entry->size);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   218
} /* QPAK_fileLength */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   219
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   220
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   221
static int QPAK_fileClose(FileHandle *handle)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   222
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   223
    QPAKfileinfo *finfo = ((QPAKfileinfo *) handle->opaque);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   224
    BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
    free(finfo);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   226
    free(handle);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   227
    return(1);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   228
} /* QPAK_fileClose */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   229
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   230
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   231
static int qpak_open(const char *filename, int forWriting,
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   232
                    void **fh, PHYSFS_uint32 *count)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   233
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   234
    PHYSFS_uint32 buf;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   235
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   236
    *fh = NULL;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   237
    BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   238
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   239
    *fh = __PHYSFS_platformOpenRead(filename);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   240
    BAIL_IF_MACRO(*fh == NULL, NULL, 0);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   241
    
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   242
    if (__PHYSFS_platformRead(*fh, &buf, sizeof (PHYSFS_uint32), 1) != 1)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   243
        goto openQpak_failed;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   244
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   245
    buf = PHYSFS_swapULE32(buf);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   246
    if (buf != QPAK_SIGNATURE)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   247
    {
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   248
        __PHYSFS_setError(ERR_UNSUPPORTED_ARCHIVE);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   249
        goto openQpak_failed;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   250
    } /* if */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   251
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   252
    if (__PHYSFS_platformRead(*fh, &buf, sizeof (PHYSFS_uint32), 1) != 1)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   253
        goto openQpak_failed;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   254
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   255
    buf = PHYSFS_swapULE32(buf);  /* directory table offset. */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   256
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   257
    if (__PHYSFS_platformRead(*fh, count, sizeof (PHYSFS_uint32), 1) != 1)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   258
        goto openQpak_failed;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   259
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   260
    *count = PHYSFS_swapULE32(*count);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   261
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   262
    if ((*count % 64) != 0)  /* corrupted archive? */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   263
    {
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   264
        __PHYSFS_setError(ERR_CORRUPTED);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   265
        goto openQpak_failed;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   266
    } /* if */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   267
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   268
    if (!__PHYSFS_platformSeek(*fh, buf))
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   269
        goto openQpak_failed;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   270
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   271
    *count /= 64;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   272
    return(1);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   273
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   274
openQpak_failed:
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   275
    if (*fh != NULL)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   276
        __PHYSFS_platformClose(*fh);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   277
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   278
    *count = -1;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   279
    *fh = NULL;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   280
    return(0);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   281
} /* qpak_open */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   282
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   283
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   284
static int QPAK_isArchive(const char *filename, int forWriting)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   285
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   286
    void *fh;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   287
    PHYSFS_uint32 fileCount;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   288
    int retval = qpak_open(filename, forWriting, &fh, &fileCount);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   289
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   290
    if (fh != NULL)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   291
        __PHYSFS_platformClose(fh);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   292
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   293
    return(retval);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   294
} /* QPAK_isArchive */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   295
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   296
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   297
static int qpak_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   298
{
927
8867d6c60ebf Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 766
diff changeset
   299
    if (one != two)
8867d6c60ebf Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 766
diff changeset
   300
    {
8867d6c60ebf Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 766
diff changeset
   301
        const QPAKentry *a = (const QPAKentry *) _a;
8867d6c60ebf Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 766
diff changeset
   302
        return(QPAK_strcmp(a[one].name, a[two].name));
8867d6c60ebf Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 766
diff changeset
   303
    } /* if */
8867d6c60ebf Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 766
diff changeset
   304
8867d6c60ebf Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 766
diff changeset
   305
    return 0;
581
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   306
} /* qpak_entry_cmp */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   307
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   308
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   309
static void qpak_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   310
{
927
8867d6c60ebf Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 766
diff changeset
   311
    if (one != two)
8867d6c60ebf Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 766
diff changeset
   312
    {
8867d6c60ebf Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 766
diff changeset
   313
        QPAKentry tmp;
8867d6c60ebf Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 766
diff changeset
   314
        QPAKentry *first = &(((QPAKentry *) _a)[one]);
8867d6c60ebf Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 766
diff changeset
   315
        QPAKentry *second = &(((QPAKentry *) _a)[two]);
8867d6c60ebf Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 766
diff changeset
   316
        memcpy(&tmp, first, sizeof (QPAKentry));
8867d6c60ebf Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 766
diff changeset
   317
        memcpy(first, second, sizeof (QPAKentry));
8867d6c60ebf Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 766
diff changeset
   318
        memcpy(second, &tmp, sizeof (QPAKentry));
8867d6c60ebf Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 766
diff changeset
   319
    } /* if */
581
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   320
} /* qpak_entry_swap */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   321
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   322
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   323
static int qpak_load_entries(const char *name, int forWriting, QPAKinfo *info)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   324
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   325
    void *fh = NULL;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   326
    PHYSFS_uint32 fileCount;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   327
    QPAKentry *entry;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   328
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   329
    BAIL_IF_MACRO(!qpak_open(name, forWriting, &fh, &fileCount), NULL, 0);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   330
    info->entryCount = fileCount;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   331
    info->entries = (QPAKentry *) malloc(sizeof (QPAKentry) * fileCount);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   332
    if (info->entries == NULL)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   333
    {
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   334
        __PHYSFS_platformClose(fh);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   335
        BAIL_MACRO(ERR_OUT_OF_MEMORY, 0);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   336
    } /* if */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   337
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   338
    for (entry = info->entries; fileCount > 0; fileCount--, entry++)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   339
    {
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   340
        PHYSFS_uint32 loc;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   341
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   342
        if (__PHYSFS_platformRead(fh,&entry->name,sizeof(entry->name),1) != 1)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   343
        {
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   344
            __PHYSFS_platformClose(fh);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   345
            return(0);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   346
        } /* if */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   347
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   348
        if (__PHYSFS_platformRead(fh,&loc,sizeof(loc),1) != 1)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   349
        {
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   350
            __PHYSFS_platformClose(fh);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   351
            return(0);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   352
        } /* if */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   353
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   354
        if (__PHYSFS_platformRead(fh,&entry->size,sizeof(entry->size),1) != 1)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   355
        {
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   356
            __PHYSFS_platformClose(fh);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   357
            return(0);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   358
        } /* if */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   359
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   360
        entry->size = PHYSFS_swapULE32(entry->size);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   361
        entry->startPos = PHYSFS_swapULE32(loc);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   362
    } /* for */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   363
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   364
    __PHYSFS_platformClose(fh);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   365
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   366
    __PHYSFS_sort(info->entries, info->entryCount,
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   367
                  qpak_entry_cmp, qpak_entry_swap);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   368
    return(1);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   369
} /* qpak_load_entries */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   370
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   371
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   372
static DirHandle *QPAK_openArchive(const char *name, int forWriting)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   373
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   374
    QPAKinfo *info;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   375
    DirHandle *retval = malloc(sizeof (DirHandle));
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   376
    PHYSFS_sint64 modtime = __PHYSFS_platformGetLastModTime(name);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   377
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   378
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   379
    info = retval->opaque = malloc(sizeof (QPAKinfo));
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   380
    if (info == NULL)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   381
    {
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   382
        __PHYSFS_setError(ERR_OUT_OF_MEMORY);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   383
        goto QPAK_openArchive_failed;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   384
    } /* if */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   385
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   386
    memset(info, '\0', sizeof (QPAKinfo));
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   387
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   388
    info->filename = (char *) malloc(strlen(name) + 1);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   389
    if (info->filename == NULL)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   390
    {
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   391
        __PHYSFS_setError(ERR_OUT_OF_MEMORY);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   392
        goto QPAK_openArchive_failed;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   393
    } /* if */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   394
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   395
    if (!qpak_load_entries(name, forWriting, info))
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   396
        goto QPAK_openArchive_failed;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   397
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   398
    strcpy(info->filename, name);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   399
    info->last_mod_time = modtime;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   400
    retval->funcs = &__PHYSFS_DirFunctions_QPAK;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   401
    return(retval);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   402
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   403
QPAK_openArchive_failed:
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   404
    if (retval != NULL)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   405
    {
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   406
        if (retval->opaque != NULL)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   407
        {
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   408
            if (info->filename != NULL)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   409
                free(info->filename);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   410
            if (info->entries != NULL)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   411
                free(info->entries);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   412
            free(info);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   413
        } /* if */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   414
        free(retval);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   415
    } /* if */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   416
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   417
    return(NULL);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   418
} /* QPAK_openArchive */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   419
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   420
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   421
static PHYSFS_sint32 qpak_find_start_of_dir(QPAKinfo *info, const char *path,
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   422
                                            int stop_on_first_find)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   423
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   424
    PHYSFS_sint32 lo = 0;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   425
    PHYSFS_sint32 hi = (PHYSFS_sint32) (info->entryCount - 1);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   426
    PHYSFS_sint32 middle;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   427
    PHYSFS_uint32 dlen = strlen(path);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   428
    PHYSFS_sint32 retval = -1;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   429
    const char *name;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   430
    int rc;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   431
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   432
    if (*path == '\0')  /* root dir? */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   433
        return(0);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   434
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   435
    if ((dlen > 0) && (path[dlen - 1] == '/')) /* ignore trailing slash. */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   436
        dlen--;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   437
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   438
    while (lo <= hi)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   439
    {
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   440
        middle = lo + ((hi - lo) / 2);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   441
        name = info->entries[middle].name;
597
e84664806f86 Made QPAK archiver case insensitive again.
Ryan C. Gordon <icculus@icculus.org>
parents: 589
diff changeset
   442
        rc = QPAK_strncmp(path, name, dlen);
581
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   443
        if (rc == 0)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   444
        {
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   445
            char ch = name[dlen];
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   446
            if (ch < '/') /* make sure this isn't just a substr match. */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   447
                rc = -1;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   448
            else if (ch > '/')
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   449
                rc = 1;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   450
            else 
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   451
            {
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   452
                if (stop_on_first_find) /* Just checking dir's existance? */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   453
                    return(middle);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   454
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   455
                if (name[dlen + 1] == '\0') /* Skip initial dir entry. */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   456
                    return(middle + 1);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   457
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   458
                /* there might be more entries earlier in the list. */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   459
                retval = middle;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   460
                hi = middle - 1;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   461
            } /* else */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   462
        } /* if */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   463
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   464
        if (rc > 0)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   465
            lo = middle + 1;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   466
        else
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   467
            hi = middle - 1;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   468
    } /* while */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   469
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   470
    return(retval);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   471
} /* qpak_find_start_of_dir */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   472
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   473
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   474
static LinkedStringList *QPAK_enumerateFiles(DirHandle *h,
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   475
                                             const char *dirname,
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   476
                                             int omitSymLinks)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   477
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   478
    QPAKinfo *info = ((QPAKinfo *) h->opaque);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   479
    LinkedStringList *retval = NULL, *p = NULL;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   480
    PHYSFS_sint32 dlen, dlen_inc, max, i;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   481
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   482
    i = qpak_find_start_of_dir(info, dirname, 0);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   483
    BAIL_IF_MACRO(i == -1, ERR_NO_SUCH_FILE, NULL);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   484
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   485
    dlen = strlen(dirname);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   486
    if ((dlen > 0) && (dirname[dlen - 1] == '/')) /* ignore trailing slash. */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   487
        dlen--;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   488
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   489
    dlen_inc = ((dlen > 0) ? 1 : 0) + dlen;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   490
    max = (PHYSFS_sint32) info->entryCount;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   491
    while (i < max)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   492
    {
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   493
        char *add;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   494
        char *ptr;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   495
        PHYSFS_sint32 ln;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   496
        char *e = info->entries[i].name;
597
e84664806f86 Made QPAK archiver case insensitive again.
Ryan C. Gordon <icculus@icculus.org>
parents: 589
diff changeset
   497
        if ((dlen) && ((QPAK_strncmp(e, dirname, dlen)) || (e[dlen] != '/')))
581
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   498
            break;  /* past end of this dir; we're done. */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   499
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   500
        add = e + dlen_inc;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   501
        ptr = strchr(add, '/');
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   502
        ln = (PHYSFS_sint32) ((ptr) ? ptr-add : strlen(add));
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   503
        retval = __PHYSFS_addToLinkedStringList(retval, &p, add, ln);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   504
        ln += dlen_inc;  /* point past entry to children... */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   505
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   506
        /* increment counter and skip children of subdirs... */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   507
        while ((++i < max) && (ptr != NULL))
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   508
        {
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   509
            char *e_new = info->entries[i].name;
597
e84664806f86 Made QPAK archiver case insensitive again.
Ryan C. Gordon <icculus@icculus.org>
parents: 589
diff changeset
   510
            if ((QPAK_strncmp(e, e_new, ln) != 0) || (e_new[ln] != '/'))
581
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   511
                break;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   512
        } /* while */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   513
    } /* while */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   514
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   515
    return(retval);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   516
} /* QPAK_enumerateFiles */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   517
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   518
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   519
/*
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   520
 * This will find the QPAKentry associated with a path in platform-independent
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   521
 *  notation. Directories don't have QPAKentries associated with them, but 
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   522
 *  (*isDir) will be set to non-zero if a dir was hit.
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   523
 */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   524
static QPAKentry *qpak_find_entry(QPAKinfo *info, const char *path, int *isDir)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   525
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   526
    QPAKentry *a = info->entries;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   527
    PHYSFS_sint32 pathlen = strlen(path);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   528
    PHYSFS_sint32 lo = 0;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   529
    PHYSFS_sint32 hi = (PHYSFS_sint32) (info->entryCount - 1);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   530
    PHYSFS_sint32 middle;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   531
    const char *thispath = NULL;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   532
    int rc;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   533
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   534
    while (lo <= hi)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   535
    {
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   536
        middle = lo + ((hi - lo) / 2);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   537
        thispath = a[middle].name;
597
e84664806f86 Made QPAK archiver case insensitive again.
Ryan C. Gordon <icculus@icculus.org>
parents: 589
diff changeset
   538
        rc = QPAK_strncmp(path, thispath, pathlen);
581
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   539
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   540
        if (rc > 0)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   541
            lo = middle + 1;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   542
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   543
        else if (rc < 0)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   544
            hi = middle - 1;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   545
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   546
        else /* substring match...might be dir or entry or nothing. */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   547
        {
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   548
            if (isDir != NULL)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   549
            {
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   550
                *isDir = (thispath[pathlen] == '/');
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   551
                if (*isDir)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   552
                    return(NULL);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   553
            } /* if */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   554
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   555
            if (thispath[pathlen] == '\0') /* found entry? */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   556
                return(&a[middle]);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   557
            else
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   558
                hi = middle - 1;  /* adjust search params, try again. */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   559
        } /* if */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   560
    } /* while */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   561
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   562
    if (isDir != NULL)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   563
        *isDir = 0;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   564
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   565
    BAIL_MACRO(ERR_NO_SUCH_FILE, NULL);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   566
} /* qpak_find_entry */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   567
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   568
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   569
static int QPAK_exists(DirHandle *h, const char *name)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   570
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   571
    int isDir;    
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   572
    QPAKinfo *info = (QPAKinfo *) h->opaque;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   573
    QPAKentry *entry = qpak_find_entry(info, name, &isDir);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   574
    return((entry != NULL) || (isDir));
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   575
} /* QPAK_exists */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   576
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   577
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   578
static int QPAK_isDirectory(DirHandle *h, const char *name, int *fileExists)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   579
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   580
    QPAKinfo *info = (QPAKinfo *) h->opaque;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   581
    int isDir;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   582
    QPAKentry *entry = qpak_find_entry(info, name, &isDir);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   583
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   584
    *fileExists = ((isDir) || (entry != NULL));
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   585
    if (isDir)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   586
        return(1); /* definitely a dir. */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   587
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   588
    BAIL_MACRO(ERR_NO_SUCH_FILE, 0);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   589
} /* QPAK_isDirectory */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   590
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   591
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   592
static int QPAK_isSymLink(DirHandle *h, const char *name, int *fileExists)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   593
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   594
    *fileExists = QPAK_exists(h, name);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   595
    return(0);  /* never symlinks in a quake pak. */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   596
} /* QPAK_isSymLink */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   597
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   598
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   599
static PHYSFS_sint64 QPAK_getLastModTime(DirHandle *h,
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   600
                                        const char *name,
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   601
                                        int *fileExists)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   602
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   603
    int isDir;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   604
    QPAKinfo *info = ((QPAKinfo *) h->opaque);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   605
    PHYSFS_sint64 retval = -1;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   606
    QPAKentry *entry = qpak_find_entry(info, name, &isDir);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   607
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   608
    *fileExists = ((isDir) || (entry != NULL));
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   609
    if (*fileExists)  /* use time of QPAK itself in the physical filesystem. */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   610
        retval = info->last_mod_time;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   611
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   612
    return(retval);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   613
} /* QPAK_getLastModTime */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   614
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   615
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   616
static FileHandle *QPAK_openRead(DirHandle *h, const char *fnm, int *fileExists)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   617
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   618
    QPAKinfo *info = ((QPAKinfo *) h->opaque);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   619
    FileHandle *retval;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   620
    QPAKfileinfo *finfo;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   621
    QPAKentry *entry;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   622
    int isDir;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   623
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   624
    entry = qpak_find_entry(info, fnm, &isDir);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   625
    *fileExists = ((entry != NULL) || (isDir));
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   626
    BAIL_IF_MACRO(isDir, ERR_NOT_A_FILE, NULL);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   627
    BAIL_IF_MACRO(entry == NULL, ERR_NO_SUCH_FILE, NULL);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   628
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   629
    retval = (FileHandle *) malloc(sizeof (FileHandle));
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   630
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   631
    finfo = (QPAKfileinfo *) malloc(sizeof (QPAKfileinfo));
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   632
    if (finfo == NULL)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   633
    {
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   634
        free(retval);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   635
        BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   636
    } /* if */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   637
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   638
    finfo->handle = __PHYSFS_platformOpenRead(info->filename);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   639
    if ( (finfo->handle == NULL) ||
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   640
         (!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) )
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   641
    {
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   642
        free(finfo);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   643
        free(retval);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   644
        return(NULL);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   645
    } /* if */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   646
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   647
    finfo->curPos = 0;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   648
    finfo->entry = entry;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   649
    retval->opaque = (void *) finfo;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   650
    retval->funcs = &__PHYSFS_FileFunctions_QPAK;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   651
    retval->dirHandle = h;
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   652
    return(retval);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   653
} /* QPAK_openRead */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   654
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   655
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   656
static FileHandle *QPAK_openWrite(DirHandle *h, const char *name)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   657
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   658
    BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   659
} /* QPAK_openWrite */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   660
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   661
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   662
static FileHandle *QPAK_openAppend(DirHandle *h, const char *name)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   663
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   664
    BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   665
} /* QPAK_openAppend */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   666
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   667
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   668
static int QPAK_remove(DirHandle *h, const char *name)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   669
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   670
    BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   671
} /* QPAK_remove */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   672
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   673
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   674
static int QPAK_mkdir(DirHandle *h, const char *name)
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   675
{
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   676
    BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   677
} /* QPAK_mkdir */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   678
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   679
#endif  /* defined PHYSFS_SUPPORTS_QPAK */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   680
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   681
/* end of qpak.c ... */
712fedcbf02c Reimplemented qpak.c for relicensing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   682