misc/libphyslayer/physfsrwops.c
author Wuzzy <almikes@aol.com>
Tue, 10 Oct 2017 02:00:04 +0200
changeset 12680 5a253f158071
parent 11656 227718170097
child 13538 f8c0a62fa3ac
permissions -rw-r--r--
Eliminate some possible spoilers in stats screen of ASA: fruit02
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     1
/*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     2
 * This code provides a glue layer between PhysicsFS and Simple Directmedia
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     3
 *  Layer's (SDL) RWops i/o abstraction.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     4
 *
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     5
 * License: this code is public domain. I make no warranty that it is useful,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     6
 *  correct, harmless, or environmentally safe.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     7
 *
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     8
 * This particular file may be used however you like, including copying it
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     9
 *  verbatim into a closed-source project, exploiting it commercially, and
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    10
 *  removing any trace of my name from the source (although I hope you won't
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    11
 *  do that). I welcome enhancements and corrections to this file, but I do
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    12
 *  not require you to send me patches if you make changes. This code has
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    13
 *  NO WARRANTY.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    14
 *
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    15
 * Unless otherwise stated, the rest of PhysicsFS falls under the zlib license.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    16
 *  Please see LICENSE.txt in the root of the source tree.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    17
 *
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    18
 * SDL 1.2 falls under the LGPL license. SDL 1.3+ is zlib, like PhysicsFS.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    19
 *  You can get SDL at http://www.libsdl.org/
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    20
 *
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    21
 *  This file was written by Ryan C. Gordon. (icculus@icculus.org).
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    22
 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    23
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    24
#include <stdio.h>  /* used for SEEK_SET, SEEK_CUR, SEEK_END ... */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    25
#include "physfsrwops.h"
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    26
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    27
/* SDL's RWOPS interface changed a little in SDL 1.3... */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    28
#if defined(SDL_VERSION_ATLEAST)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    29
#if SDL_VERSION_ATLEAST(1, 3, 0)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    30
#define TARGET_SDL13 1
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    31
#endif
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    32
#endif
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    33
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    34
#if TARGET_SDL13
9378
2be457289e60 update physlayer and sdl bindings to the new rwops interface
koda
parents: 9309
diff changeset
    35
static SDLCALL Sint64 physfsrwops_size(struct SDL_RWops *rw)
2be457289e60 update physlayer and sdl bindings to the new rwops interface
koda
parents: 9309
diff changeset
    36
{
2be457289e60 update physlayer and sdl bindings to the new rwops interface
koda
parents: 9309
diff changeset
    37
    PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
2be457289e60 update physlayer and sdl bindings to the new rwops interface
koda
parents: 9309
diff changeset
    38
    return PHYSFS_fileLength(handle);
2be457289e60 update physlayer and sdl bindings to the new rwops interface
koda
parents: 9309
diff changeset
    39
}
2be457289e60 update physlayer and sdl bindings to the new rwops interface
koda
parents: 9309
diff changeset
    40
#endif
2be457289e60 update physlayer and sdl bindings to the new rwops interface
koda
parents: 9309
diff changeset
    41
2be457289e60 update physlayer and sdl bindings to the new rwops interface
koda
parents: 9309
diff changeset
    42
#if TARGET_SDL13
9309
7e8f91634f80 engine compiles for ios again, but SDL bindings are outdated. Fix some warnings
koda
parents: 8524
diff changeset
    43
static SDLCALL Sint64 physfsrwops_seek(struct SDL_RWops *rw, Sint64 offset, int whence)
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    44
#else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    45
static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    46
#endif
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    47
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    48
    PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    49
    PHYSFS_sint64 pos = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    50
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    51
    if (whence == SEEK_SET)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    52
        pos = (PHYSFS_sint64) offset;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    53
    else if (whence == SEEK_CUR)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    54
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    55
        const PHYSFS_sint64 current = PHYSFS_tell(handle);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    56
        if (current == -1)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    57
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    58
            SDL_SetError("Can't find position in file: %s",
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    59
                          PHYSFS_getLastError());
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    60
            return -1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    61
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    62
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    63
        if (offset == 0)  /* this is a "tell" call. We're done. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    64
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    65
            #if TARGET_SDL13
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    66
            return (long) current;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    67
            #else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    68
            return (int) current;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    69
            #endif
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    70
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    71
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    72
        pos = current + ((PHYSFS_sint64) offset);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    73
    } /* else if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    74
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    75
    else if (whence == SEEK_END)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    76
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    77
        const PHYSFS_sint64 len = PHYSFS_fileLength(handle);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    78
        if (len == -1)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    79
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    80
            SDL_SetError("Can't find end of file: %s", PHYSFS_getLastError());
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    81
            return -1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    82
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    83
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    84
        pos = len + ((PHYSFS_sint64) offset);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    85
    } /* else if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    86
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    87
    else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    88
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    89
        SDL_SetError("Invalid 'whence' parameter.");
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    90
        return -1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    91
    } /* else */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    92
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    93
    if ( pos < 0 )
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    94
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    95
        SDL_SetError("Attempt to seek past start of file.");
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    96
        return -1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    97
    } /* if */
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9378
diff changeset
    98
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    99
    if (!PHYSFS_seek(handle, (PHYSFS_uint64) pos))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   100
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   101
        SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   102
        return -1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   103
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   104
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   105
    #if TARGET_SDL13
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   106
    return (long) pos;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   107
    #else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   108
    return (int) pos;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   109
    #endif
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   110
} /* physfsrwops_seek */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   111
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   112
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   113
#if TARGET_SDL13
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   114
static size_t SDLCALL physfsrwops_read(struct SDL_RWops *rw, void *ptr,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   115
                                       size_t size, size_t maxnum)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   116
