misc/libphyslayer/physfsrwops.c
author alfadur
Sun, 14 Oct 2018 22:55:07 +0300
changeset 13912 d178a834f1f4
parent 13538 f8c0a62fa3ac
child 13913 f8b5708835de
permissions -rw-r--r--
set proper sdl calling convention for vcpkg builds
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
13912
d178a834f1f4 set proper sdl calling convention for vcpkg builds
alfadur
parents: 13538
diff changeset
    27
#ifdef WIN32_VCPKG
d178a834f1f4 set proper sdl calling convention for vcpkg builds
alfadur
parents: 13538
diff changeset
    28
#define SDLCALL __cdecl
d178a834f1f4 set proper sdl calling convention for vcpkg builds
alfadur
parents: 13538
diff changeset
    29
#endif
d178a834f1f4 set proper sdl calling convention for vcpkg builds
alfadur
parents: 13538
diff changeset
    30
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    31
/* SDL's RWOPS interface changed a little in SDL 1.3... */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    32
#if defined(SDL_VERSION_ATLEAST)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    33
#if SDL_VERSION_ATLEAST(1, 3, 0)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    34
#define TARGET_SDL13 1
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    35
#endif
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    36
#endif
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    37
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    38
#if TARGET_SDL13
9378
2be457289e60 update physlayer and sdl bindings to the new rwops interface
koda
parents: 9309
diff changeset
    39
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
    40
{
2be457289e60 update physlayer and sdl bindings to the new rwops interface
koda
parents: 9309
diff changeset
    41
    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
    42
    return PHYSFS_fileLength(handle);
2be457289e60 update physlayer and sdl bindings to the new rwops interface
koda
parents: 9309
diff changeset
    43
}
2be457289e60 update physlayer and sdl bindings to the new rwops interface
koda
parents: 9309
diff changeset
    44
#endif
2be457289e60 update physlayer and sdl bindings to the new rwops interface
koda
parents: 9309
diff changeset
    45
2be457289e60 update physlayer and sdl bindings to the new rwops interface
koda
parents: 9309
diff changeset
    46
#if TARGET_SDL13
9309
7e8f91634f80 engine compiles for ios again, but SDL bindings are outdated. Fix some warnings
koda
parents: 8524
diff changeset
    47
