include/SDL_rwops.h
author Sam Lantinga <slouken@libsdl.org>
Sat, 05 Sep 2009 23:37:35 +0000
changeset 3253 5d7ef5970073
parent 2859 99210400e8b9
child 3407 d3baf5ac4e37
permissions -rw-r--r--
Fixed issues building 64-bit Windows binary
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@2859
     3
    Copyright (C) 1997-2009 Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@0
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@251
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@0
    22
slouken@1895
    23
/**
slouken@1895
    24
 * \file SDL_rwops.h
slouken@1895
    25
 *
slouken@1895
    26
 * This file provides a general interface for SDL to read and write
slouken@1895
    27
 * data sources.  It can easily be extended to files, memory, etc.
slouken@1895
    28
 */
slouken@0
    29
slouken@1402
    30
#ifndef _SDL_rwops_h
slouken@1402
    31
#define _SDL_rwops_h
slouken@0
    32
slouken@1354
    33
#include "SDL_stdinc.h"
slouken@1358
    34
#include "SDL_error.h"
slouken@1330
    35
slouken@0
    36
#include "begin_code.h"
slouken@0
    37
/* Set up for C function definitions, even when using C++ */
slouken@0
    38
#ifdef __cplusplus
slouken@1895
    39
/* *INDENT-OFF* */
slouken@0
    40
