include/SDL_rwops.h
author Sam Lantinga <slouken@libsdl.org>
Sun, 08 Jun 2014 12:05:17 -0700
changeset 8850 7e248a233387
parent 8845 5d51b3217769
child 9619 b94b6d0bff0f
permissions -rw-r--r--
The NaCL mount/unmount functions need to be in SDL_system.h and specific to NaCL
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     2
  Simple DirectMedia Layer
8149
681eb46b8ac4 Fixed bug 2374 - Update copyright for 2014...
Sam Lantinga <slouken@libsdl.org>
parents: 7678
diff changeset
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     7
  arising from the use of this software.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    11
  freely, subject to the following restrictions:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    20
*/
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    21
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
    22
/**
3407
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
    23
 *  \file SDL_rwops.h
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7064
diff changeset
    24
 *
3407
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
    25
 *  This file provides a general interface for SDL to read and write
4971
158bb5752974 Updated headers to match wiki documentation
Sam Lantinga <slouken@libsdl.org>
parents: 4864
diff changeset
    26
 *  data streams.  It can easily be extended to files, memory, etc.
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
    27
 */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    28
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    29
#ifndef _SDL_rwops_h
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    30
#define _SDL_rwops_h
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    31
1354
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
    32
#include "SDL_stdinc.h"
1358
c71e05b4dc2e More header massaging... works great on Windows. ;-)
Sam Lantinga <slouken@libsdl.org>
parents: 1356
diff changeset
    33
