extras/physfsrwops.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 26 Sep 2004 13:17:54 +0000
changeset 654 c0ae01de361d
parent 576 5da65f8e9a50
child 767 db29bf06d171
permissions -rw-r--r--
Changed PHYSFS_file to PHYSFS_File to match rest of API's naming convention. This won't break binary compat (function signatures are extern "C" so name mangling doesn't apply), and I've placed a typedef for the old name to support legacy source code.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
123
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/*
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
 * This code provides a glue layer between PhysicsFS and Simple Directmedia
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 *  Layer's (SDL) RWops i/o abstraction.
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
 *
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 * License: this code is public domain. I make no warranty that it is useful,
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
 *  correct, harmless, or environmentally safe.
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
 *
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
 * This particular file may be used however you like, including copying it
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
 *  verbatim into a closed-source project, exploiting it commercially, and
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
 *  removing any trace of my name from the source (although I hope you won't
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
 *  do that). I welcome enhancements and corrections to this file, but I do
576
5da65f8e9a50 Switched to zlib license.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
    12
 *  not require you to send me patches if you make changes. This code has
5da65f8e9a50 Switched to zlib license.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
    13
 *  NO WARRANTY.
123
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
 *
576
5da65f8e9a50 Switched to zlib license.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
    15
 * Unless otherwise stated, the rest of PhysicsFS falls under the zlib license.
5da65f8e9a50 Switched to zlib license.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
    16
 *  Please see LICENSE in the root of the source tree.
123
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
 *
576
5da65f8e9a50 Switched to zlib license.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
    18
 * SDL falls under the LGPL license. You can get SDL at http://www.libsdl.org/
123
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
 *
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
 *  This file was written by Ryan C. Gordon. (icculus@clutteredmind.org).
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
 */
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
#include <stdio.h>  /* used for SEEK_SET, SEEK_CUR, SEEK_END ... */
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
#include "physfsrwops.h"
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence)
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
{
654
c0ae01de361d Changed PHYSFS_file to PHYSFS_File to match rest of API's naming
Ryan C. Gordon <icculus@icculus.org>
parents: 576
diff changeset
    28
    PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
123
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
    int pos = 0;
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
    if (whence == SEEK_SET)
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
    {
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
        pos = offset;
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
    } /* if */
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
    else if (whence == SEEK_CUR)
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
    {
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
    38
        PHYSFS_sint64 current = PHYSFS_tell(handle);
123
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
        if (current == -1)
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
        {
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
            SDL_SetError("Can't find position in file: %s",
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
                          PHYSFS_getLastError());
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
            return(-1);
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
        } /* if */
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
    46
        pos = (int) current;
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
    47
        if ( ((PHYSFS_sint64) pos) != current )
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
    48
        {
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
    49
            SDL_SetError("Can't fit current file position in an int!");
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
    50
            return(-1);
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
    51
        } /* if */
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
    52
123
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
        if (offset == 0)  /* this is a "tell" call. We're done. */
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
    54
            return(pos);
123
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
    56
        pos += offset;
123
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
    } /* else if */
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
    else if (whence == SEEK_END)
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
    {
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
    61
        PHYSFS_sint64 len = PHYSFS_fileLength(handle);
123
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
        if (len == -1)
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
        {
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
            SDL_SetError("Can't find end of file: %s", PHYSFS_getLastError());
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
            return(-1);
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
        } /* if */
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
    68
        pos = (int) len;
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
    69
        if ( ((PHYSFS_sint64) pos) != len )
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
    70
        {
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
    71
            SDL_SetError("Can't fit end-of-file position in an int!");
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
    72
            return(-1);
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
    73
        } /* if */
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
    74
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
    75
        pos += offset;
123
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
    } /* else if */
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
    else
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
    {
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
        SDL_SetError("Invalid 'whence' parameter.");
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
        return(-1);
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
    } /* else */
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
    84
    if ( pos < 0 )
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
    85
    {
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
    86
        SDL_SetError("Attempt to seek past start of file.");
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
    87
        return(-1);
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
    88
    } /* if */
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
    89
    
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
    90
    if (!PHYSFS_seek(handle, (PHYSFS_uint64) pos))
123
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
    {
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
        SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
        return(-1);
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
    } /* if */
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
    return(pos);
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
} /* physfsrwops_seek */
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
static int physfsrwops_read(SDL_RWops *rw, void *ptr, int size, int maxnum)
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
{
654
c0ae01de361d Changed PHYSFS_file to PHYSFS_File to match rest of API's naming
Ryan C. Gordon <icculus@icculus.org>
parents: 576
diff changeset
   102
    PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
   103
    PHYSFS_sint64 rc = PHYSFS_read(handle, ptr, size, maxnum);
123
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
    if (rc != maxnum)
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
    {
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
        if (!PHYSFS_eof(handle)) /* not EOF? Must be an error. */
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
            SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
    } /* if */
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   109
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
   110
    return((int) rc);
123
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
} /* physfsrwops_read */
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
static int physfsrwops_write(SDL_RWops *rw, const void *ptr, int size, int num)
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
{
654
c0ae01de361d Changed PHYSFS_file to PHYSFS_File to match rest of API's naming
Ryan C. Gordon <icculus@icculus.org>
parents: 576
diff changeset
   116
    PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
   117
    PHYSFS_sint64 rc = PHYSFS_write(handle, ptr, size, num);
123
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
    if (rc != num)
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
        SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 123
diff changeset
   121
    return((int) rc);
123
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
} /* physfsrwops_write */
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
static int physfsrwops_close(SDL_RWops *rw)
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
{
654
c0ae01de361d Changed PHYSFS_file to PHYSFS_File to match rest of API's naming
Ryan C. Gordon <icculus@icculus.org>
parents: 576
diff changeset
   127
    PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
123
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
    if (!PHYSFS_close(handle))
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
    {
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
        SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
        return(-1);
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
    } /* if */
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
    SDL_FreeRW(rw);
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
    return(0);
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
} /* physfsrwops_close */
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
654
c0ae01de361d Changed PHYSFS_file to PHYSFS_File to match rest of API's naming
Ryan C. Gordon <icculus@icculus.org>
parents: 576
diff changeset
   139
