src/file/SDL_rwops.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 04 Mar 2006 08:24:35 +0000
changeset 1465 8dfa9a6d69a5
parent 1456 84de7511f79f
child 1659 14717b52abc0
permissions -rw-r--r--
Updated WinCE support by Dmitry (with some tweaks) Converted the disk audio driver to SDL_RWops for portability
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     1
/*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     2
    SDL - Simple DirectMedia Layer
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1269
diff changeset
     3
    Copyright (C) 1997-2006 Sam Lantinga
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     5
    This library is free software; you can redistribute it and/or
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1269
diff changeset
     6
    modify it under the terms of the GNU Lesser General Public
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     7
    License as published by the Free Software Foundation; either
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1269
diff changeset
     8
    version 2.1 of the License, or (at your option) any later version.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    10
    This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1269
diff changeset
    13
    Lesser General Public License for more details.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    14
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1269
diff changeset
    15
    You should have received a copy of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1269
diff changeset
    16
    License along with this library; if not, write to the Free Software
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1269
diff changeset
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    19
    Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 36
diff changeset
    20
    slouken@libsdl.org
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    21
*/
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    22
#include "SDL_config.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    23
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    24
/* This file provides a general interface for SDL to read and write
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    25
   data sources.  It can easily be extended to files, memory, etc.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    26
*/
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    27
1354
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
    28
#include "SDL_endian.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    29
#include "SDL_rwops.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
    30
1354
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
    31
1465
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    32
#if defined(__WIN32__)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    33
1447
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
    34