#include "SDL_error.h"
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
    34
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    35
#include "begin_code.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    36
/* Set up for C function definitions, even when using C++ */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    37
#ifdef __cplusplus
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    38
extern "C" {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    39
#endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    40
6999
681820ca0e78 Fix bug 122 - SDL_RWops bug fixes: set RWops.type field, add input validation, add test coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6996
diff changeset
    41
/* RWops Types */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7064
diff changeset
    42
#define SDL_RWOPS_UNKNOWN   0   /* Unknown stream type */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7064
diff changeset
    43
#define SDL_RWOPS_WINFILE   1   /* Win32 file */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7064
diff changeset
    44
#define SDL_RWOPS_STDFILE   2   /* Stdio file */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7064
diff changeset
    45
#define SDL_RWOPS_JNIFILE   3   /* Android asset */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7064
diff changeset
    46
#define SDL_RWOPS_MEMORY    4   /* Memory stream */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7064
diff changeset
    47
#define SDL_RWOPS_MEMORY_RO 5   /* Read-Only memory stream */
6999
681820ca0e78 Fix bug 122 - SDL_RWops bug fixes: set RWops.type field, add input validation, add test coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6996
diff changeset
    48
3407
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
    49
/**
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
    50
 * This is the read/write operation structure -- very basic.
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
    51
 */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
    52
typedef struct SDL_RWops
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
    53
{
3407
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
    54
    /**
6642
b716011e53ce Added an API to get the size of a file - WARNING! ABI CHANGE!
Sam Lantinga <slouken@libsdl.org>
parents: 6308
diff changeset
    55
     *  Return the size of the file in this rwops, or -1 if unknown
b716011e53ce Added an API to get the size of a file - WARNING! ABI CHANGE!
Sam Lantinga <slouken@libsdl.org>
parents: 6308
diff changeset
    56
     */
b716011e53ce Added an API to get the size of a file - WARNING! ABI CHANGE!
Sam Lantinga <slouken@libsdl.org>
parents: 6308
diff changeset
    57
    Sint64 (SDLCALL * size) (struct SDL_RWops * context);
b716011e53ce Added an API to get the size of a file - WARNING! ABI CHANGE!
Sam Lantinga <slouken@libsdl.org>
parents: 6308
diff changeset
    58
b716011e53ce Added an API to get the size of a file - WARNING! ABI CHANGE!
Sam Lantinga <slouken@libsdl.org>
parents: 6308
diff changeset
    59
    /**
3407
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
    60
     *  Seek to \c offset relative to \c whence, one of stdio's whence values:
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
    61
     *  RW_SEEK_SET, RW_SEEK_CUR, RW_SEEK_END
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7064
diff changeset
    62
     *
6996
bc0fd5bced25 Fix bug 1560 - SDL_RWFromConstMem write operation returns -1 but should return 0.
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6885
diff changeset
    63
     *  \return the final offset in the data stream, or -1 on error.
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
    64
     */
6642
b716011e53ce Added an API to get the size of a file - WARNING! ABI CHANGE!
Sam Lantinga <slouken@libsdl.org>
parents: 6308
diff changeset
    65
    Sint64 (SDLCALL * seek) (struct SDL_RWops * context, Sint64 offset,
b716011e53ce Added an API to get the size of a file - WARNING! ABI CHANGE!
Sam Lantinga <slouken@libsdl.org>
parents: 6308
diff changeset
    66
                             int whence);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    67
3407
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
    68
    /**
3614
701f54683b24 Merged r4412:4413 from branches/SDL-1.2: rwops documentation fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 3564
diff changeset
    69
     *  Read up to \c maxnum objects each of size \c size from the data
4971
158bb5752974 Updated headers to match wiki documentation
Sam Lantinga <slouken@libsdl.org>
parents: 4864
diff changeset
    70
     *  stream to the area pointed at by \c ptr.
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7064
diff changeset
    71
     *
3407
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
    72
     *  \return the number of objects read, or 0 at error or end of file.
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
    73
     */
6642
b716011e53ce Added an API to get the size of a file - WARNING! ABI CHANGE!
Sam Lantinga <slouken@libsdl.org>
parents: 6308
diff changeset
    74
    size_t (SDLCALL * read) (struct SDL_RWops * context, void *ptr,
b716011e53ce Added an API to get the size of a file - WARNING! ABI CHANGE!
Sam Lantinga <slouken@libsdl.org>
parents: 6308
diff changeset
    75
                             size_t size, size_t maxnum);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    76
3407
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
    77
    /**
4864
ebcb4988b16f Fixed documentation typo
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    78
     *  Write exactly \c num objects each of size \c size from the area
4971
158bb5752974 Updated headers to match wiki documentation
Sam Lantinga <slouken@libsdl.org>
parents: 4864
diff changeset
    79
     *  pointed at by \c ptr to data stream.
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7064
diff changeset
    80
     *
3407
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
    81
     *  \return the number of objects written, or 0 at error or end of file.
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
    82
     */
6642
b716011e53ce Added an API to get the size of a file - WARNING! ABI CHANGE!
Sam Lantinga <slouken@libsdl.org>
parents: 6308
diff changeset
    83
    size_t (SDLCALL * write) (struct SDL_RWops * context, const void *ptr,
b716011e53ce Added an API to get the size of a file - WARNING! ABI CHANGE!
Sam Lantinga <slouken@libsdl.org>
parents: 6308
diff changeset
    84
                              size_t size, size_t num);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    85
3407
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
    86
    /**
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
    87
     *  Close and free an allocated SDL_RWops structure.
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7064
diff changeset
    88
     *
3407
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
    89
     *  \return 0 if successful or -1 on write error when flushing data.
2160
00adbaed3910 Updated to use size_t instead of int for amounts of data.
Sam Lantinga <slouken@libsdl.org>
parents: 2159
diff changeset
    90
     */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
    91
    int (SDLCALL * close) (struct SDL_RWops * context);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    92
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
    93
    Uint32 type;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
    94
    union
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
    95
    {
8761
bce4122e6e87 __ANDROID__ is the correct macro to check for an android system.ANDROID is only defined in NDK build system (.mk) and not in the standalone NDK.
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 8149
diff changeset
    96
#if defined(__ANDROID__)
5582
1281a3f1f0a6 Allow Android platforms to read from .apk files via the RWOPS interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
    97
        struct
1281a3f1f0a6 Allow Android platforms to read from .apk files via the RWOPS interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
    98
        {
1281a3f1f0a6 Allow Android platforms to read from .apk files via the RWOPS interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
    99
            void *fileNameRef;
1281a3f1f0a6 Allow Android platforms to read from .apk files via the RWOPS interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   100
            void *inputStreamRef;
1281a3f1f0a6 Allow Android platforms to read from .apk files via the RWOPS interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   101
            void *readableByteChannelRef;
1281a3f1f0a6 Allow Android platforms to read from .apk files via the RWOPS interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   102
            void *readMethod;
6806
9e57ff36fd7a Android: Access APK files using AssetFileDescriptor
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6655
diff changeset
   103
            void *assetFileDescriptorRef;
5582
1281a3f1f0a6 Allow Android platforms to read from .apk files via the RWOPS interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   104
            long position;
6806
9e57ff36fd7a Android: Access APK files using AssetFileDescriptor
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6655
diff changeset
   105
            long size;
9e57ff36fd7a Android: Access APK files using AssetFileDescriptor
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6655
diff changeset
   106
            long offset;
9e57ff36fd7a Android: Access APK files using AssetFileDescriptor
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6655
diff changeset
   107
            int fd;
5582
1281a3f1f0a6 Allow Android platforms to read from .apk files via the RWOPS interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   108
        } androidio;
1281a3f1f0a6 Allow Android platforms to read from .apk files via the RWOPS interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   109
#elif defined(__WIN32__)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   110
        struct
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   111
        {
2160
00adbaed3910 Updated to use size_t instead of int for amounts of data.
Sam Lantinga <slouken@libsdl.org>
parents: 2159
diff changeset
   112
            SDL_bool append;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   113
            void *h;
2159
dd4753e47ed4 Merged read-ahead support for Win32 file I/O from SDL 1.2 revision 3183
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   114
            struct
dd4753e47ed4 Merged read-ahead support for Win32 file I/O from SDL 1.2 revision 3183
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   115
            {
dd4753e47ed4 Merged read-ahead support for Win32 file I/O from SDL 1.2 revision 3183
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   116
                void *data;
3253
5d7ef5970073 Fixed issues building 64-bit Windows binary
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   117
                size_t size;
5d7ef5970073 Fixed issues building 64-bit Windows binary
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   118
                size_t left;
2159
dd4753e47ed4 Merged read-ahead support for Win32 file I/O from SDL 1.2 revision 3183
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   119
            } buffer;
5062
e8916fe9cfc8 Fixed bug #925
Sam Lantinga <slouken@libsdl.org>
parents: 4971
diff changeset
   120
        } windowsio;
1447
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   121
#endif
5582
1281a3f1f0a6 Allow Android platforms to read from .apk files via the RWOPS interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   122
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   123
#ifdef HAVE_STDIO_H
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   124
        struct
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   125
        {
2160
00adbaed3910 Updated to use size_t instead of int for amounts of data.
Sam Lantinga <slouken@libsdl.org>
parents: 2159
diff changeset
   126
            SDL_bool autoclose;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   127
            FILE *fp;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   128
        } stdio;
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
   129
#endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   130
        struct
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   131
        {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   132
            Uint8 *base;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   133
            Uint8 *here;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   134
            Uint8 *stop;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   135
        } mem;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   136
        struct
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   137
        {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   138
            void *data1;
7064
239ce872e8d4 Make the new SDL_RWops::hidden::unknown::data2 field a void*, not an int.
Ryan C. Gordon <icculus@icculus.org>
parents: 7063
diff changeset
   139
            void *data2;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   140
        } unknown;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   141
    } hidden;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   142
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   143
} SDL_RWops;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   144
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   145
3407
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
   146
/**
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
   147
 *  \name RWFrom functions
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7064
diff changeset
   148
 *
4971
158bb5752974 Updated headers to match wiki documentation
Sam Lantinga <slouken@libsdl.org>
parents: 4864
diff changeset
   149
 *  Functions to create SDL_RWops structures from various data streams.
3407
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
   150
 */
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   151
/* @{ */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   152
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   153
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFile(const char *file,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   154
                                                  const char *mode);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   155
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
   156
#ifdef HAVE_STDIO_H
2161
e635db5b45ef Oh yeah, they're boolean values...
Sam Lantinga <slouken@libsdl.org>
parents: 2160
diff changeset
   157
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(FILE * fp,
e635db5b45ef Oh yeah, they're boolean values...
Sam Lantinga <slouken@libsdl.org>
parents: 2160
diff changeset
   158
                                                SDL_bool autoclose);
3564
d264d99576c1 Add a dummy function if SDL doesn't have STDIO support
Sam Lantinga <slouken@libsdl.org>
parents: 3407
diff changeset
   159
#else
d264d99576c1 Add a dummy function if SDL doesn't have STDIO support
Sam Lantinga <slouken@libsdl.org>
parents: 3407
diff changeset
   160
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(void * fp,
d264d99576c1 Add a dummy function if SDL doesn't have STDIO support
Sam Lantinga <slouken@libsdl.org>
parents: 3407
diff changeset
   161
                                                SDL_bool autoclose);
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
   162
#endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   163
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   164
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromMem(void *mem, int size);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   165
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromConstMem(const void *mem,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   166
                                                      int size);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   167
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   168
/* @} *//* RWFrom functions */
3407
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
   169
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
   170
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   171
extern DECLSPEC SDL_RWops *SDLCALL SDL_AllocRW(void);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   172
extern DECLSPEC void SDLCALL SDL_FreeRW(SDL_RWops * area);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   173
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7064
diff changeset
   174
#define RW_SEEK_SET 0       /**< Seek from the beginning of data */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7064
diff changeset
   175
#define RW_SEEK_CUR 1       /**< Seek relative to current read point */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7064
diff changeset
   176
#define RW_SEEK_END 2       /**< Seek relative to the end of data */
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
   177
3407
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
   178
/**
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
   179
 *  \name Read/write macros
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7064
diff changeset
   180
 *
3407
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
   181
 *  Macros to easily read and write from an SDL_RWops structure.
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
   182
 */
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   183
/* @{ */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7064
diff changeset
   184
#define SDL_RWsize(ctx)         (ctx)->size(ctx)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7064
diff changeset
   185
#define SDL_RWseek(ctx, offset, whence) (ctx)->seek(ctx, offset, whence)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7064
diff changeset
   186
#define SDL_RWtell(ctx)         (ctx)->seek(ctx, 0, RW_SEEK_CUR)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7064
diff changeset
   187
#define SDL_RWread(ctx, ptr, size, n)   (ctx)->read(ctx, ptr, size, n)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7064
diff changeset
   188
#define SDL_RWwrite(ctx, ptr, size, n)  (ctx)->write(ctx, ptr, size, n)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7064
diff changeset
   189
#define SDL_RWclose(ctx)        (ctx)->close(ctx)
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   190
/* @} *//* Read/write macros */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   191
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   192
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7064
diff changeset
   193
/**
3407
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
   194
 *  \name Read endian functions
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7064
diff changeset
   195
 *
3407
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
   196
 *  Read an item of the specified endianness and return in native format.
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
   197
 */
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   198
/* @{ */
6655
6a3e741ea70d Added SDL_ReadU8() and SDL_WriteU8() for consistency with the rest of the API.
Sam Lantinga <slouken@libsdl.org>
parents: 6642
diff changeset
   199
extern DECLSPEC Uint8 SDLCALL SDL_ReadU8(SDL_RWops * src);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   200
extern DECLSPEC Uint16 SDLCALL SDL_ReadLE16(SDL_RWops * src);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   201
extern DECLSPEC Uint16 SDLCALL SDL_ReadBE16(SDL_RWops * src);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   202
extern DECLSPEC Uint32 SDLCALL SDL_ReadLE32(SDL_RWops * src);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   203
extern DECLSPEC Uint32 SDLCALL SDL_ReadBE32(SDL_RWops * src);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   204
extern DECLSPEC Uint64 SDLCALL SDL_ReadLE64(SDL_RWops * src);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   205
extern DECLSPEC Uint64 SDLCALL SDL_ReadBE64(SDL_RWops * src);
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   206
/* @} *//* Read endian functions */
1354
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
   207
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7064
diff changeset
   208
/**
3407
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
   209
 *  \name Write endian functions
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7064
diff changeset
   210
 *
3407
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
   211
 *  Write an item of native format to the specified endianness.
d3baf5ac4e37 Partial fix for bug #859
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
   212
 */
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   213
/* @{ */
6655
6a3e741ea70d Added SDL_ReadU8() and SDL_WriteU8() for consistency with the rest of the API.
Sam Lantinga <slouken@libsdl.org>
parents: 6642
diff changeset
   214
extern DECLSPEC size_t SDLCALL SDL_WriteU8(SDL_RWops * dst, Uint8 value);
3253
5d7ef5970073 Fixed issues building 64-bit Windows binary
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   215
extern DECLSPEC size_t SDLCALL SDL_WriteLE16(SDL_RWops * dst, Uint16 value);
5d7ef5970073 Fixed issues building 64-bit Windows binary
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   216
extern DECLSPEC size_t SDLCALL SDL_WriteBE16(SDL_RWops * dst, Uint16 value);
5d7ef5970073 Fixed issues building 64-bit Windows binary
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   217
extern DECLSPEC size_t SDLCALL SDL_WriteLE32(SDL_RWops * dst, Uint32 value);
5d7ef5970073 Fixed issues building 64-bit Windows binary
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   218
extern DECLSPEC size_t SDLCALL SDL_WriteBE32(SDL_RWops * dst, Uint32 value);
5d7ef5970073 Fixed issues building 64-bit Windows binary
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   219
extern DECLSPEC size_t SDLCALL SDL_WriteLE64(SDL_RWops * dst, Uint64 value);
5d7ef5970073 Fixed issues building 64-bit Windows binary
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   220
extern DECLSPEC size_t SDLCALL SDL_WriteBE64(SDL_RWops * dst, Uint64 value);
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   221
/* @} *//* Write endian functions */
1354
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
   222
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   223
/* Ends C function definitions when using C++ */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   224
#ifdef __cplusplus
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   225
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   226
#endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   227
#include "close_code.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   228
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   229
#endif /* _SDL_rwops_h */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   230
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   231
/* vi: set ts=4 sw=4 expandtab: */