#else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   117
static int physfsrwops_read(SDL_RWops *rw, void *ptr, int size, int maxnum)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   118
#endif
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   119
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   120
    PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   121
    const PHYSFS_uint64 readlen = (PHYSFS_uint64) (maxnum * size);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   122
    const PHYSFS_sint64 rc = PHYSFS_readBytes(handle, ptr, readlen);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   123
    if (rc != ((PHYSFS_sint64) readlen))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   124
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   125
        if (!PHYSFS_eof(handle)) /* not EOF? Must be an error. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   126
            SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   127
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   128
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   129
    #if TARGET_SDL13
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   130
    return (size_t) rc;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   131
    #else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   132
    return (int) rc;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   133
    #endif
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   134
} /* physfsrwops_read */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   135
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   136
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   137
#if TARGET_SDL13
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   138
static size_t SDLCALL physfsrwops_write(struct SDL_RWops *rw, const void *ptr,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   139
                                        size_t size, size_t num)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   140
#else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   141
static int physfsrwops_write(SDL_RWops *rw, const void *ptr, int size, int num)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   142
#endif
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   143
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   144
    PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   145
    const PHYSFS_uint64 writelen = (PHYSFS_uint64) (num * size);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   146
    const PHYSFS_sint64 rc = PHYSFS_writeBytes(handle, ptr, writelen);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   147
    if (rc != ((PHYSFS_sint64) writelen))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   148
        SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   149
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   150
    #if TARGET_SDL13
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   151
    return (size_t) rc;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   152
    #else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   153
    return (int) rc;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   154
    #endif
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   155
} /* physfsrwops_write */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   156
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   157
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   158
static int physfsrwops_close(SDL_RWops *rw)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   159
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   160
    PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   161
    if (!PHYSFS_close(handle))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   162
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   163
        SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   164
        return -1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   165
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   166
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   167
    SDL_FreeRW(rw);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   168
    return 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   169
} /* physfsrwops_close */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   170
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   171
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   172
static SDL_RWops *create_rwops(PHYSFS_File *handle)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   173
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   174
    SDL_RWops *retval = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   175
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   176
    if (handle == NULL)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   177
        SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   178
    else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   179
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   180
        retval = SDL_AllocRW();
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   181
        if (retval != NULL)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   182
        {
11656
227718170097 Work around how emscripten defines rwops
koda
parents: 10017
diff changeset
   183
#if TARGET_SDL13 && !defined(EMSCRIPTEN)
9378
2be457289e60 update physlayer and sdl bindings to the new rwops interface
koda
parents: 9309
diff changeset
   184
            retval->size  = physfsrwops_size;
2be457289e60 update physlayer and sdl bindings to the new rwops interface
koda
parents: 9309
diff changeset
   185
#endif
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   186
            retval->seek  = physfsrwops_seek;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   187
            retval->read  = physfsrwops_read;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   188
            retval->write = physfsrwops_write;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   189
            retval->close = physfsrwops_close;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   190
            retval->hidden.unknown.data1 = handle;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   191
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   192
    } /* else */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   193
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   194
    return retval;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   195
} /* create_rwops */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   196
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   197
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   198
SDL_RWops *PHYSFSRWOPS_makeRWops(PHYSFS_File *handle)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   199
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   200
    SDL_RWops *retval = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   201
    if (handle == NULL)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   202
        SDL_SetError("NULL pointer passed to PHYSFSRWOPS_makeRWops().");
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   203
    else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   204
        retval = create_rwops(handle);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   205
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   206
    return retval;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   207
} /* PHYSFSRWOPS_makeRWops */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   208
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   209
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   210
SDL_RWops *PHYSFSRWOPS_openRead(const char *fname)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   211
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   212
    return create_rwops(PHYSFS_openRead(fname));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   213
} /* PHYSFSRWOPS_openRead */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   214
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   215
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   216
SDL_RWops *PHYSFSRWOPS_openWrite(const char *fname)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   217
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   218
    return create_rwops(PHYSFS_openWrite(fname));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   219
} /* PHYSFSRWOPS_openWrite */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   220
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   221
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   222
SDL_RWops *PHYSFSRWOPS_openAppend(const char *fname)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   223
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   224
    return create_rwops(PHYSFS_openAppend(fname));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   225
} /* PHYSFSRWOPS_openAppend */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   226
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   227
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   228
/* end of physfsrwops.c ... */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   229