/* Functions to read/write Win32 API file pointers */
1465
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    35
/* Will not use it on WinCE because stdio is buffered, it means
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    36
   faster, and all stdio functions anyway are embedded in coredll.dll - 
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    37
   the main wince dll*/
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    38
1446
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    39
#define WINDOWS_LEAN_AND_MEAN
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    40
#include <windows.h>
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    41
1465
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    42
#ifndef INVALID_SET_FILE_POINTER
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    43
#define INVALID_SET_FILE_POINTER 0xFFFFFFFF
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    44
#endif
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    45
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    46
static int win32_file_open(SDL_RWops *context, const char *filename, const char *mode)
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    47
{
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    48
#ifndef _WIN32_WCE
1446
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    49
	UINT	old_error_mode;
1465
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    50
#endif
1446
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    51
	HANDLE	h;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    52
	DWORD	r_right, w_right;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    53
	DWORD	must_exist, truncate;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    54
	int		a_mode;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    55
1455
f487bb150acc Hah, standard stdio code crashed on the test case.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
    56
	if (!context)
1446
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    57
		return -1;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    58
		
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    59
	context->hidden.win32io.h = INVALID_HANDLE_VALUE; /* mark this as unusable */
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    60
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    61
	/* "r" = reading, file must exist */
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    62
	/* "w" = writing, truncate existing, file may not exist */
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    63
	/* "r+"= reading or writing, file must exist            */
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    64
	/* "a" = writing, append file may not exist             */
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    65
	/* "a+"= append + read, file may not exist              */
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    66
	/* "w+" = read, write, truncate. file may not exist    */
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    67
	
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    68
	must_exist = ( SDL_strchr(mode,'r') != NULL ) ? OPEN_EXISTING : 0;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    69
	truncate   = ( SDL_strchr(mode,'w') != NULL ) ? CREATE_ALWAYS : 0;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    70
	r_right    = ( SDL_strchr(mode,'+') != NULL || must_exist ) ? GENERIC_READ : 0;
1453
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1447
diff changeset
    71
	a_mode     = ( SDL_strchr(mode,'a') != NULL ) ? OPEN_ALWAYS : 0;
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1447
diff changeset
    72
	w_right    = ( a_mode || SDL_strchr(mode,'+') || truncate ) ? GENERIC_WRITE : 0;
1446
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    73
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    74
	if (!r_right && !w_right) /* inconsistent mode */
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    75
		return -1; /* failed (invalid call)*/
1465
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    76
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    77
#ifdef _WIN32_WCE
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    78
	{
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    79
		size_t size = SDL_strlen(filename)+1;
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    80
		wchar_t *filenameW = SDL_stack_alloc(wchar_t, size);
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    81
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    82
		if ( MultiByteToWideChar(CP_UTF8, 0, filename, -1, filenameW, size) == 0 ) {
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    83
			SDL_SetError("Unable to convert filename to Unicode");
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    84
			SDL_stack_free(filenameW);
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    85
			return -1;
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    86
		}
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    87
		h = CreateFile(filenameW, (w_right|r_right), (w_right)? 0 : FILE_SHARE_READ, 
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    88
					   NULL, (must_exist|truncate|a_mode), FILE_ATTRIBUTE_NORMAL,NULL);
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    89
		SDL_stack_free(filenameW);
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    90
	}
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    91
#else
1446
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    92
	/* Do not open a dialog box if failure */
1465
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    93
	old_error_mode = SetErrorMode(SEM_NOOPENFILEERRORBOX|SEM_FAILCRITICALERRORS);
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    94
1446
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    95
	h = CreateFile(filename, (w_right|r_right), (w_right)? 0 : FILE_SHARE_READ, 
1453
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1447
diff changeset
    96
		           NULL, (must_exist|truncate|a_mode), FILE_ATTRIBUTE_NORMAL,NULL);
1465
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    97
1446
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    98
	/* restore old behaviour */
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    99
	SetErrorMode(old_error_mode);
1465
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   100
#endif /* _WIN32_WCE */
1446
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   101
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   102
	if (h==INVALID_HANDLE_VALUE) {
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   103
		SDL_SetError("Couldn't open %s",filename);
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   104
		return -2; /* failed (CreateFile) */
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   105
	}
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   106
	context->hidden.win32io.h = h;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   107
	context->hidden.win32io.append = a_mode;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   108
	
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   109
	return 0; /* ok */
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   110
}
1465
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   111
static int win32_file_seek(SDL_RWops *context, int offset, int whence)
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   112
{
1446
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   113
	DWORD win32whence;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   114
	int   file_pos;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   115
	
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   116
	if (!context || context->hidden.win32io.h == INVALID_HANDLE_VALUE) {
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   117
		SDL_SetError("win32_file_seek: invalid context/file not opened");
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   118
		return -1;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   119
	}
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   120
	
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   121
	switch (whence) {
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   122
		case RW_SEEK_SET:		
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   123
			win32whence = FILE_BEGIN; break;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   124
		case RW_SEEK_CUR:
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   125
			win32whence = FILE_CURRENT; break;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   126
		case RW_SEEK_END:
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   127
			win32whence = FILE_END; break;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   128
		default:
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   129
			SDL_SetError("win32_file_seek: Unknown value for 'whence'");			
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   130
			return -1;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   131
	}
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   132
	
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   133
	file_pos = SetFilePointer(context->hidden.win32io.h,offset,NULL,win32whence);
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   134
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   135
	if ( file_pos != INVALID_SET_FILE_POINTER )
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   136
		return file_pos; /* success */
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   137
	
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   138
	SDL_Error(SDL_EFSEEK);
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   139
	return -1; /* error */
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   140
}
1465
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   141
static int win32_file_read(SDL_RWops *context, void *ptr, int size, int maxnum)
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   142
{
1446
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   143
	
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   144
	int		total_bytes; 
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   145
	DWORD	byte_read,nread;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   146
	
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   147
	total_bytes = size*maxnum;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   148
	
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   149
	if (!context || context->hidden.win32io.h == INVALID_HANDLE_VALUE || total_bytes<=0 || !size) 	
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   150
		return 0;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   151
	
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   152
	if (!ReadFile(context->hidden.win32io.h,ptr,total_bytes,&byte_read,NULL)) {
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   153
		SDL_Error(SDL_EFREAD);
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   154
		return 0;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   155
	}
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   156
	nread = byte_read/size;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   157
	return nread;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   158
}
1465
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   159
static int win32_file_write(SDL_RWops *context, const void *ptr, int size, int num)
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   160
{
1446
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   161
	
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   162
	int		total_bytes; 
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   163
	DWORD	byte_written,nwritten;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   164
	
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   165
	total_bytes = size*num;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   166
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   167
	if (!context || context->hidden.win32io.h==INVALID_HANDLE_VALUE || total_bytes<=0 || !size) 	
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   168
		return 0;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   169
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   170
	/* if in append mode, we must go to the EOF before write */
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   171
	if (context->hidden.win32io.append) {
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   172
		if ( SetFilePointer(context->hidden.win32io.h,0L,NULL,FILE_END) == INVALID_SET_FILE_POINTER ) {
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   173
			SDL_Error(SDL_EFWRITE);
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   174
			return 0;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   175
		}
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   176
	}
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   177
	
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   178
	if (!WriteFile(context->hidden.win32io.h,ptr,total_bytes,&byte_written,NULL)) {
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   179
		SDL_Error(SDL_EFWRITE);
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   180
		return 0;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   181
	}
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   182
	
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   183
	nwritten = byte_written/size;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   184
	return nwritten;
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   185
}
1465
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   186
static int win32_file_close(SDL_RWops *context)
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   187
{
1446
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   188
	
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   189
	if ( context ) {								
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   190
		if (context->hidden.win32io.h != INVALID_HANDLE_VALUE) {
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   191
			CloseHandle(context->hidden.win32io.h);
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   192
			context->hidden.win32io.h = INVALID_HANDLE_VALUE; /* to be sure */
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   193
		}
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   194
		SDL_FreeRW(context);
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   195
	}
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   196
	return(0);
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   197
}
1447
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   198
#endif /* __WIN32__ */
1446
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   199
1447
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   200
#ifdef HAVE_STDIO_H
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   201
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   202
/* Functions to read/write stdio file pointers */
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   203
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   204
static int stdio_seek(SDL_RWops *context, int offset, int whence)
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   205
{
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   206
	if ( fseek(context->hidden.stdio.fp, offset, whence) == 0 ) {
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   207
		return(ftell(context->hidden.stdio.fp));
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   208
	} else {
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   209
		SDL_Error(SDL_EFSEEK);
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   210
		return(-1);
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   211
	}
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   212
}
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   213
static int stdio_read(SDL_RWops *context, void *ptr, int size, int maxnum)
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   214
{
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   215
	size_t nread;
1446
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   216
1447
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   217
	nread = fread(ptr, size, maxnum, context->hidden.stdio.fp); 
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   218
	if ( nread == 0 && ferror(context->hidden.stdio.fp) ) {
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   219
		SDL_Error(SDL_EFREAD);
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   220
	}
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   221
	return(nread);
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   222
}
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   223
static int stdio_write(SDL_RWops *context, const void *ptr, int size, int num)
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   224
{
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   225
	size_t nwrote;
1446
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   226
1447
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   227
	nwrote = fwrite(ptr, size, num, context->hidden.stdio.fp);
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   228
	if ( nwrote == 0 && ferror(context->hidden.stdio.fp) ) {
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   229
		SDL_Error(SDL_EFWRITE);
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   230
	}
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   231
	return(nwrote);
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   232
}
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   233
static int stdio_close(SDL_RWops *context)
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   234
{
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   235
	if ( context ) {
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   236
		if ( context->hidden.stdio.autoclose ) {
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   237
			/* WARNING:  Check the return value here! */
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   238
			fclose(context->hidden.stdio.fp);
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   239
		}
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   240
		SDL_FreeRW(context);
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   241
	}
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   242
	return(0);
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   243
}
1446
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   244
#endif /* !HAVE_STDIO_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
   245
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   246
/* Functions to read/write memory pointers */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   247
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   248
static int mem_seek(SDL_RWops *context, int offset, int whence)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   249
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   250
	Uint8 *newpos;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   251
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   252
	switch (whence) {
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
   253
		case RW_SEEK_SET:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   254
			newpos = context->hidden.mem.base+offset;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   255
			break;
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
   256
		case RW_SEEK_CUR:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   257
			newpos = context->hidden.mem.here+offset;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   258
			break;
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
   259
		case RW_SEEK_END:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   260
			newpos = context->hidden.mem.stop+offset;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   261
			break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   262
		default:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   263
			SDL_SetError("Unknown value for 'whence'");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   264
			return(-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   265
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   266
	if ( newpos < context->hidden.mem.base ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   267
		newpos = context->hidden.mem.base;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   268
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   269
	if ( newpos > context->hidden.mem.stop ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   270
		newpos = context->hidden.mem.stop;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   271
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   272
	context->hidden.mem.here = newpos;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   273
	return(context->hidden.mem.here-context->hidden.mem.base);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   274
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   275
static int mem_read(SDL_RWops *context, void *ptr, int size, int maxnum)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   276
{
1456
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1455
diff changeset
   277
	size_t total_bytes;
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1455
diff changeset
   278
	size_t mem_available;
1078
e2ef6b7001fd Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   279
e2ef6b7001fd Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   280
	total_bytes = (maxnum * size);
1465
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   281
	if ( (maxnum <= 0) || (size <= 0) || ((total_bytes / maxnum) != (size_t) size) ) {
1078
e2ef6b7001fd Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   282
		return 0;
e2ef6b7001fd Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   283
	}
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   284
1078
e2ef6b7001fd Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   285
	mem_available = (context->hidden.mem.stop - context->hidden.mem.here);
e2ef6b7001fd Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   286
	if (total_bytes > mem_available) {
e2ef6b7001fd Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   287
		total_bytes = mem_available;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   288
	}
1078
e2ef6b7001fd Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   289
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
   290
	SDL_memcpy(ptr, context->hidden.mem.here, total_bytes);
1078
e2ef6b7001fd Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   291
	context->hidden.mem.here += total_bytes;
e2ef6b7001fd Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   292
e2ef6b7001fd Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   293
	return (total_bytes / size);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   294
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   295
static int mem_write(SDL_RWops *context, const void *ptr, int size, int num)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   296
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   297
	if ( (context->hidden.mem.here + (num*size)) > context->hidden.mem.stop ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   298
		num = (context->hidden.mem.stop-context->hidden.mem.here)/size;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   299
	}
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
   300
	SDL_memcpy(context->hidden.mem.here, ptr, num*size);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   301
	context->hidden.mem.here += num*size;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   302
	return(num);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   303
}
764
974c0fb74bf8 Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
   304
static int mem_writeconst(SDL_RWops *context, const void *ptr, int size, int num)
974c0fb74bf8 Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
   305
{
974c0fb74bf8 Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
   306
	SDL_SetError("Can't write to read-only memory");
974c0fb74bf8 Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
   307
	return(-1);
974c0fb74bf8 Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
   308
}
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   309
static int mem_close(SDL_RWops *context)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   310
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   311
	if ( context ) {
1202
0748fbb272e7 Matched SDL_AllowRW and SDL_FreeRW calls in SDL_rwops.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 1078
diff changeset
   312
		SDL_FreeRW(context);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   313
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   314
	return(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   315
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   316
1447
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   317
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   318
/* Functions to create SDL_RWops structures from various data sources */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   319
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   320
#ifdef __MACOS__
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   321
/*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   322
 * translate unix-style slash-separated filename to mac-style colon-separated
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   323
 * name; return malloced string
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   324
 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   325
static char *unix_to_mac(const char *file)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   326
{
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
   327
	int flen = SDL_strlen(file);
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
   328
	char *path = SDL_malloc(flen + 2);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   329
	const char *src = file;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   330
	char *dst = path;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   331
	if(*src == '/') {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   332
		/* really depends on filesystem layout, hope for the best */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   333
		src++;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   334
	} else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   335
		/* Check if this is a MacOS path to begin with */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   336
		if(*src != ':')
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   337
			*dst++ = ':';   /* relative paths begin with ':' */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   338
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   339
	while(src < file + flen) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
   340
		const char *end = SDL_strchr(src, '/');
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   341
		int len;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   342
		if(!end)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   343
			end = file + flen; /* last component */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   344
		len = end - src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   345
		if(len == 0 || (len == 1 && src[0] == '.')) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   346
			/* remove repeated slashes and . */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   347
		} else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   348
			if(len == 2 && src[0] == '.' && src[1] == '.') {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   349
				/* replace .. with the empty string */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   350
			} else {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
   351
				SDL_memcpy(dst, src, len);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   352
				dst += len;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   353
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   354
			if(end < file + flen)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   355
				*dst++ = ':';
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   356
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   357
		src = end + 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   358
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   359
	*dst++ = '\0';
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   360
	return path;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   361
}
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   362
#endif /* __MACOS__ */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   363
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   364
SDL_RWops *SDL_RWFromFile(const char *file, const char *mode)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   365
{
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
   366
	SDL_RWops *rwops = NULL;
1465
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   367
#ifdef HAVE_STDIO_H
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   368
	FILE *fp = NULL;
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   369
#endif
1455
f487bb150acc Hah, standard stdio code crashed on the test case.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   370
	if ( !file || !*file || !mode || !*mode ) {
f487bb150acc Hah, standard stdio code crashed on the test case.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   371
		SDL_SetError("SDL_RWFromFile(): No file or no mode specified");
f487bb150acc Hah, standard stdio code crashed on the test case.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   372
		return NULL;
f487bb150acc Hah, standard stdio code crashed on the test case.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   373
	}
f487bb150acc Hah, standard stdio code crashed on the test case.
Sam Lantinga <slouken@libsdl.org>
parents: 1453
diff changeset
   374
1465
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   375
#if defined(__WIN32__)
1447
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   376
	rwops = SDL_AllocRW();
1453
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1447
diff changeset
   377
	if (!rwops)
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1447
diff changeset
   378
		return NULL; /* SDL_SetError already setup by SDL_AllocRW() */
1447
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   379
	rwops->hidden.win32io.h = INVALID_HANDLE_VALUE;
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   380
	if (win32_file_open(rwops,file,mode)) {
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   381
		SDL_FreeRW(rwops);
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   382
		return NULL;
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   383
	}	
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   384
	rwops->seek  = win32_file_seek;
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   385
	rwops->read  = win32_file_read;
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   386
	rwops->write = win32_file_write;
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   387
	rwops->close = win32_file_close;
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   388
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   389
#elif HAVE_STDIO_H
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   390
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   391
#ifdef __MACOS__
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   392
	{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   393
		char *mpath = unix_to_mac(file);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   394
		fp = fopen(mpath, mode);
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
   395
		SDL_free(mpath);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   396
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   397
#else
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   398
	fp = fopen(file, mode);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   399
#endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   400
	if ( fp == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   401
		SDL_SetError("Couldn't open %s", file);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   402
	} else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   403
		rwops = SDL_RWFromFP(fp, 1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   404
	}
1447
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   405
#else
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   406
	SDL_SetError("SDL not compiled with stdio support");
1446
47bf1767c4ca Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   407
#endif /* !HAVE_STDIO_H */
1447
515df0086eb7 Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents: 1446
diff changeset
   408
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   409
	return(rwops);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   410
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   411
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
   412
#ifdef HAVE_STDIO_H
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   413
SDL_RWops *SDL_RWFromFP(FILE *fp, int autoclose)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   414
{
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
   415
	SDL_RWops *rwops = NULL;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   416
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   417
	rwops = SDL_AllocRW();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   418
	if ( rwops != NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   419
		rwops->seek = stdio_seek;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   420
		rwops->read = stdio_read;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   421
		rwops->write = stdio_write;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   422
		rwops->close = stdio_close;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   423
		rwops->hidden.stdio.fp = fp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   424
		rwops->hidden.stdio.autoclose = autoclose;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   425
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   426
	return(rwops);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   427
}
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
   428
#endif /* HAVE_STDIO_H */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   429
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   430
SDL_RWops *SDL_RWFromMem(void *mem, int size)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   431
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   432
	SDL_RWops *rwops;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   433
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   434
	rwops = SDL_AllocRW();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   435
	if ( rwops != NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   436
		rwops->seek = mem_seek;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   437
		rwops->read = mem_read;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   438
		rwops->write = mem_write;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   439
		rwops->close = mem_close;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   440
		rwops->hidden.mem.base = (Uint8 *)mem;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   441
		rwops->hidden.mem.here = rwops->hidden.mem.base;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   442
		rwops->hidden.mem.stop = rwops->hidden.mem.base+size;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   443
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   444
	return(rwops);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   445
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   446
764
974c0fb74bf8 Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
   447
SDL_RWops *SDL_RWFromConstMem(const void *mem, int size)
974c0fb74bf8 Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
   448
{
974c0fb74bf8 Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
   449
	SDL_RWops *rwops;
974c0fb74bf8 Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
   450
974c0fb74bf8 Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
   451
	rwops = SDL_AllocRW();
974c0fb74bf8 Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
   452
	if ( rwops != NULL ) {
974c0fb74bf8 Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
   453
		rwops->seek = mem_seek;
974c0fb74bf8 Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
   454
		rwops->read = mem_read;
974c0fb74bf8 Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
   455
		rwops->write = mem_writeconst;
974c0fb74bf8 Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
   456
		rwops->close = mem_close;
974c0fb74bf8 Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
   457
		rwops->hidden.mem.base = (Uint8 *)mem;
974c0fb74bf8 Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
   458
		rwops->hidden.mem.here = rwops->hidden.mem.base;
974c0fb74bf8 Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
   459
		rwops->hidden.mem.stop = rwops->hidden.mem.base+size;
974c0fb74bf8 Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
   460
	}
974c0fb74bf8 Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
   461
	return(rwops);
974c0fb74bf8 Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
   462
}
974c0fb74bf8 Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
   463
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   464
SDL_RWops *SDL_AllocRW(void)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   465
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   466
	SDL_RWops *area;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   467
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
   468
	area = (SDL_RWops *)SDL_malloc(sizeof *area);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   469
	if ( area == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   470
		SDL_OutOfMemory();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   471
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   472
	return(area);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   473
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   474
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   475
void SDL_FreeRW(SDL_RWops *area)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   476
{
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
   477
	SDL_free(area);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   478
}
1354
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   479
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   480
/* Functions for dynamically reading and writing endian-specific values */
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   481
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   482
Uint16 SDL_ReadLE16 (SDL_RWops *src)
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   483
{
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   484
	Uint16 value;
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   485
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   486
	SDL_RWread(src, &value, (sizeof value), 1);
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   487
	return(SDL_SwapLE16(value));
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   488
}
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   489
Uint16 SDL_ReadBE16 (SDL_RWops *src)
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   490
{
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   491
	Uint16 value;
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   492
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   493
	SDL_RWread(src, &value, (sizeof value), 1);
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   494
	return(SDL_SwapBE16(value));
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   495
}
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   496
Uint32 SDL_ReadLE32 (SDL_RWops *src)
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   497
{
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   498
	Uint32 value;
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   499
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   500
	SDL_RWread(src, &value, (sizeof value), 1);
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   501
	return(SDL_SwapLE32(value));
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   502
}
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   503
Uint32 SDL_ReadBE32 (SDL_RWops *src)
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   504
{
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   505
	Uint32 value;
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   506
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   507
	SDL_RWread(src, &value, (sizeof value), 1);
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   508
	return(SDL_SwapBE32(value));
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   509
}
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   510
Uint64 SDL_ReadLE64 (SDL_RWops *src)
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   511
{
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   512
	Uint64 value;
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   513
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   514
	SDL_RWread(src, &value, (sizeof value), 1);
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   515
	return(SDL_SwapLE64(value));
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   516
}
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   517
Uint64 SDL_ReadBE64 (SDL_RWops *src)
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   518
{
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   519
	Uint64 value;
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   520
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   521
	SDL_RWread(src, &value, (sizeof value), 1);
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   522
	return(SDL_SwapBE64(value));
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   523
}
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   524
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   525
int SDL_WriteLE16 (SDL_RWops *dst, Uint16 value)
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   526
{
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   527
	value = SDL_SwapLE16(value);
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   528
	return(SDL_RWwrite(dst, &value, (sizeof value), 1));
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   529
}
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   530
int SDL_WriteBE16 (SDL_RWops *dst, Uint16 value)
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   531
{
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   532
	value = SDL_SwapBE16(value);
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   533
	return(SDL_RWwrite(dst, &value, (sizeof value), 1));
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   534
}
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   535
int SDL_WriteLE32 (SDL_RWops *dst, Uint32 value)
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   536
{
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   537
	value = SDL_SwapLE32(value);
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   538
	return(SDL_RWwrite(dst, &value, (sizeof value), 1));
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   539
}
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   540
int SDL_WriteBE32 (SDL_RWops *dst, Uint32 value)
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   541
{
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   542
	value = SDL_SwapBE32(value);
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   543
	return(SDL_RWwrite(dst, &value, (sizeof value), 1));
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   544
}
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   545
int SDL_WriteLE64 (SDL_RWops *dst, Uint64 value)
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   546
{
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   547
	value = SDL_SwapLE64(value);
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   548
	return(SDL_RWwrite(dst, &value, (sizeof value), 1));
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   549
}
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   550
int SDL_WriteBE64 (SDL_RWops *dst, Uint64 value)
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   551
{
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   552
	value = SDL_SwapBE64(value);
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   553
	return(SDL_RWwrite(dst, &value, (sizeof value), 1));
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   554
}