Mercurial > sdl-ios-xcode
annotate src/file/SDL_rwops.c @ 4329:9716da353104 SDL-1.2
Corrected my snd_pcm_writei fix.
Apparently ALSA says "frames" but it means samples...you don't split this into
groups by number of channels.
The adventure continues.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Tue, 13 Oct 2009 08:27:28 +0000 |
parents | 261ad7b40a31 |
children |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
4159 | 3 Copyright (C) 1997-2009 Sam Lantinga |
0 | 4 |
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 | 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 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
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 | 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 | 18 |
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 | 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 | 23 |
24 /* This file provides a general interface for SDL to read and write | |
25 data sources. It can easily be extended to files, memory, etc. | |
26 */ | |
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 | 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 |
3975 | 32 #if defined(__WIN32__) && !defined(__SYMBIAN32__) |
0 | 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 | 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 |
4026
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
46 #define READAHEAD_BUFFER_SIZE 1024 |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
47 |
1769 | 48 static int SDLCALL win32_file_open(SDL_RWops *context, const char *filename, const char *mode) |
1465
8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
49 { |
8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
50 #ifndef _WIN32_WCE |
1446
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
51 UINT old_error_mode; |
1465
8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
52 #endif |
1446
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
53 HANDLE h; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
54 DWORD r_right, w_right; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
55 DWORD must_exist, truncate; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
56 int a_mode; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
57 |
1455
f487bb150acc
Hah, standard stdio code crashed on the test case.
Sam Lantinga <slouken@libsdl.org>
parents:
1453
diff
changeset
|
58 if (!context) |
4038
eeb0862b9697
Simplified Win32 file opening code
Sam Lantinga <slouken@libsdl.org>
parents:
4035
diff
changeset
|
59 return -1; /* failed (invalid call) */ |
4039
7fd9a811efc7
Reverted most of r3200:3201: a malloc() failure would leave a zero-byte
Ryan C. Gordon <icculus@icculus.org>
parents:
4038
diff
changeset
|
60 |
7fd9a811efc7
Reverted most of r3200:3201: a malloc() failure would leave a zero-byte
Ryan C. Gordon <icculus@icculus.org>
parents:
4038
diff
changeset
|
61 context->hidden.win32io.h = INVALID_HANDLE_VALUE; /* mark this as unusable */ |
7fd9a811efc7
Reverted most of r3200:3201: a malloc() failure would leave a zero-byte
Ryan C. Gordon <icculus@icculus.org>
parents:
4038
diff
changeset
|
62 context->hidden.win32io.buffer.data = NULL; |
7fd9a811efc7
Reverted most of r3200:3201: a malloc() failure would leave a zero-byte
Ryan C. Gordon <icculus@icculus.org>
parents:
4038
diff
changeset
|
63 context->hidden.win32io.buffer.size = 0; |
7fd9a811efc7
Reverted most of r3200:3201: a malloc() failure would leave a zero-byte
Ryan C. Gordon <icculus@icculus.org>
parents:
4038
diff
changeset
|
64 context->hidden.win32io.buffer.left = 0; |
4026
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
65 |
1446
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
66 /* "r" = reading, file must exist */ |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
67 /* "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
|
68 /* "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
|
69 /* "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
|
70 /* "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
|
71 /* "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
|
72 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
73 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
|
74 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
|
75 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
|
76 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
|
77 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
|
78 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
79 if (!r_right && !w_right) /* inconsistent mode */ |
4038
eeb0862b9697
Simplified Win32 file opening code
Sam Lantinga <slouken@libsdl.org>
parents:
4035
diff
changeset
|
80 return -1; /* failed (invalid call) */ |
4035
3ccd06fc22e5
Don't leak the readahead buffer if win32 rwops file open fails.
Ryan C. Gordon <icculus@icculus.org>
parents:
4027
diff
changeset
|
81 |
4039
7fd9a811efc7
Reverted most of r3200:3201: a malloc() failure would leave a zero-byte
Ryan C. Gordon <icculus@icculus.org>
parents:
4038
diff
changeset
|
82 context->hidden.win32io.buffer.data = (char *)SDL_malloc(READAHEAD_BUFFER_SIZE); |
7fd9a811efc7
Reverted most of r3200:3201: a malloc() failure would leave a zero-byte
Ryan C. Gordon <icculus@icculus.org>
parents:
4038
diff
changeset
|
83 if (!context->hidden.win32io.buffer.data) { |
7fd9a811efc7
Reverted most of r3200:3201: a malloc() failure would leave a zero-byte
Ryan C. Gordon <icculus@icculus.org>
parents:
4038
diff
changeset
|
84 SDL_OutOfMemory(); |
7fd9a811efc7
Reverted most of r3200:3201: a malloc() failure would leave a zero-byte
Ryan C. Gordon <icculus@icculus.org>
parents:
4038
diff
changeset
|
85 return -1; |
7fd9a811efc7
Reverted most of r3200:3201: a malloc() failure would leave a zero-byte
Ryan C. Gordon <icculus@icculus.org>
parents:
4038
diff
changeset
|
86 } |
7fd9a811efc7
Reverted most of r3200:3201: a malloc() failure would leave a zero-byte
Ryan C. Gordon <icculus@icculus.org>
parents:
4038
diff
changeset
|
87 |
1465
8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
88 #ifdef _WIN32_WCE |
8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
89 { |
8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
90 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
|
91 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
|
92 |
8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
93 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
|
94 SDL_stack_free(filenameW); |
4039
7fd9a811efc7
Reverted most of r3200:3201: a malloc() failure would leave a zero-byte
Ryan C. Gordon <icculus@icculus.org>
parents:
4038
diff
changeset
|
95 SDL_free(context->hidden.win32io.buffer.data); |
7fd9a811efc7
Reverted most of r3200:3201: a malloc() failure would leave a zero-byte
Ryan C. Gordon <icculus@icculus.org>
parents:
4038
diff
changeset
|
96 context->hidden.win32io.buffer.data = NULL; |
4040
8515468091e3
Set the error after freeing stuff, just in case one of those functions resets
Ryan C. Gordon <icculus@icculus.org>
parents:
4039
diff
changeset
|
97 SDL_SetError("Unable to convert filename to Unicode"); |
1465
8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
98 return -1; |
8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
99 } |
8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
100 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
|
101 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
|
102 SDL_stack_free(filenameW); |
8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
103 } |
8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
104 #else |
4284
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
105 { |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
106 |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
107 /* handle Unicode filenames. We do some tapdancing here to make sure this |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
108 works on Win9x, which doesn't support anything but 1-byte codepages. */ |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
109 const size_t size = SDL_strlen(filename)+1; |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
110 static int unicode_support = -1; |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
111 |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
112 if (unicode_support == -1) { |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
113 OSVERSIONINFO osVerInfo; /* Information about the OS */ |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
114 osVerInfo.dwOSVersionInfoSize = sizeof(osVerInfo); |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
115 if (!GetVersionEx(&osVerInfo)) { |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
116 unicode_support = 0; |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
117 } else if (osVerInfo.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS) { |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
118 unicode_support = 1; /* Not Win95/98/ME. */ |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
119 } else { |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
120 unicode_support = 0; |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
121 } |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
122 } |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
123 |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
124 if (unicode_support) { /* everything but Win95/98/ME. */ |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
125 wchar_t *filenameW = SDL_stack_alloc(wchar_t, size); |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
126 if ( MultiByteToWideChar(CP_UTF8, 0, filename, -1, filenameW, size) == 0 ) { |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
127 SDL_stack_free(filenameW); |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
128 SDL_free(context->hidden.win32io.buffer.data); |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
129 context->hidden.win32io.buffer.data = NULL; |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
130 SDL_SetError("Unable to convert filename to Unicode"); |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
131 return -1; |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
132 } |
1465
8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
133 |
4284
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
134 /* Do not open a dialog box if failure */ |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
135 old_error_mode = SetErrorMode(SEM_NOOPENFILEERRORBOX|SEM_FAILCRITICALERRORS); |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
136 h = CreateFileW(filenameW, (w_right|r_right), (w_right)? 0 : FILE_SHARE_READ, |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
137 NULL, (must_exist|truncate|a_mode), FILE_ATTRIBUTE_NORMAL,NULL); |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
138 /* restore old behaviour */ |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
139 SetErrorMode(old_error_mode); |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
140 |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
141 SDL_stack_free(filenameW); |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
142 } else { |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
143 /* CP_UTF8 might not be supported (Win95), so use SDL_iconv to get wchars. */ |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
144 /* Use UCS2: no UTF-16 support here. Try again in SDL 1.3. :) */ |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
145 char *utf16 = SDL_iconv_string("UCS2", "UTF8", filename, SDL_strlen(filename) + 1); |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
146 char *filenameA = SDL_stack_alloc(char, size * 6); /* 6, just in case. */ |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
147 BOOL bDefCharUsed = FALSE; |
1465
8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
148 |
4284
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
149 /* Dither down to a codepage and hope for the best. */ |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
150 if (!utf16 || |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
151 !WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)utf16, -1, filenameA, size*6, 0, &bDefCharUsed) || |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
152 bDefCharUsed) { |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
153 SDL_stack_free(filenameA); |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
154 SDL_free(utf16); |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
155 SDL_free(context->hidden.win32io.buffer.data); |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
156 context->hidden.win32io.buffer.data = NULL; |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
157 SDL_SetError("Unable to convert filename to Unicode"); |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
158 return -1; |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
159 } |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
160 |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
161 /* Do not open a dialog box if failure */ |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
162 old_error_mode = SetErrorMode(SEM_NOOPENFILEERRORBOX|SEM_FAILCRITICALERRORS); |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
163 h = CreateFile(filenameA, (w_right|r_right), (w_right)? 0 : FILE_SHARE_READ, |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
164 NULL, (must_exist|truncate|a_mode), FILE_ATTRIBUTE_NORMAL,NULL); |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
165 /* restore old behaviour */ |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
166 SetErrorMode(old_error_mode); |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
167 |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
168 SDL_stack_free(filenameA); |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
169 SDL_free(utf16); |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
170 } |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
171 |
261ad7b40a31
Allow Unicode filenames in RWOPS on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
172 } |
1465
8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
173 #endif /* _WIN32_WCE */ |
1446
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
174 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
175 if (h==INVALID_HANDLE_VALUE) { |
4039
7fd9a811efc7
Reverted most of r3200:3201: a malloc() failure would leave a zero-byte
Ryan C. Gordon <icculus@icculus.org>
parents:
4038
diff
changeset
|
176 SDL_free(context->hidden.win32io.buffer.data); |
7fd9a811efc7
Reverted most of r3200:3201: a malloc() failure would leave a zero-byte
Ryan C. Gordon <icculus@icculus.org>
parents:
4038
diff
changeset
|
177 context->hidden.win32io.buffer.data = NULL; |
4040
8515468091e3
Set the error after freeing stuff, just in case one of those functions resets
Ryan C. Gordon <icculus@icculus.org>
parents:
4039
diff
changeset
|
178 SDL_SetError("Couldn't open %s",filename); |
1446
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
179 return -2; /* failed (CreateFile) */ |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
180 } |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
181 context->hidden.win32io.h = h; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
182 context->hidden.win32io.append = a_mode; |
4035
3ccd06fc22e5
Don't leak the readahead buffer if win32 rwops file open fails.
Ryan C. Gordon <icculus@icculus.org>
parents:
4027
diff
changeset
|
183 |
1446
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
184 return 0; /* ok */ |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
185 } |
1769 | 186 static int SDLCALL win32_file_seek(SDL_RWops *context, int offset, int whence) |
1465
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 DWORD win32whence; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
189 int file_pos; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
190 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
191 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
|
192 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
|
193 return -1; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
194 } |
4026
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
195 |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
196 /* FIXME: We may be able to satisfy the seek within buffered data */ |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
197 if (whence == RW_SEEK_CUR && context->hidden.win32io.buffer.left) { |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
198 offset -= context->hidden.win32io.buffer.left; |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
199 } |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
200 context->hidden.win32io.buffer.left = 0; |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
201 |
1446
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
202 switch (whence) { |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
203 case RW_SEEK_SET: |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
204 win32whence = FILE_BEGIN; break; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
205 case RW_SEEK_CUR: |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
206 win32whence = FILE_CURRENT; break; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
207 case RW_SEEK_END: |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
208 win32whence = FILE_END; break; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
209 default: |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
210 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
|
211 return -1; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
212 } |
4026
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
213 |
1446
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
214 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
|
215 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
216 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
|
217 return file_pos; /* success */ |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
218 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
219 SDL_Error(SDL_EFSEEK); |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
220 return -1; /* error */ |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
221 } |
1769 | 222 static int SDLCALL win32_file_read(SDL_RWops *context, void *ptr, int size, int maxnum) |
1465
8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
223 { |
4026
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
224 int total_need; |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
225 int total_read = 0; |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
226 int read_ahead; |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
227 DWORD byte_read; |
1446
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
228 |
4026
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
229 total_need = size*maxnum; |
1446
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
230 |
4026
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
231 if (!context || context->hidden.win32io.h == INVALID_HANDLE_VALUE || total_need<=0 || !size) |
1446
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
232 return 0; |
4026
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
233 |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
234 if (context->hidden.win32io.buffer.left > 0) { |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
235 void *data = (char *)context->hidden.win32io.buffer.data + |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
236 context->hidden.win32io.buffer.size - |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
237 context->hidden.win32io.buffer.left; |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
238 read_ahead = SDL_min(total_need, context->hidden.win32io.buffer.left); |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
239 SDL_memcpy(ptr, data, read_ahead); |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
240 context->hidden.win32io.buffer.left -= read_ahead; |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
241 |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
242 if (read_ahead == total_need) { |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
243 return maxnum; |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
244 } |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
245 ptr = (char *)ptr + read_ahead; |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
246 total_need -= read_ahead; |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
247 total_read += read_ahead; |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
248 } |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
249 |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
250 if (total_need < READAHEAD_BUFFER_SIZE) { |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
251 if (!ReadFile(context->hidden.win32io.h,context->hidden.win32io.buffer.data,READAHEAD_BUFFER_SIZE,&byte_read,NULL)) { |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
252 SDL_Error(SDL_EFREAD); |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
253 return 0; |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
254 } |
4027
407ecf3ad3b3
Fixed signed/unsigned mismatch ... hmm, limited to 2 GB reads? Fix in SDL 1.3
Sam Lantinga <slouken@libsdl.org>
parents:
4026
diff
changeset
|
255 read_ahead = SDL_min(total_need, (int)byte_read); |
4026
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
256 SDL_memcpy(ptr, context->hidden.win32io.buffer.data, read_ahead); |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
257 context->hidden.win32io.buffer.size = byte_read; |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
258 context->hidden.win32io.buffer.left = byte_read-read_ahead; |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
259 total_read += read_ahead; |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
260 } else { |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
261 if (!ReadFile(context->hidden.win32io.h,ptr,total_need,&byte_read,NULL)) { |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
262 SDL_Error(SDL_EFREAD); |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
263 return 0; |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
264 } |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
265 total_read += byte_read; |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
266 } |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
267 return (total_read/size); |
1446
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
268 } |
1769 | 269 static int SDLCALL win32_file_write(SDL_RWops *context, const void *ptr, int size, int num) |
1465
8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
270 { |
1446
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
271 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
272 int total_bytes; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
273 DWORD byte_written,nwritten; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
274 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
275 total_bytes = size*num; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
276 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
277 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
|
278 return 0; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
279 |
4026
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
280 if (context->hidden.win32io.buffer.left) { |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
281 SetFilePointer(context->hidden.win32io.h,-context->hidden.win32io.buffer.left,NULL,FILE_CURRENT); |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
282 context->hidden.win32io.buffer.left = 0; |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
283 } |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
284 |
1446
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
285 /* 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
|
286 if (context->hidden.win32io.append) { |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
287 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
|
288 SDL_Error(SDL_EFWRITE); |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
289 return 0; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
290 } |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
291 } |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
292 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
293 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
|
294 SDL_Error(SDL_EFWRITE); |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
295 return 0; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
296 } |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
297 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
298 nwritten = byte_written/size; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
299 return nwritten; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
300 } |
1769 | 301 static int SDLCALL win32_file_close(SDL_RWops *context) |
1465
8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
302 { |
1446
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
303 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
304 if ( context ) { |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
305 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
|
306 CloseHandle(context->hidden.win32io.h); |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
307 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
|
308 } |
4026
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
309 if (context->hidden.win32io.buffer.data) { |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
310 SDL_free(context->hidden.win32io.buffer.data); |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
311 context->hidden.win32io.buffer.data = NULL; |
255b0469ca83
Added read-ahead support for Win32 file IO
Sam Lantinga <slouken@libsdl.org>
parents:
3975
diff
changeset
|
312 } |
1446
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
313 SDL_FreeRW(context); |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
314 } |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
315 return(0); |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
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 #endif /* __WIN32__ */ |
1446
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
318 |
1447
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
319 #ifdef HAVE_STDIO_H |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
320 |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
321 /* 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
|
322 |
1769 | 323 static int SDLCALL stdio_seek(SDL_RWops *context, int offset, int whence) |
1447
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
324 { |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
325 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
|
326 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
|
327 } else { |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
328 SDL_Error(SDL_EFSEEK); |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
329 return(-1); |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
330 } |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
331 } |
1769 | 332 static int SDLCALL stdio_read(SDL_RWops *context, void *ptr, int size, int maxnum) |
1447
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
333 { |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
334 size_t nread; |
1446
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
335 |
1447
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
336 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
|
337 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
|
338 SDL_Error(SDL_EFREAD); |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
339 } |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
340 return(nread); |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
341 } |
1769 | 342 static int SDLCALL stdio_write(SDL_RWops *context, const void *ptr, int size, int num) |
1447
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
343 { |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
344 size_t nwrote; |
1446
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
345 |
1447
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
346 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
|
347 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
|
348 SDL_Error(SDL_EFWRITE); |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
349 } |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
350 return(nwrote); |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
351 } |
1769 | 352 static int SDLCALL stdio_close(SDL_RWops *context) |
1447
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
353 { |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
354 if ( context ) { |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
355 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
|
356 /* 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
|
357 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
|
358 } |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
359 SDL_FreeRW(context); |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
360 } |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
361 return(0); |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
362 } |
1446
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
363 #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
|
364 |
0 | 365 /* Functions to read/write memory pointers */ |
366 | |
1769 | 367 static int SDLCALL mem_seek(SDL_RWops *context, int offset, int whence) |
0 | 368 { |
369 Uint8 *newpos; | |
370 | |
371 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
|
372 case RW_SEEK_SET: |
0 | 373 newpos = context->hidden.mem.base+offset; |
374 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
|
375 case RW_SEEK_CUR: |
0 | 376 newpos = context->hidden.mem.here+offset; |
377 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
|
378 case RW_SEEK_END: |
0 | 379 newpos = context->hidden.mem.stop+offset; |
380 break; | |
381 default: | |
382 SDL_SetError("Unknown value for 'whence'"); | |
383 return(-1); | |
384 } | |
385 if ( newpos < context->hidden.mem.base ) { | |
386 newpos = context->hidden.mem.base; | |
387 } | |
388 if ( newpos > context->hidden.mem.stop ) { | |
389 newpos = context->hidden.mem.stop; | |
390 } | |
391 context->hidden.mem.here = newpos; | |
392 return(context->hidden.mem.here-context->hidden.mem.base); | |
393 } | |
1769 | 394 static int SDLCALL mem_read(SDL_RWops *context, void *ptr, int size, int maxnum) |
0 | 395 { |
1456
84de7511f79f
Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents:
1455
diff
changeset
|
396 size_t total_bytes; |
84de7511f79f
Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents:
1455
diff
changeset
|
397 size_t mem_available; |
1078
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
398 |
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
399 total_bytes = (maxnum * size); |
1465
8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
400 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
|
401 return 0; |
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
402 } |
0 | 403 |
1078
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
404 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
|
405 if (total_bytes > mem_available) { |
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
406 total_bytes = mem_available; |
0 | 407 } |
1078
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
408 |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
409 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
|
410 context->hidden.mem.here += total_bytes; |
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
411 |
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
412 return (total_bytes / size); |
0 | 413 } |
1769 | 414 static int SDLCALL mem_write(SDL_RWops *context, const void *ptr, int size, int num) |
0 | 415 { |
416 if ( (context->hidden.mem.here + (num*size)) > context->hidden.mem.stop ) { | |
417 num = (context->hidden.mem.stop-context->hidden.mem.here)/size; | |
418 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
419 SDL_memcpy(context->hidden.mem.here, ptr, num*size); |
0 | 420 context->hidden.mem.here += num*size; |
421 return(num); | |
422 } | |
1769 | 423 static int SDLCALL mem_writeconst(SDL_RWops *context, const void *ptr, int size, int num) |
764
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
424 { |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
425 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
|
426 return(-1); |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
427 } |
1769 | 428 static int SDLCALL mem_close(SDL_RWops *context) |
0 | 429 { |
430 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
|
431 SDL_FreeRW(context); |
0 | 432 } |
433 return(0); | |
434 } | |
435 | |
1447
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
436 |
0 | 437 /* Functions to create SDL_RWops structures from various data sources */ |
438 | |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
439 #ifdef __MACOS__ |
0 | 440 /* |
441 * translate unix-style slash-separated filename to mac-style colon-separated | |
442 * name; return malloced string | |
443 */ | |
444 static char *unix_to_mac(const char *file) | |
445 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
446 int flen = SDL_strlen(file); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
447 char *path = SDL_malloc(flen + 2); |
0 | 448 const char *src = file; |
449 char *dst = path; | |
450 if(*src == '/') { | |
451 /* really depends on filesystem layout, hope for the best */ | |
452 src++; | |
453 } else { | |
454 /* Check if this is a MacOS path to begin with */ | |
455 if(*src != ':') | |
456 *dst++ = ':'; /* relative paths begin with ':' */ | |
457 } | |
458 while(src < file + flen) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
459 const char *end = SDL_strchr(src, '/'); |
0 | 460 int len; |
461 if(!end) | |
462 end = file + flen; /* last component */ | |
463 len = end - src; | |
464 if(len == 0 || (len == 1 && src[0] == '.')) { | |
465 /* remove repeated slashes and . */ | |
466 } else { | |
467 if(len == 2 && src[0] == '.' && src[1] == '.') { | |
468 /* replace .. with the empty string */ | |
469 } else { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
470 SDL_memcpy(dst, src, len); |
0 | 471 dst += len; |
472 } | |
473 if(end < file + flen) | |
474 *dst++ = ':'; | |
475 } | |
476 src = end + 1; | |
477 } | |
478 *dst++ = '\0'; | |
479 return path; | |
480 } | |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
481 #endif /* __MACOS__ */ |
0 | 482 |
483 SDL_RWops *SDL_RWFromFile(const char *file, const char *mode) | |
484 { | |
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
|
485 SDL_RWops *rwops = NULL; |
1465
8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
486 #ifdef HAVE_STDIO_H |
8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
487 FILE *fp = NULL; |
8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
488 #endif |
1455
f487bb150acc
Hah, standard stdio code crashed on the test case.
Sam Lantinga <slouken@libsdl.org>
parents:
1453
diff
changeset
|
489 if ( !file || !*file || !mode || !*mode ) { |
f487bb150acc
Hah, standard stdio code crashed on the test case.
Sam Lantinga <slouken@libsdl.org>
parents:
1453
diff
changeset
|
490 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
|
491 return NULL; |
f487bb150acc
Hah, standard stdio code crashed on the test case.
Sam Lantinga <slouken@libsdl.org>
parents:
1453
diff
changeset
|
492 } |
f487bb150acc
Hah, standard stdio code crashed on the test case.
Sam Lantinga <slouken@libsdl.org>
parents:
1453
diff
changeset
|
493 |
3975 | 494 #if defined(__WIN32__) && !defined(__SYMBIAN32__) |
1447
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
495 rwops = SDL_AllocRW(); |
1453
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1447
diff
changeset
|
496 if (!rwops) |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1447
diff
changeset
|
497 return NULL; /* SDL_SetError already setup by SDL_AllocRW() */ |
4038
eeb0862b9697
Simplified Win32 file opening code
Sam Lantinga <slouken@libsdl.org>
parents:
4035
diff
changeset
|
498 if (win32_file_open(rwops,file,mode) < 0) { |
1447
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
499 SDL_FreeRW(rwops); |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
500 return NULL; |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
501 } |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
502 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
|
503 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
|
504 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
|
505 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
|
506 |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
507 #elif HAVE_STDIO_H |
0 | 508 |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
509 #ifdef __MACOS__ |
0 | 510 { |
511 char *mpath = unix_to_mac(file); | |
512 fp = fopen(mpath, mode); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
513 SDL_free(mpath); |
0 | 514 } |
515 #else | |
516 fp = fopen(file, mode); | |
517 #endif | |
518 if ( fp == NULL ) { | |
519 SDL_SetError("Couldn't open %s", file); | |
520 } else { | |
521 rwops = SDL_RWFromFP(fp, 1); | |
522 } | |
1447
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
523 #else |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
524 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
|
525 #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
|
526 |
0 | 527 return(rwops); |
528 } | |
529 | |
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
|
530 #ifdef HAVE_STDIO_H |
0 | 531 SDL_RWops *SDL_RWFromFP(FILE *fp, int autoclose) |
532 { | |
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
|
533 SDL_RWops *rwops = NULL; |
0 | 534 |
535 rwops = SDL_AllocRW(); | |
536 if ( rwops != NULL ) { | |
537 rwops->seek = stdio_seek; | |
538 rwops->read = stdio_read; | |
539 rwops->write = stdio_write; | |
540 rwops->close = stdio_close; | |
541 rwops->hidden.stdio.fp = fp; | |
542 rwops->hidden.stdio.autoclose = autoclose; | |
543 } | |
544 return(rwops); | |
545 } | |
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
|
546 #endif /* HAVE_STDIO_H */ |
0 | 547 |
548 SDL_RWops *SDL_RWFromMem(void *mem, int size) | |
549 { | |
550 SDL_RWops *rwops; | |
551 | |
552 rwops = SDL_AllocRW(); | |
553 if ( rwops != NULL ) { | |
554 rwops->seek = mem_seek; | |
555 rwops->read = mem_read; | |
556 rwops->write = mem_write; | |
557 rwops->close = mem_close; | |
558 rwops->hidden.mem.base = (Uint8 *)mem; | |
559 rwops->hidden.mem.here = rwops->hidden.mem.base; | |
560 rwops->hidden.mem.stop = rwops->hidden.mem.base+size; | |
561 } | |
562 return(rwops); | |
563 } | |
564 | |
764
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
565 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
|
566 { |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
567 SDL_RWops *rwops; |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
568 |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
569 rwops = SDL_AllocRW(); |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
570 if ( rwops != NULL ) { |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
571 rwops->seek = mem_seek; |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
572 rwops->read = mem_read; |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
573 rwops->write = mem_writeconst; |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
574 rwops->close = mem_close; |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
575 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
|
576 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
|
577 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
|
578 } |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
579 return(rwops); |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
580 } |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
581 |
0 | 582 SDL_RWops *SDL_AllocRW(void) |
583 { | |
584 SDL_RWops *area; | |
585 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
586 area = (SDL_RWops *)SDL_malloc(sizeof *area); |
0 | 587 if ( area == NULL ) { |
588 SDL_OutOfMemory(); | |
589 } | |
590 return(area); | |
591 } | |
592 | |
593 void SDL_FreeRW(SDL_RWops *area) | |
594 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
595 SDL_free(area); |
0 | 596 } |
1354
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
597 |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
598 /* 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
|
599 |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
600 Uint16 SDL_ReadLE16 (SDL_RWops *src) |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
601 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
602 Uint16 value; |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
603 |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
604 SDL_RWread(src, &value, (sizeof value), 1); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
605 return(SDL_SwapLE16(value)); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
606 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
607 Uint16 SDL_ReadBE16 (SDL_RWops *src) |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
608 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
609 Uint16 value; |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
610 |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
611 SDL_RWread(src, &value, (sizeof value), 1); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
612 return(SDL_SwapBE16(value)); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
613 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
614 Uint32 SDL_ReadLE32 (SDL_RWops *src) |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
615 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
616 Uint32 value; |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
617 |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
618 SDL_RWread(src, &value, (sizeof value), 1); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
619 return(SDL_SwapLE32(value)); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
620 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
621 Uint32 SDL_ReadBE32 (SDL_RWops *src) |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
622 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
623 Uint32 value; |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
624 |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
625 SDL_RWread(src, &value, (sizeof value), 1); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
626 return(SDL_SwapBE32(value)); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
627 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
628 Uint64 SDL_ReadLE64 (SDL_RWops *src) |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
629 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
630 Uint64 value; |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
631 |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
632 SDL_RWread(src, &value, (sizeof value), 1); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
633 return(SDL_SwapLE64(value)); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
634 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
635 Uint64 SDL_ReadBE64 (SDL_RWops *src) |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
636 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
637 Uint64 value; |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
638 |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
639 SDL_RWread(src, &value, (sizeof value), 1); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
640 return(SDL_SwapBE64(value)); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
641 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
642 |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
643 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
|
644 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
645 value = SDL_SwapLE16(value); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
646 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
|
647 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
648 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
|
649 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
650 value = SDL_SwapBE16(value); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
651 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
|
652 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
653 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
|
654 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
655 value = SDL_SwapLE32(value); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
656 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
|
657 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
658 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
|
659 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
660 value = SDL_SwapBE32(value); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
661 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
|
662 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
663 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
|
664 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
665 value = SDL_SwapLE64(value); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
666 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
|
667 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
668 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
|
669 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
670 value = SDL_SwapBE64(value); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
671 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
|
672 } |