static SDL_RWops *create_rwops(PHYSFS_File *handle)
123
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
{
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
    SDL_RWops *retval = NULL;
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
    if (handle == NULL)
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
        SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
    else
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
    {
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
        retval = SDL_AllocRW();
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
        if (retval != NULL)
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
        {
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
            retval->seek  = physfsrwops_seek;
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
            retval->read  = physfsrwops_read;
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
            retval->write = physfsrwops_write;
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
            retval->close = physfsrwops_close;
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
            retval->hidden.unknown.data1 = handle;
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
        } /* if */
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
    } /* else */
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
    return(retval);
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
} /* create_rwops */
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
654
c0ae01de361d Changed PHYSFS_file to PHYSFS_File to match rest of API's naming
Ryan C. Gordon <icculus@icculus.org>
parents: 576
diff changeset
   162
SDL_RWops *PHYSFSRWOPS_makeRWops(PHYSFS_File *handle)
123
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
{
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   164
    SDL_RWops *retval = NULL;
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
    if (handle == NULL)
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
        SDL_SetError("NULL pointer passed to PHYSFSRWOPS_makeRWops().");
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
    else
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   168
        retval = create_rwops(handle);
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
    return(retval);
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
} /* PHYSFSRWOPS_makeRWops */
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   174
SDL_RWops *PHYSFSRWOPS_openRead(const char *fname)
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
{
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
    return(create_rwops(PHYSFS_openRead(fname)));
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
} /* PHYSFSRWOPS_openRead */
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   179
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
SDL_RWops *PHYSFSRWOPS_openWrite(const char *fname)
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
{
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
    return(create_rwops(PHYSFS_openWrite(fname)));
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
} /* PHYSFSRWOPS_openWrite */
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
SDL_RWops *PHYSFSRWOPS_openAppend(const char *fname)
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
{
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   188
    return(create_rwops(PHYSFS_openAppend(fname)));
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
} /* PHYSFSRWOPS_openAppend */
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   191
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
/* end of physfsrwops.c ... */
53305c50c541 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193