extern "C" {
slouken@1895
    41
/* *INDENT-ON* */
slouken@0
    42
#endif
slouken@0
    43
slouken@0
    44
/* This is the read/write operation structure -- very basic */
slouken@0
    45
slouken@1895
    46
typedef struct SDL_RWops
slouken@1895
    47
{
slouken@1895
    48
    /* Seek to 'offset' relative to whence, one of stdio's whence values:
slouken@2160
    49
       RW_SEEK_SET, RW_SEEK_CUR, RW_SEEK_END
slouken@1895
    50
       Returns the final offset in the data source.
slouken@1895
    51
     */
slouken@2160
    52
    long (SDLCALL * seek) (struct SDL_RWops * context, long offset,
slouken@2160
    53
                           int whence);
slouken@0
    54
slouken@1895
    55
    /* Read up to 'num' objects each of size 'objsize' from the data
slouken@1895
    56
       source to the area pointed at by 'ptr'.
slouken@2160
    57
       Returns the number of objects read, or 0 at error or end of file.
slouken@1895
    58
     */
slouken@2160
    59
      size_t(SDLCALL * read) (struct SDL_RWops * context, void *ptr,
slouken@2160
    60
                              size_t size, size_t maxnum);
slouken@0
    61
slouken@1895
    62
    /* Write exactly 'num' objects each of size 'objsize' from the area
slouken@1895
    63
       pointed at by 'ptr' to data source.
slouken@2160
    64
       Returns the number of objects written, or 0 at error or end of file.
slouken@1895
    65
     */
slouken@2160
    66
      size_t(SDLCALL * write) (struct SDL_RWops * context, const void *ptr,
slouken@2160
    67
                               size_t size, size_t num);
slouken@0
    68
slouken@2160
    69
    /* Close and free an allocated SDL_RWops structure.
slouken@2160
    70
       Returns 0 if successful or -1 on write error when flushing data.
slouken@2160
    71
     */
slouken@1895
    72
    int (SDLCALL * close) (struct SDL_RWops * context);
slouken@0
    73
slouken@1895
    74
    Uint32 type;
slouken@1895
    75
    union
slouken@1895
    76
    {
slouken@1447
    77
#ifdef __WIN32__
slouken@1895
    78
        struct
slouken@1895
    79
        {
slouken@2160
    80
            SDL_bool append;
slouken@1895
    81
            void *h;
slouken@2159
    82
            struct
slouken@2159
    83
            {
slouken@2159
    84
                void *data;
slouken@3253
    85
                size_t size;
slouken@3253
    86
                size_t left;
slouken@2159
    87
            } buffer;
slouken@1895
    88
        } win32io;
slouken@1447
    89
#endif
slouken@1895
    90
#ifdef HAVE_STDIO_H
slouken@1895
    91
        struct
slouken@1895
    92
        {
slouken@2160
    93
            SDL_bool autoclose;
slouken@1895
    94
            FILE *fp;
slouken@1895
    95
        } stdio;
slouken@1330
    96
#endif
slouken@1895
    97
        struct
slouken@1895
    98
        {
slouken@1895
    99
            Uint8 *base;
slouken@1895
   100
            Uint8 *here;
slouken@1895
   101
            Uint8 *stop;
slouken@1895
   102
        } mem;
slouken@1895
   103
        struct
slouken@1895
   104
        {
slouken@1895
   105
            void *data1;
slouken@1895
   106
        } unknown;
slouken@1895
   107
    } hidden;
slouken@0
   108
slouken@0
   109
} SDL_RWops;
slouken@0
   110
slouken@0
   111
slouken@0
   112
/* Functions to create SDL_RWops structures from various data sources */
slouken@0
   113
slouken@1895
   114
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFile(const char *file,
slouken@1895
   115
                                                  const char *mode);
slouken@0
   116
slouken@1330
   117
#ifdef HAVE_STDIO_H
slouken@2161
   118
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(FILE * fp,
slouken@2161
   119
                                                SDL_bool autoclose);
slouken@1330
   120
#endif
slouken@0
   121
slouken@1895
   122
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromMem(void *mem, int size);
slouken@1895
   123
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromConstMem(const void *mem,
slouken@1895
   124
                                                      int size);
slouken@0
   125
slouken@1895
   126
extern DECLSPEC SDL_RWops *SDLCALL SDL_AllocRW(void);
slouken@1895
   127
extern DECLSPEC void SDLCALL SDL_FreeRW(SDL_RWops * area);
slouken@0
   128
slouken@1895
   129
#define RW_SEEK_SET	0       /* Seek from the beginning of data */
slouken@1895
   130
#define RW_SEEK_CUR	1       /* Seek relative to current read point */
slouken@1895
   131
#define RW_SEEK_END	2       /* Seek relative to the end of data */
slouken@1330
   132
slouken@0
   133
/* Macros to easily read and write from an SDL_RWops structure */
slouken@0
   134
#define SDL_RWseek(ctx, offset, whence)	(ctx)->seek(ctx, offset, whence)
slouken@1330
   135
#define SDL_RWtell(ctx)			(ctx)->seek(ctx, 0, RW_SEEK_CUR)
slouken@0
   136
#define SDL_RWread(ctx, ptr, size, n)	(ctx)->read(ctx, ptr, size, n)
slouken@0
   137
#define SDL_RWwrite(ctx, ptr, size, n)	(ctx)->write(ctx, ptr, size, n)
slouken@0
   138
#define SDL_RWclose(ctx)		(ctx)->close(ctx)
slouken@0
   139
slouken@0
   140
slouken@1354
   141
/* Read an item of the specified endianness and return in native format */
slouken@1895
   142
extern DECLSPEC Uint16 SDLCALL SDL_ReadLE16(SDL_RWops * src);
slouken@1895
   143
extern DECLSPEC Uint16 SDLCALL SDL_ReadBE16(SDL_RWops * src);
slouken@1895
   144
extern DECLSPEC Uint32 SDLCALL SDL_ReadLE32(SDL_RWops * src);
slouken@1895
   145
extern DECLSPEC Uint32 SDLCALL SDL_ReadBE32(SDL_RWops * src);
slouken@1895
   146
extern DECLSPEC Uint64 SDLCALL SDL_ReadLE64(SDL_RWops * src);
slouken@1895
   147
extern DECLSPEC Uint64 SDLCALL SDL_ReadBE64(SDL_RWops * src);
slouken@1354
   148
slouken@1354
   149
/* Write an item of native format to the specified endianness */
slouken@3253
   150
extern DECLSPEC size_t SDLCALL SDL_WriteLE16(SDL_RWops * dst, Uint16 value);
slouken@3253
   151
extern DECLSPEC size_t SDLCALL SDL_WriteBE16(SDL_RWops * dst, Uint16 value);
slouken@3253
   152
extern DECLSPEC size_t SDLCALL SDL_WriteLE32(SDL_RWops * dst, Uint32 value);
slouken@3253
   153
extern DECLSPEC size_t SDLCALL SDL_WriteBE32(SDL_RWops * dst, Uint32 value);
slouken@3253
   154
extern DECLSPEC size_t SDLCALL SDL_WriteLE64(SDL_RWops * dst, Uint64 value);
slouken@3253
   155
extern DECLSPEC size_t SDLCALL SDL_WriteBE64(SDL_RWops * dst, Uint64 value);
slouken@1354
   156
slouken@1354
   157
slouken@0
   158
/* Ends C function definitions when using C++ */
slouken@0
   159
#ifdef __cplusplus
slouken@1895
   160
/* *INDENT-OFF* */
slouken@0
   161
}
slouken@1895
   162
/* *INDENT-ON* */
slouken@0
   163
#endif
slouken@0
   164
#include "close_code.h"
slouken@0
   165
slouken@1402
   166
#endif /* _SDL_rwops_h */
slouken@1895
   167
slouken@1895
   168
/* vi: set ts=4 sw=4 expandtab: */