Mercurial > sdl-ios-xcode
annotate src/file/SDL_rwops.c @ 1447:515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 27 Feb 2006 04:16:44 +0000 |
parents | 47bf1767c4ca |
children | 2eb75f8a32ca |
rev | line source |
---|---|
0 | 1 /* |
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 | 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 |
1447
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
32 #ifdef __WIN32__ |
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 */ |
0 | 35 |
1446
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
36 #define WINDOWS_LEAN_AND_MEAN |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
37 #include <windows.h> |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
38 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
39 static int win32_file_open(SDL_RWops *context, const char *filename, const char *mode) { |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
40 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
41 UINT old_error_mode; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
42 HANDLE h; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
43 DWORD r_right, w_right; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
44 DWORD must_exist, truncate; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
45 int a_mode; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
46 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
47 if (!context || !filename || !mode) |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
48 return -1; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
49 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
50 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
|
51 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
52 /* "r" = reading, file must exist */ |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
53 /* "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
|
54 /* "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
|
55 /* "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
|
56 /* "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
|
57 /* "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
|
58 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
59 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
|
60 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
|
61 r_right = ( SDL_strchr(mode,'+') != NULL || must_exist ) ? GENERIC_READ : 0; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
62 a_mode = ( SDL_strchr(mode,'a') != NULL ); |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
63 w_right = ( a_mode || SDL_strchr(mode,'w') || truncate ) ? GENERIC_WRITE : 0; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
64 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
65 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
|
66 return -1; /* failed (invalid call)*/ |
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 /* Do not open a dialog box if failure */ |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
69 old_error_mode = SetErrorMode(SEM_NOOPENFILEERRORBOX|SEM_FAILCRITICALERRORS); |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
70 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
71 h = CreateFile(filename, (w_right|r_right), (w_right)? 0 : FILE_SHARE_READ, |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
72 NULL, (must_exist|truncate), FILE_ATTRIBUTE_NORMAL,NULL); |
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 /* restore old behaviour */ |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
75 SetErrorMode(old_error_mode); |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
76 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
77 if (h==INVALID_HANDLE_VALUE) { |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
78 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
|
79 return -2; /* failed (CreateFile) */ |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
80 } |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
81 context->hidden.win32io.h = h; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
82 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
|
83 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
84 return 0; /* ok */ |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
85 } |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
86 static int win32_file_seek(SDL_RWops *context, int offset, int whence) { |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
87 DWORD win32whence; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
88 int file_pos; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
89 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
90 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
|
91 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
|
92 return -1; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
93 } |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
94 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
95 switch (whence) { |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
96 case RW_SEEK_SET: |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
97 win32whence = FILE_BEGIN; break; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
98 case RW_SEEK_CUR: |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
99 win32whence = FILE_CURRENT; break; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
100 case RW_SEEK_END: |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
101 win32whence = FILE_END; break; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
102 default: |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
103 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
|
104 return -1; |
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 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
107 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
|
108 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
109 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
|
110 return file_pos; /* success */ |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
111 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
112 SDL_Error(SDL_EFSEEK); |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
113 return -1; /* error */ |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
114 } |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
115 static int win32_file_read(SDL_RWops *context, void *ptr, int size, int maxnum) { |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
116 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
117 int total_bytes; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
118 DWORD byte_read,nread; |
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 total_bytes = size*maxnum; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
121 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
122 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
|
123 return 0; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
124 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
125 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
|
126 SDL_Error(SDL_EFREAD); |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
127 return 0; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
128 } |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
129 nread = byte_read/size; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
130 return nread; |
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 static int win32_file_write(SDL_RWops *context, const void *ptr, int size, int num) { |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
133 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
134 int total_bytes; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
135 DWORD byte_written,nwritten; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
136 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
137 total_bytes = size*num; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
138 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
139 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
|
140 return 0; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
141 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
142 /* 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
|
143 if (context->hidden.win32io.append) { |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
144 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
|
145 SDL_Error(SDL_EFWRITE); |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
146 return 0; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
147 } |
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 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
150 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
|
151 SDL_Error(SDL_EFWRITE); |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
152 return 0; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
153 } |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
154 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
155 nwritten = byte_written/size; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
156 return nwritten; |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
157 } |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
158 static int win32_file_close(SDL_RWops *context) { |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
159 |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
160 if ( context ) { |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
161 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
|
162 CloseHandle(context->hidden.win32io.h); |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
163 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
|
164 } |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
165 SDL_FreeRW(context); |
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 return(0); |
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
168 } |
1447
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
169 #endif /* __WIN32__ */ |
1446
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
170 |
1447
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
171 #ifdef HAVE_STDIO_H |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
172 |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
173 /* 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
|
174 |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
175 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
|
176 { |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
177 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
|
178 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
|
179 } else { |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
180 SDL_Error(SDL_EFSEEK); |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
181 return(-1); |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
182 } |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
183 } |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
184 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
|
185 { |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
186 size_t nread; |
1446
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
187 |
1447
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
188 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
|
189 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
|
190 SDL_Error(SDL_EFREAD); |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
191 } |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
192 return(nread); |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
193 } |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
194 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
|
195 { |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
196 size_t nwrote; |
1446
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 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
|
199 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
|
200 SDL_Error(SDL_EFWRITE); |
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 return(nwrote); |
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_close(SDL_RWops *context) |
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 ( context ) { |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
207 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
|
208 /* 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
|
209 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
|
210 } |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
211 SDL_FreeRW(context); |
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 return(0); |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
214 } |
1446
47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
215 #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
|
216 |
0 | 217 /* Functions to read/write memory pointers */ |
218 | |
219 static int mem_seek(SDL_RWops *context, int offset, int whence) | |
220 { | |
221 Uint8 *newpos; | |
222 | |
223 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
|
224 case RW_SEEK_SET: |
0 | 225 newpos = context->hidden.mem.base+offset; |
226 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
|
227 case RW_SEEK_CUR: |
0 | 228 newpos = context->hidden.mem.here+offset; |
229 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
|
230 case RW_SEEK_END: |
0 | 231 newpos = context->hidden.mem.stop+offset; |
232 break; | |
233 default: | |
234 SDL_SetError("Unknown value for 'whence'"); | |
235 return(-1); | |
236 } | |
237 if ( newpos < context->hidden.mem.base ) { | |
238 newpos = context->hidden.mem.base; | |
239 } | |
240 if ( newpos > context->hidden.mem.stop ) { | |
241 newpos = context->hidden.mem.stop; | |
242 } | |
243 context->hidden.mem.here = newpos; | |
244 return(context->hidden.mem.here-context->hidden.mem.base); | |
245 } | |
246 static int mem_read(SDL_RWops *context, void *ptr, int size, int maxnum) | |
247 { | |
1078
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
248 int total_bytes; |
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
249 int mem_available; |
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
250 |
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
251 total_bytes = (maxnum * size); |
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
252 if ( (maxnum <= 0) || (size <= 0) || ((total_bytes / maxnum) != size) ) { |
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
253 return 0; |
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
254 } |
0 | 255 |
1078
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
256 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
|
257 if (total_bytes > mem_available) { |
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
258 total_bytes = mem_available; |
0 | 259 } |
1078
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
260 |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
261 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
|
262 context->hidden.mem.here += total_bytes; |
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
263 |
e2ef6b7001fd
Patch from Antonio SJ Musumeci:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
264 return (total_bytes / size); |
0 | 265 } |
266 static int mem_write(SDL_RWops *context, const void *ptr, int size, int num) | |
267 { | |
268 if ( (context->hidden.mem.here + (num*size)) > context->hidden.mem.stop ) { | |
269 num = (context->hidden.mem.stop-context->hidden.mem.here)/size; | |
270 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
271 SDL_memcpy(context->hidden.mem.here, ptr, num*size); |
0 | 272 context->hidden.mem.here += num*size; |
273 return(num); | |
274 } | |
764
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
275 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
|
276 { |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
277 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
|
278 return(-1); |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
279 } |
0 | 280 static int mem_close(SDL_RWops *context) |
281 { | |
282 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
|
283 SDL_FreeRW(context); |
0 | 284 } |
285 return(0); | |
286 } | |
287 | |
1447
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
288 |
0 | 289 /* Functions to create SDL_RWops structures from various data sources */ |
290 | |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
291 #ifdef __MACOS__ |
0 | 292 /* |
293 * translate unix-style slash-separated filename to mac-style colon-separated | |
294 * name; return malloced string | |
295 */ | |
296 static char *unix_to_mac(const char *file) | |
297 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
298 int flen = SDL_strlen(file); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
299 char *path = SDL_malloc(flen + 2); |
0 | 300 const char *src = file; |
301 char *dst = path; | |
302 if(*src == '/') { | |
303 /* really depends on filesystem layout, hope for the best */ | |
304 src++; | |
305 } else { | |
306 /* Check if this is a MacOS path to begin with */ | |
307 if(*src != ':') | |
308 *dst++ = ':'; /* relative paths begin with ':' */ | |
309 } | |
310 while(src < file + flen) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
311 const char *end = SDL_strchr(src, '/'); |
0 | 312 int len; |
313 if(!end) | |
314 end = file + flen; /* last component */ | |
315 len = end - src; | |
316 if(len == 0 || (len == 1 && src[0] == '.')) { | |
317 /* remove repeated slashes and . */ | |
318 } else { | |
319 if(len == 2 && src[0] == '.' && src[1] == '.') { | |
320 /* replace .. with the empty string */ | |
321 } else { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
322 SDL_memcpy(dst, src, len); |
0 | 323 dst += len; |
324 } | |
325 if(end < file + flen) | |
326 *dst++ = ':'; | |
327 } | |
328 src = end + 1; | |
329 } | |
330 *dst++ = '\0'; | |
331 return path; | |
332 } | |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
333 #endif /* __MACOS__ */ |
0 | 334 |
335 SDL_RWops *SDL_RWFromFile(const char *file, const char *mode) | |
336 { | |
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
|
337 SDL_RWops *rwops = NULL; |
1447
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
338 |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
339 #ifdef __WIN32__ |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
340 rwops = SDL_AllocRW(); |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
341 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
|
342 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
|
343 SDL_FreeRW(rwops); |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
344 return NULL; |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
345 } |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
346 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
|
347 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
|
348 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
|
349 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
|
350 |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
351 #elif HAVE_STDIO_H |
0 | 352 FILE *fp; |
353 | |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
354 #ifdef __MACOS__ |
0 | 355 { |
356 char *mpath = unix_to_mac(file); | |
357 fp = fopen(mpath, mode); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
358 SDL_free(mpath); |
0 | 359 } |
360 #else | |
361 fp = fopen(file, mode); | |
362 #endif | |
363 if ( fp == NULL ) { | |
364 SDL_SetError("Couldn't open %s", file); | |
365 } else { | |
366 rwops = SDL_RWFromFP(fp, 1); | |
367 } | |
1447
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
368 #else |
515df0086eb7
Prefer the raw Win32 API over stdio for file RWops
Sam Lantinga <slouken@libsdl.org>
parents:
1446
diff
changeset
|
369 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
|
370 #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
|
371 |
0 | 372 return(rwops); |
373 } | |
374 | |
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 #ifdef HAVE_STDIO_H |
0 | 376 SDL_RWops *SDL_RWFromFP(FILE *fp, int autoclose) |
377 { | |
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 SDL_RWops *rwops = NULL; |
0 | 379 |
380 rwops = SDL_AllocRW(); | |
381 if ( rwops != NULL ) { | |
382 rwops->seek = stdio_seek; | |
383 rwops->read = stdio_read; | |
384 rwops->write = stdio_write; | |
385 rwops->close = stdio_close; | |
386 rwops->hidden.stdio.fp = fp; | |
387 rwops->hidden.stdio.autoclose = autoclose; | |
388 } | |
389 return(rwops); | |
390 } | |
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
|
391 #endif /* HAVE_STDIO_H */ |
0 | 392 |
393 SDL_RWops *SDL_RWFromMem(void *mem, int size) | |
394 { | |
395 SDL_RWops *rwops; | |
396 | |
397 rwops = SDL_AllocRW(); | |
398 if ( rwops != NULL ) { | |
399 rwops->seek = mem_seek; | |
400 rwops->read = mem_read; | |
401 rwops->write = mem_write; | |
402 rwops->close = mem_close; | |
403 rwops->hidden.mem.base = (Uint8 *)mem; | |
404 rwops->hidden.mem.here = rwops->hidden.mem.base; | |
405 rwops->hidden.mem.stop = rwops->hidden.mem.base+size; | |
406 } | |
407 return(rwops); | |
408 } | |
409 | |
764
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
410 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
|
411 { |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
412 SDL_RWops *rwops; |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
413 |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
414 rwops = SDL_AllocRW(); |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
415 if ( rwops != NULL ) { |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
416 rwops->seek = mem_seek; |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
417 rwops->read = mem_read; |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
418 rwops->write = mem_writeconst; |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
419 rwops->close = mem_close; |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
420 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
|
421 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
|
422 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
|
423 } |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
424 return(rwops); |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
425 } |
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
543
diff
changeset
|
426 |
0 | 427 SDL_RWops *SDL_AllocRW(void) |
428 { | |
429 SDL_RWops *area; | |
430 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
431 area = (SDL_RWops *)SDL_malloc(sizeof *area); |
0 | 432 if ( area == NULL ) { |
433 SDL_OutOfMemory(); | |
434 } | |
435 return(area); | |
436 } | |
437 | |
438 void SDL_FreeRW(SDL_RWops *area) | |
439 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
440 SDL_free(area); |
0 | 441 } |
1354
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
442 |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
443 /* 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
|
444 |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
445 Uint16 SDL_ReadLE16 (SDL_RWops *src) |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
446 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
447 Uint16 value; |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
448 |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
449 SDL_RWread(src, &value, (sizeof value), 1); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
450 return(SDL_SwapLE16(value)); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
451 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
452 Uint16 SDL_ReadBE16 (SDL_RWops *src) |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
453 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
454 Uint16 value; |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
455 |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
456 SDL_RWread(src, &value, (sizeof value), 1); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
457 return(SDL_SwapBE16(value)); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
458 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
459 Uint32 SDL_ReadLE32 (SDL_RWops *src) |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
460 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
461 Uint32 value; |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
462 |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
463 SDL_RWread(src, &value, (sizeof value), 1); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
464 return(SDL_SwapLE32(value)); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
465 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
466 Uint32 SDL_ReadBE32 (SDL_RWops *src) |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
467 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
468 Uint32 value; |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
469 |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
470 SDL_RWread(src, &value, (sizeof value), 1); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
471 return(SDL_SwapBE32(value)); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
472 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
473 Uint64 SDL_ReadLE64 (SDL_RWops *src) |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
474 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
475 Uint64 value; |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
476 |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
477 SDL_RWread(src, &value, (sizeof value), 1); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
478 return(SDL_SwapLE64(value)); |
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 Uint64 SDL_ReadBE64 (SDL_RWops *src) |
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 Uint64 value; |
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 SDL_RWread(src, &value, (sizeof value), 1); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
485 return(SDL_SwapBE64(value)); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
486 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
487 |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
488 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
|
489 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
490 value = SDL_SwapLE16(value); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
491 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
|
492 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
493 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
|
494 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
495 value = SDL_SwapBE16(value); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
496 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
|
497 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
498 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
|
499 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
500 value = SDL_SwapLE32(value); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
501 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
|
502 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
503 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
|
504 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
505 value = SDL_SwapBE32(value); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
506 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
|
507 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
508 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
|
509 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
510 value = SDL_SwapLE64(value); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
511 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
|
512 } |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
513 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
|
514 { |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
515 value = SDL_SwapBE64(value); |
22f39393668a
Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
516 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
|
517 } |