include/SDL_rwops.h
author Ozkan Sezer <sezeroz@gmail.com>
Sun, 01 Jul 2018 17:00:02 +0300
branchSDL-1.2
changeset 12053 edddd89f910d
parent 6137 4720145f848b
permissions -rw-r--r--
SDL_svgaevents.c: add missing ioctl.h include
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@6137
     3
    Copyright (C) 1997-2012 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@4217
    23
/** @file SDL_rwops.h
slouken@4217
    24
 *  This file provides a general interface for SDL to read and write
slouken@4217
    25
 *  data sources.  It can easily be extended to files, memory, etc.
slouken@4217
    26
 */
slouken@0
    27
slouken@1402
    28
#ifndef _SDL_rwops_h
slouken@1402
    29
#define _SDL_rwops_h
slouken@0
    30
slouken@1354
    31
#include "SDL_stdinc.h"
slouken@1358
    32
#include "SDL_error.h"
slouken@1330
    33
slouken@0
    34
#include "begin_code.h"
slouken@0
    35
/* Set up for C function definitions, even when using C++ */
slouken@0
    36
#ifdef __cplusplus
slouken@0
    37
extern "C" {
slouken@0
    38
#endif
slouken@0
    39
slouken@4217
    40
/** This is the read/write operation structure -- very basic */
slouken@0
    41
slouken@0
    42
typedef struct SDL_RWops {
slouken@4217
    43
	/** Seek to 'offset' relative to whence, one of stdio's whence values:
slouken@4217
    44
	 *	SEEK_SET, SEEK_CUR, SEEK_END
slouken@4217
    45
	 *  Returns the final offset in the data source.
slouken@0
    46
	 */
slouken@930
    47
	int (SDLCALL *seek)(struct SDL_RWops *context, int offset, int whence);
slouken@0
    48
slouken@4217
    49
	/** Read up to 'maxnum' objects each of size 'size' from the data
slouken@4217
    50
	 *  source to the area pointed at by 'ptr'.
slouken@4217
    51
	 *  Returns the number of objects read, or -1 if the read failed.
slouken@0
    52
	 */
slouken@930
    53
	int (SDLCALL *read)(struct SDL_RWops *context, void *ptr, int size, int maxnum);
slouken@0
    54
slouken@4217
    55
	/** Write exactly 'num' objects each of size 'objsize' from the area
slouken@4217
    56
	 *  pointed at by 'ptr' to data source.
slouken@4217
    57
	 *  Returns 'num', or -1 if the write failed.
slouken@0
    58
	 */
slouken@930
    59
	int (SDLCALL *write)(struct SDL_RWops *context, const void *ptr, int size, int num);
slouken@0
    60
slouken@4217
    61
	/** Close and free an allocated SDL_FSops structure */
slouken@930
    62
	int (SDLCALL *close)(struct SDL_RWops *context);
slouken@0
    63
slouken@0
    64
	Uint32 type;
slouken@0
    65
	union {
slouken@4026
    66
#if defined(__WIN32__) && !defined(__SYMBIAN32__)
slouken@1449
    67
	    struct {
slouken@4026
    68
		int   append;
slouken@4026
    69
		void *h;
slouken@4026
    70
		struct {
slouken@4026
    71
		    void *data;
slouken@4026
    72
		    int size;
slouken@4026
    73
		    int left;
slouken@4026
    74
		} buffer;
slouken@1449
    75
	    } win32io;
slouken@1447
    76
#endif
slouken@1446
    77
#ifdef HAVE_STDIO_H 
slouken@0
    78
	    struct {
slouken@0
    79
		int autoclose;
slouken@0
    80
	 	FILE *fp;
slouken@0
    81
	    } stdio;
slouken@1330
    82
#endif
slouken@0
    83
	    struct {
slouken@0
    84
		Uint8 *base;
slouken@0
    85
	 	Uint8 *here;
slouken@0
    86
		Uint8 *stop;
slouken@0
    87
	    } mem;
slouken@0
    88
	    struct {
slouken@0
    89
		void *data1;
slouken@0
    90
	    } unknown;
slouken@0
    91
	} hidden;
slouken@0
    92
slouken@0
    93
} SDL_RWops;
slouken@0
    94
slouken@0
    95
slouken@4217
    96
/** @name Functions to create SDL_RWops structures from various data sources */
slouken@4217
    97
/*@{*/
slouken@0
    98
slouken@337
    99
extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromFile(const char *file, const char *mode);
slouken@0
   100
slouken@1330
   101
#ifdef HAVE_STDIO_H
slouken@337
   102
extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromFP(FILE *fp, int autoclose);
slouken@1330
   103
#endif
slouken@0
   104
slouken@337
   105
extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromMem(void *mem, int size);
slouken@764
   106
extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromConstMem(const void *mem, int size);
slouken@0
   107
slouken@337
   108
extern DECLSPEC SDL_RWops * SDLCALL SDL_AllocRW(void);
slouken@337
   109
extern DECLSPEC void SDLCALL SDL_FreeRW(SDL_RWops *area);
slouken@0
   110
slouken@4217
   111
/*@}*/
slouken@1330
   112
slouken@4217
   113
/** @name Seek Reference Points */
slouken@4217
   114
/*@{*/
slouken@4217
   115
#define RW_SEEK_SET	0	/**< Seek from the beginning of data */
slouken@4217
   116
#define RW_SEEK_CUR	1	/**< Seek relative to current read point */
slouken@4217
   117
#define RW_SEEK_END	2	/**< Seek relative to the end of data */
slouken@4217
   118
/*@}*/
slouken@4217
   119
slouken@4217
   120
/** @name Macros to easily read and write from an SDL_RWops structure */
slouken@4217
   121
/*@{*/
slouken@0
   122
#define SDL_RWseek(ctx, offset, whence)	(ctx)->seek(ctx, offset, whence)
slouken@1330
   123
#define SDL_RWtell(ctx)			(ctx)->seek(ctx, 0, RW_SEEK_CUR)
slouken@0
   124
#define SDL_RWread(ctx, ptr, size, n)	(ctx)->read(ctx, ptr, size, n)
slouken@0
   125
#define SDL_RWwrite(ctx, ptr, size, n)	(ctx)->write(ctx, ptr, size, n)
slouken@0
   126
#define SDL_RWclose(ctx)		(ctx)->close(ctx)
slouken@4217
   127
/*@}*/
slouken@0
   128
slouken@4217
   129
/** @name Read an item of the specified endianness and return in native format */
slouken@4217
   130
/*@{*/
slouken@1354
   131
extern DECLSPEC Uint16 SDLCALL SDL_ReadLE16(SDL_RWops *src);
slouken@1354
   132
extern DECLSPEC Uint16 SDLCALL SDL_ReadBE16(SDL_RWops *src);
slouken@1354
   133
extern DECLSPEC Uint32 SDLCALL SDL_ReadLE32(SDL_RWops *src);
slouken@1354
   134
extern DECLSPEC Uint32 SDLCALL SDL_ReadBE32(SDL_RWops *src);
slouken@1354
   135
extern DECLSPEC Uint64 SDLCALL SDL_ReadLE64(SDL_RWops *src);
slouken@1354
   136
extern DECLSPEC Uint64 SDLCALL SDL_ReadBE64(SDL_RWops *src);
slouken@4217
   137
/*@}*/
slouken@1354
   138
slouken@4217
   139
/** @name Write an item of native format to the specified endianness */
slouken@4217
   140
/*@{*/
slouken@1354
   141
extern DECLSPEC int SDLCALL SDL_WriteLE16(SDL_RWops *dst, Uint16 value);
slouken@1354
   142
extern DECLSPEC int SDLCALL SDL_WriteBE16(SDL_RWops *dst, Uint16 value);
slouken@1354
   143
extern DECLSPEC int SDLCALL SDL_WriteLE32(SDL_RWops *dst, Uint32 value);
slouken@1354
   144
extern DECLSPEC int SDLCALL SDL_WriteBE32(SDL_RWops *dst, Uint32 value);
slouken@1354
   145
extern DECLSPEC int SDLCALL SDL_WriteLE64(SDL_RWops *dst, Uint64 value);
slouken@1354
   146
extern DECLSPEC int SDLCALL SDL_WriteBE64(SDL_RWops *dst, Uint64 value);
slouken@4217
   147
/*@}*/
slouken@1354
   148
slouken@0
   149
/* Ends C function definitions when using C++ */
slouken@0
   150
#ifdef __cplusplus
slouken@0
   151
}
slouken@0
   152
#endif
slouken@0
   153
#include "close_code.h"
slouken@0
   154
slouken@1402
   155
#endif /* _SDL_rwops_h */