static SDLCALL Sint64 physfsrwops_seek(struct SDL_RWops *rw, Sint64 offset, int whence)
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    48
#else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    49
static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    50
#endif
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    51
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    52
    PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    53
    PHYSFS_sint64 pos = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    54
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    55
    if (whence == SEEK_SET)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    56
        pos = (PHYSFS_sint64) offset;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    57
    else if (whence == SEEK_CUR)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    58
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    59
        const PHYSFS_sint64 current = PHYSFS_tell(handle);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    60
        if (current == -1)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    61
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    62
            SDL_SetError("Can't find position in file: %s",
13538
f8c0a62fa3ac Fix deprecation warnings in libphyslayer
Wuzzy <Wuzzy2@mail.ru>
parents: 11656
diff changeset
    63
                          PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    64
            return -1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    65
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    66
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    67
        if (offset == 0)  /* this is a "tell" call. We're done. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    68
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    69
            #if TARGET_SDL13
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    70
            return (long) current;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    71
            #else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    72
            return (int) current;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    73
            #endif
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    74
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    75
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    76
        pos = current + ((PHYSFS_sint64) offset);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    77
    } /* else if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    78
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    79
    else if (whence == SEEK_END)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    80
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    81
        const PHYSFS_sint64 len = PHYSFS_fileLength(handle);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    82
        if (len == -1)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    83
        {
13538
f8c0a62fa3ac Fix deprecation warnings in libphyslayer
Wuzzy <Wuzzy2@mail.ru>
parents: 11656
diff changeset
    84
            SDL_SetError("Can't find end of file: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    85
            return -1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    86
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    87
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    88
        pos = len + ((PHYSFS_sint64) offset);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    89
    } /* else if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    90
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
        SDL_SetError("Invalid 'whence' parameter.");
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    94
        return -1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    95
    } /* else */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    96
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    97
    if ( pos < 0 )
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    98
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    99
        SDL_SetError("Attempt to seek past start of file.");
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   100
        return -1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   101
    } /* if */
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9378
diff changeset
   102
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   103
    if (!PHYSFS_seek(handle, (PHYSFS_uint64) pos))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   104
    {
13538
f8c0a62fa3ac Fix deprecation warnings in libphyslayer
Wuzzy <Wuzzy2@mail.ru>
parents: 11656
diff changeset
   105
        SDL_SetError("PhysicsFS error: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   106
        return -1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   107
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   108
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   109
    #if TARGET_SDL13
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   110
    return (long) pos;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   111
    #else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   112
    return (int) pos;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   113
    #endif
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   114
} /* physfsrwops_seek */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   115
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   116
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   117
#if TARGET_SDL13
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   118
static size_t SDLCALL physfsrwops_read(struct SDL_RWops *rw, void *ptr,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   119
                                       size_t size, size_t maxnum)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   120
#else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   121
static int physfsrwops_read(SDL_RWops *rw, void *ptr, int size, int maxnum)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   122
#endif
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   123
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   124
    PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   125
    const PHYSFS_uint64 readlen = (PHYSFS_uint64) (maxnum * size);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   126
    const PHYSFS_sint64 rc = PHYSFS_readBytes(handle, ptr, readlen);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   127
    if (rc != ((PHYSFS_sint64) readlen))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   128
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   129
        if (!PHYSFS_eof(handle)) /* not EOF? Must be an error. */
13538
f8c0a62fa3ac Fix deprecation warnings in libphyslayer
Wuzzy <Wuzzy2@mail.ru>
parents: 11656
diff changeset
   130
            SDL_SetError("PhysicsFS error: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   131
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   132
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   133
    #if TARGET_SDL13
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   134
    return (size_t) rc;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   135
    #else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   136
    return (int) rc;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   137
    #endif
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   138
} /* physfsrwops_read */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   139
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   140
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   141
#if TARGET_SDL13
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   142
static size_t SDLCALL physfsrwops_write(struct SDL_RWops *rw, const void *ptr,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   143
                                        size_t size, size_t num)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   144
#else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   145
static int physfsrwops_write(SDL_RWops *rw, const void *ptr, int size, int num)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   146
#endif
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   147
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   148
    PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   149
    const PHYSFS_uint64 writelen = (PHYSFS_uint64) (num * size);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   150
    const PHYSFS_sint64 rc = PHYSFS_writeBytes(handle, ptr, writelen);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   151
    if (rc != ((PHYSFS_sint64) writelen))
13538
f8c0a62fa3ac Fix deprecation warnings in libphyslayer
Wuzzy <Wuzzy2@mail.ru>
parents: 11656
diff changeset
   152
        SDL_SetError("PhysicsFS error: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   153
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   154
    #if TARGET_SDL13
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   155
    return (size_t) rc;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   156
    #else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   157
    return (int) rc;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   158
    #endif
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   159
} /* physfsrwops_write */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   160
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   161
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   162
static int physfsrwops_close(SDL_RWops *rw)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   163
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   164
    PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   165
    if (!PHYSFS_close(handle))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   166
    {
13538
f8c0a62fa3ac Fix deprecation warnings in libphyslayer
Wuzzy <Wuzzy2@mail.ru>
parents: 11656
diff changeset
   167
        SDL_SetError("PhysicsFS error: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   168
        return -1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   169
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   170
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   171
    SDL_FreeRW(rw);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   172
    return 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   173
} /* physfsrwops_close */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   174
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   175
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   176
static SDL_RWops *create_rwops(PHYSFS_File *handle)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   177
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   178
    SDL_RWops *retval = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   179
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   180
    if (handle == NULL)
13538
f8c0a62fa3ac Fix deprecation warnings in libphyslayer
Wuzzy <Wuzzy2@mail.ru>
parents: 11656
diff changeset
   181
        SDL_SetError("PhysicsFS error: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   182
    else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   183
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   184
        retval = SDL_AllocRW();
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   185
        if (retval != NULL)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   186
        {
11656
227718170097 Work around how emscripten defines rwops
koda
parents: 10017
diff changeset
   187
#if TARGET_SDL13 && !defined(EMSCRIPTEN)
9378
2be457289e60 update physlayer and sdl bindings to the new rwops interface
koda
parents: 9309
diff changeset
   188
            retval->size  = physfsrwops_size;
2be457289e60 update physlayer and sdl bindings to the new rwops interface
koda
parents: 9309
diff changeset
   189
#endif
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   190
            retval->seek  = physfsrwops_seek;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   191
            retval->read  = physfsrwops_read;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   192
            retval->write = physfsrwops_write;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   193
            retval->close = physfsrwops_close;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   194
            retval->hidden.unknown.data1 = handle;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   195
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   196
    } /* else */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   197
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   198
    return retval;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   199
} /* create_rwops */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   200
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   201
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   202
SDL_RWops *PHYSFSRWOPS_makeRWops(PHYSFS_File *handle)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   203
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   204
    SDL_RWops *retval = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   205
    if (handle == NULL)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   206
        SDL_SetError("NULL pointer passed to PHYSFSRWOPS_makeRWops().");
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   207
    else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   208
        retval = create_rwops(handle);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   209
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   210
    return retval;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   211
} /* PHYSFSRWOPS_makeRWops */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   212
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   213
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   214
SDL_RWops *PHYSFSRWOPS_openRead(const char *fname)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   215
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   216
    return create_rwops(PHYSFS_openRead(fname));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   217
} /* PHYSFSRWOPS_openRead */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   218
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   219
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   220
SDL_RWops *PHYSFSRWOPS_openWrite(const char *fname)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   221
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   222
    return create_rwops(PHYSFS_openWrite(fname));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   223
} /* PHYSFSRWOPS_openWrite */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   224
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   225
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   226
SDL_RWops *PHYSFSRWOPS_openAppend(const char *fname)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   227
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   228
    return create_rwops(PHYSFS_openAppend(fname));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   229
} /* PHYSFSRWOPS_openAppend */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   230
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   231
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   232
/* end of physfsrwops.c ... */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   233