author  Ryan C. Gordon <icculus@icculus.org> 
Fri, 12 Aug 2016 19:59:00 0400  
changeset 10266  c09f06c4e8c8 
parent 9998  f67cf37e9cd4 
permissions  rwrr 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

1 
/* 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

2 
Simple DirectMedia Layer 
9998
f67cf37e9cd4
Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents:
9619
diff
changeset

3 
Copyright (C) 19972016 Sam Lantinga <slouken@libsdl.org> 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

4 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

5 
This software is provided 'asis', without any express or implied 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

6 
warranty. In no event will the authors be held liable for any damages 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

7 
arising from the use of this software. 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

8 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

9 
Permission is granted to anyone to use this software for any purpose, 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

10 
including commercial applications, and to alter it and redistribute it 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

11 
freely, subject to the following restrictions: 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

12 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

13 
1. The origin of this software must not be misrepresented; you must not 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

14 
claim that you wrote the original software. If you use this software 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

15 
in a product, an acknowledgment in the product documentation would be 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

16 
appreciated but is not required. 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

17 
2. Altered source versions must be plainly marked as such, and must not be 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

18 
misrepresented as being the original software. 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

19 
3. This notice may not be removed or altered from any source distribution. 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

20 
*/ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

21 
/* Need this so Linux systems define fseek64o, ftell64o and off64_t */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

22 
#define _LARGEFILE64_SOURCE 
8093
b43765095a6f
Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents:
7828
diff
changeset

23 
#include "../SDL_internal.h" 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

24 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

25 
#if defined(__WIN32__) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

26 
#include "../core/windows/SDL_windows.h" 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

27 
#endif 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

28 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

29 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

30 
/* This file provides a general interface for SDL to read and write 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

31 
data sources. It can easily be extended to files, memory, etc. 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

32 
*/ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

33 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

34 
#include "SDL_endian.h" 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

35 
#include "SDL_rwops.h" 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

36 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

37 
#ifdef __APPLE__ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

38 
#include "cocoa/SDL_rwopsbundlesupport.h" 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

39 
#endif /* __APPLE__ */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

40 

8761
bce4122e6e87
__ANDROID__ is the correct macro to check for an android system.ANDROID is only defined in NDK build system (.mk) and not in the standalone NDK.
Dimitris Zenios <dimitris.zenios@gmail.com>
parents:
8583
diff
changeset

41 
#ifdef __ANDROID__ 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

42 
#include "../core/android/SDL_android.h" 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

43 
#include "SDL_system.h" 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

44 
#endif 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

45 

8833
ae720d61d14d
Chrome's Native Client backend implementation
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8761
diff
changeset

46 
#if __NACL__ 
ae720d61d14d
Chrome's Native Client backend implementation
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8761
diff
changeset

47 
#include "nacl_io/nacl_io.h" 
ae720d61d14d
Chrome's Native Client backend implementation
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8761
diff
changeset

48 
#endif 
ae720d61d14d
Chrome's Native Client backend implementation
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8761
diff
changeset

49 

8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

50 
#ifdef __WIN32__ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

51 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

52 
/* Functions to read/write Win32 API file pointers */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

53 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

54 
#ifndef INVALID_SET_FILE_POINTER 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

55 
#define INVALID_SET_FILE_POINTER 0xFFFFFFFF 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

56 
#endif 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

57 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

58 
#define READAHEAD_BUFFER_SIZE 1024 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

59 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

60 
static int SDLCALL 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

61 
windows_file_open(SDL_RWops * context, const char *filename, const char *mode) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

62 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

63 
UINT old_error_mode; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

64 
HANDLE h; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

65 
DWORD r_right, w_right; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

66 
DWORD must_exist, truncate; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

67 
int a_mode; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

68 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

69 
if (!context) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

70 
return 1; /* failed (invalid call) */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

71 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

72 
context>hidden.windowsio.h = INVALID_HANDLE_VALUE; /* mark this as unusable */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

73 
context>hidden.windowsio.buffer.data = NULL; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

74 
context>hidden.windowsio.buffer.size = 0; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

75 
context>hidden.windowsio.buffer.left = 0; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

76 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

77 
/* "r" = reading, file must exist */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

78 
/* "w" = writing, truncate existing, file may not exist */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

79 
/* "r+"= reading or writing, file must exist */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

80 
/* "a" = writing, append file may not exist */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

81 
/* "a+"= append + read, file may not exist */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

82 
/* "w+" = read, write, truncate. file may not exist */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

83 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

84 
must_exist = (SDL_strchr(mode, 'r') != NULL) ? OPEN_EXISTING : 0; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

85 
truncate = (SDL_strchr(mode, 'w') != NULL) ? CREATE_ALWAYS : 0; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

86 
r_right = (SDL_strchr(mode, '+') != NULL 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

87 
 must_exist) ? GENERIC_READ : 0; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

88 
a_mode = (SDL_strchr(mode, 'a') != NULL) ? OPEN_ALWAYS : 0; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

89 
w_right = (a_mode  SDL_strchr(mode, '+') 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

90 
 truncate) ? GENERIC_WRITE : 0; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

91 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

92 
if (!r_right && !w_right) /* inconsistent mode */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

93 
return 1; /* failed (invalid call) */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

94 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

95 
context>hidden.windowsio.buffer.data = 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

96 
(char *) SDL_malloc(READAHEAD_BUFFER_SIZE); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

97 
if (!context>hidden.windowsio.buffer.data) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

98 
return SDL_OutOfMemory(); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

99 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

100 
/* Do not open a dialog box if failure */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

101 
old_error_mode = 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

102 
SetErrorMode(SEM_NOOPENFILEERRORBOX  SEM_FAILCRITICALERRORS); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

103 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

104 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

105 
LPTSTR tstr = WIN_UTF8ToString(filename); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

106 
h = CreateFile(tstr, (w_right  r_right), 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

107 
(w_right) ? 0 : FILE_SHARE_READ, NULL, 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

108 
(must_exist  truncate  a_mode), 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

109 
FILE_ATTRIBUTE_NORMAL, NULL); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

110 
SDL_free(tstr); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

111 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

112 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

113 
/* restore old behavior */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

114 
SetErrorMode(old_error_mode); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

115 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

116 
if (h == INVALID_HANDLE_VALUE) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

117 
SDL_free(context>hidden.windowsio.buffer.data); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

118 
context>hidden.windowsio.buffer.data = NULL; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

119 
SDL_SetError("Couldn't open %s", filename); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

120 
return 2; /* failed (CreateFile) */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

121 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

122 
context>hidden.windowsio.h = h; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

123 
context>hidden.windowsio.append = a_mode ? SDL_TRUE : SDL_FALSE; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

124 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

125 
return 0; /* ok */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

126 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

127 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

128 
static Sint64 SDLCALL 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

129 
windows_file_size(SDL_RWops * context) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

130 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

131 
LARGE_INTEGER size; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

132 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

133 
if (!context  context>hidden.windowsio.h == INVALID_HANDLE_VALUE) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

134 
return SDL_SetError("windows_file_size: invalid context/file not opened"); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

135 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

136 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

137 
if (!GetFileSizeEx(context>hidden.windowsio.h, &size)) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

138 
return WIN_SetError("windows_file_size"); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

139 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

140 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

141 
return size.QuadPart; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

142 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

143 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

144 
static Sint64 SDLCALL 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

145 
windows_file_seek(SDL_RWops * context, Sint64 offset, int whence) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

146 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

147 
DWORD windowswhence; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

148 
LARGE_INTEGER windowsoffset; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

149 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

150 
if (!context  context>hidden.windowsio.h == INVALID_HANDLE_VALUE) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

151 
return SDL_SetError("windows_file_seek: invalid context/file not opened"); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

152 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

153 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

154 
/* FIXME: We may be able to satisfy the seek within buffered data */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

155 
if (whence == RW_SEEK_CUR && context>hidden.windowsio.buffer.left) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

156 
offset = (long)context>hidden.windowsio.buffer.left; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

157 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

158 
context>hidden.windowsio.buffer.left = 0; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

159 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

160 
switch (whence) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

161 
case RW_SEEK_SET: 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

162 
windowswhence = FILE_BEGIN; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

163 
break; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

164 
case RW_SEEK_CUR: 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

165 
windowswhence = FILE_CURRENT; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

166 
break; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

167 
case RW_SEEK_END: 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

168 
windowswhence = FILE_END; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

169 
break; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

170 
default: 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

171 
return SDL_SetError("windows_file_seek: Unknown value for 'whence'"); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

172 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

173 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

174 
windowsoffset.QuadPart = offset; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

175 
if (!SetFilePointerEx(context>hidden.windowsio.h, windowsoffset, &windowsoffset, windowswhence)) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

176 
return WIN_SetError("windows_file_seek"); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

177 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

178 
return windowsoffset.QuadPart; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

179 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

180 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

181 
static size_t SDLCALL 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

182 
windows_file_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

183 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

184 
size_t total_need; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

185 
size_t total_read = 0; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

186 
size_t read_ahead; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

187 
DWORD byte_read; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

188 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

189 
total_need = size * maxnum; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

190 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

191 
if (!context  context>hidden.windowsio.h == INVALID_HANDLE_VALUE 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

192 
 !total_need) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

193 
return 0; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

194 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

195 
if (context>hidden.windowsio.buffer.left > 0) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

196 
void *data = (char *) context>hidden.windowsio.buffer.data + 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

197 
context>hidden.windowsio.buffer.size  
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

198 
context>hidden.windowsio.buffer.left; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

199 
read_ahead = 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

200 
SDL_min(total_need, context>hidden.windowsio.buffer.left); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

201 
SDL_memcpy(ptr, data, read_ahead); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

202 
context>hidden.windowsio.buffer.left = read_ahead; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

203 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

204 
if (read_ahead == total_need) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

205 
return maxnum; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

206 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

207 
ptr = (char *) ptr + read_ahead; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

208 
total_need = read_ahead; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

209 
total_read += read_ahead; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

210 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

211 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

212 
if (total_need < READAHEAD_BUFFER_SIZE) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

213 
if (!ReadFile 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

214 
(context>hidden.windowsio.h, context>hidden.windowsio.buffer.data, 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

215 
READAHEAD_BUFFER_SIZE, &byte_read, NULL)) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

216 
SDL_Error(SDL_EFREAD); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

217 
return 0; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

218 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

219 
read_ahead = SDL_min(total_need, (int) byte_read); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

220 
SDL_memcpy(ptr, context>hidden.windowsio.buffer.data, read_ahead); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

221 
context>hidden.windowsio.buffer.size = byte_read; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

222 
context>hidden.windowsio.buffer.left = byte_read  read_ahead; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

223 
total_read += read_ahead; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

224 
} else { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

225 
if (!ReadFile 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

226 
(context>hidden.windowsio.h, ptr, (DWORD)total_need, &byte_read, NULL)) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

227 
SDL_Error(SDL_EFREAD); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

228 
return 0; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

229 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

230 
total_read += byte_read; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

231 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

232 
return (total_read / size); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

233 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

234 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

235 
static size_t SDLCALL 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

236 
windows_file_write(SDL_RWops * context, const void *ptr, size_t size, 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

237 
size_t num) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

238 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

239 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

240 
size_t total_bytes; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

241 
DWORD byte_written; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

242 
size_t nwritten; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

243 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

244 
total_bytes = size * num; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

245 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

246 
if (!context  context>hidden.windowsio.h == INVALID_HANDLE_VALUE 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

247 
 total_bytes <= 0  !size) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

248 
return 0; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

249 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

250 
if (context>hidden.windowsio.buffer.left) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

251 
SetFilePointer(context>hidden.windowsio.h, 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

252 
(LONG)context>hidden.windowsio.buffer.left, NULL, 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

253 
FILE_CURRENT); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

254 
context>hidden.windowsio.buffer.left = 0; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

255 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

256 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

257 
/* if in append mode, we must go to the EOF before write */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

258 
if (context>hidden.windowsio.append) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

259 
if (SetFilePointer(context>hidden.windowsio.h, 0L, NULL, FILE_END) == 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

260 
INVALID_SET_FILE_POINTER) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

261 
SDL_Error(SDL_EFWRITE); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

262 
return 0; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

263 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

264 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

265 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

266 
if (!WriteFile 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

267 
(context>hidden.windowsio.h, ptr, (DWORD)total_bytes, &byte_written, NULL)) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

268 
SDL_Error(SDL_EFWRITE); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

269 
return 0; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

270 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

271 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

272 
nwritten = byte_written / size; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

273 
return nwritten; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

274 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

275 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

276 
static int SDLCALL 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

277 
windows_file_close(SDL_RWops * context) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

278 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

279 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

280 
if (context) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

281 
if (context>hidden.windowsio.h != INVALID_HANDLE_VALUE) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

282 
CloseHandle(context>hidden.windowsio.h); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

283 
context>hidden.windowsio.h = INVALID_HANDLE_VALUE; /* to be sure */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

284 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

285 
SDL_free(context>hidden.windowsio.buffer.data); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

286 
context>hidden.windowsio.buffer.data = NULL; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

287 
SDL_FreeRW(context); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

288 
} 
8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

289 
return 0; 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

290 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

291 
#endif /* __WIN32__ */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

292 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

293 
#ifdef HAVE_STDIO_H 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

294 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

295 
/* Functions to read/write stdio file pointers */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

296 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

297 
static Sint64 SDLCALL 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

298 
stdio_size(SDL_RWops * context) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

299 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

300 
Sint64 pos, size; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

301 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

302 
pos = SDL_RWseek(context, 0, RW_SEEK_CUR); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

303 
if (pos < 0) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

304 
return 1; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

305 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

306 
size = SDL_RWseek(context, 0, RW_SEEK_END); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

307 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

308 
SDL_RWseek(context, pos, RW_SEEK_SET); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

309 
return size; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

310 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

311 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

312 
static Sint64 SDLCALL 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

313 
stdio_seek(SDL_RWops * context, Sint64 offset, int whence) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

314 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

315 
#ifdef HAVE_FSEEKO64 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

316 
if (fseeko64(context>hidden.stdio.fp, (off64_t)offset, whence) == 0) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

317 
return ftello64(context>hidden.stdio.fp); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

318 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

319 
#elif defined(HAVE_FSEEKO) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

320 
if (fseeko(context>hidden.stdio.fp, (off_t)offset, whence) == 0) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

321 
return ftello(context>hidden.stdio.fp); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

322 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

323 
#elif defined(HAVE__FSEEKI64) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

324 
if (_fseeki64(context>hidden.stdio.fp, offset, whence) == 0) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

325 
return _ftelli64(context>hidden.stdio.fp); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

326 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

327 
#else 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

328 
if (fseek(context>hidden.stdio.fp, offset, whence) == 0) { 
8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

329 
return ftell(context>hidden.stdio.fp); 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

330 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

331 
#endif 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

332 
return SDL_Error(SDL_EFSEEK); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

333 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

334 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

335 
static size_t SDLCALL 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

336 
stdio_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

337 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

338 
size_t nread; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

339 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

340 
nread = fread(ptr, size, maxnum, context>hidden.stdio.fp); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

341 
if (nread == 0 && ferror(context>hidden.stdio.fp)) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

342 
SDL_Error(SDL_EFREAD); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

343 
} 
8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

344 
return nread; 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

345 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

346 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

347 
static size_t SDLCALL 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

348 
stdio_write(SDL_RWops * context, const void *ptr, size_t size, size_t num) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

349 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

350 
size_t nwrote; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

351 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

352 
nwrote = fwrite(ptr, size, num, context>hidden.stdio.fp); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

353 
if (nwrote == 0 && ferror(context>hidden.stdio.fp)) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

354 
SDL_Error(SDL_EFWRITE); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

355 
} 
8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

356 
return nwrote; 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

357 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

358 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

359 
static int SDLCALL 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

360 
stdio_close(SDL_RWops * context) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

361 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

362 
int status = 0; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

363 
if (context) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

364 
if (context>hidden.stdio.autoclose) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

365 
/* WARNING: Check the return value here! */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

366 
if (fclose(context>hidden.stdio.fp) != 0) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

367 
status = SDL_Error(SDL_EFWRITE); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

368 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

369 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

370 
SDL_FreeRW(context); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

371 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

372 
return status; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

373 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

374 
#endif /* !HAVE_STDIO_H */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

375 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

376 
/* Functions to read/write memory pointers */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

377 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

378 
static Sint64 SDLCALL 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

379 
mem_size(SDL_RWops * context) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

380 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

381 
return (Sint64)(context>hidden.mem.stop  context>hidden.mem.base); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

382 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

383 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

384 
static Sint64 SDLCALL 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

385 
mem_seek(SDL_RWops * context, Sint64 offset, int whence) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

386 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

387 
Uint8 *newpos; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

388 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

389 
switch (whence) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

390 
case RW_SEEK_SET: 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

391 
newpos = context>hidden.mem.base + offset; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

392 
break; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

393 
case RW_SEEK_CUR: 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

394 
newpos = context>hidden.mem.here + offset; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

395 
break; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

396 
case RW_SEEK_END: 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

397 
newpos = context>hidden.mem.stop + offset; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

398 
break; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

399 
default: 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

400 
return SDL_SetError("Unknown value for 'whence'"); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

401 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

402 
if (newpos < context>hidden.mem.base) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

403 
newpos = context>hidden.mem.base; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

404 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

405 
if (newpos > context>hidden.mem.stop) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

406 
newpos = context>hidden.mem.stop; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

407 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

408 
context>hidden.mem.here = newpos; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

409 
return (Sint64)(context>hidden.mem.here  context>hidden.mem.base); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

410 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

411 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

412 
static size_t SDLCALL 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

413 
mem_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

414 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

415 
size_t total_bytes; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

416 
size_t mem_available; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

417 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

418 
total_bytes = (maxnum * size); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

419 
if ((maxnum <= 0)  (size <= 0) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

420 
 ((total_bytes / maxnum) != (size_t) size)) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

421 
return 0; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

422 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

423 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

424 
mem_available = (context>hidden.mem.stop  context>hidden.mem.here); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

425 
if (total_bytes > mem_available) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

426 
total_bytes = mem_available; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

427 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

428 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

429 
SDL_memcpy(ptr, context>hidden.mem.here, total_bytes); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

430 
context>hidden.mem.here += total_bytes; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

431 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

432 
return (total_bytes / size); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

433 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

434 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

435 
static size_t SDLCALL 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

436 
mem_write(SDL_RWops * context, const void *ptr, size_t size, size_t num) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

437 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

438 
if ((context>hidden.mem.here + (num * size)) > context>hidden.mem.stop) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

439 
num = (context>hidden.mem.stop  context>hidden.mem.here) / size; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

440 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

441 
SDL_memcpy(context>hidden.mem.here, ptr, num * size); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

442 
context>hidden.mem.here += num * size; 
8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

443 
return num; 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

444 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

445 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

446 
static size_t SDLCALL 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

447 
mem_writeconst(SDL_RWops * context, const void *ptr, size_t size, size_t num) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

448 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

449 
SDL_SetError("Can't write to readonly memory"); 
8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

450 
return 0; 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

451 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

452 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

453 
static int SDLCALL 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

454 
mem_close(SDL_RWops * context) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

455 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

456 
if (context) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

457 
SDL_FreeRW(context); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

458 
} 
8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

459 
return 0; 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

460 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

461 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

462 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

463 
/* Functions to create SDL_RWops structures from various data sources */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

464 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

465 
SDL_RWops * 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

466 
SDL_RWFromFile(const char *file, const char *mode) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

467 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

468 
SDL_RWops *rwops = NULL; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

469 
if (!file  !*file  !mode  !*mode) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

470 
SDL_SetError("SDL_RWFromFile(): No file or no mode specified"); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

471 
return NULL; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

472 
} 
8761
bce4122e6e87
__ANDROID__ is the correct macro to check for an android system.ANDROID is only defined in NDK build system (.mk) and not in the standalone NDK.
Dimitris Zenios <dimitris.zenios@gmail.com>
parents:
8583
diff
changeset

473 
#if defined(__ANDROID__) 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

474 
#ifdef HAVE_STDIO_H 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

475 
/* Try to open the file on the filesystem first */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

476 
if (*file == '/') { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

477 
FILE *fp = fopen(file, mode); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

478 
if (fp) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

479 
return SDL_RWFromFP(fp, 1); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

480 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

481 
} else { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

482 
/* Try opening it from internal storage if it's a relative path */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

483 
char *path; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

484 
FILE *fp; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

485 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

486 
path = SDL_stack_alloc(char, PATH_MAX); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

487 
if (path) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

488 
SDL_snprintf(path, PATH_MAX, "%s/%s", 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

489 
SDL_AndroidGetInternalStoragePath(), file); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

490 
fp = fopen(path, mode); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

491 
SDL_stack_free(path); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

492 
if (fp) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

493 
return SDL_RWFromFP(fp, 1); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

494 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

495 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

496 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

497 
#endif /* HAVE_STDIO_H */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

498 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

499 
/* Try to open the file from the asset system */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

500 
rwops = SDL_AllocRW(); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

501 
if (!rwops) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

502 
return NULL; /* SDL_SetError already setup by SDL_AllocRW() */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

503 
if (Android_JNI_FileOpen(rwops, file, mode) < 0) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

504 
SDL_FreeRW(rwops); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

505 
return NULL; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

506 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

507 
rwops>size = Android_JNI_FileSize; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

508 
rwops>seek = Android_JNI_FileSeek; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

509 
rwops>read = Android_JNI_FileRead; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

510 
rwops>write = Android_JNI_FileWrite; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

511 
rwops>close = Android_JNI_FileClose; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

512 
rwops>type = SDL_RWOPS_JNIFILE; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

513 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

514 
#elif defined(__WIN32__) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

515 
rwops = SDL_AllocRW(); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

516 
if (!rwops) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

517 
return NULL; /* SDL_SetError already setup by SDL_AllocRW() */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

518 
if (windows_file_open(rwops, file, mode) < 0) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

519 
SDL_FreeRW(rwops); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

520 
return NULL; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

521 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

522 
rwops>size = windows_file_size; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

523 
rwops>seek = windows_file_seek; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

524 
rwops>read = windows_file_read; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

525 
rwops>write = windows_file_write; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

526 
rwops>close = windows_file_close; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

527 
rwops>type = SDL_RWOPS_WINFILE; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

528 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

529 
#elif HAVE_STDIO_H 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

530 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

531 
#ifdef __APPLE__ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

532 
FILE *fp = SDL_OpenFPFromBundleOrFallback(file, mode); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

533 
#elif __WINRT__ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

534 
FILE *fp = NULL; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

535 
fopen_s(&fp, file, mode); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

536 
#else 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

537 
FILE *fp = fopen(file, mode); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

538 
#endif 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

539 
if (fp == NULL) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

540 
SDL_SetError("Couldn't open %s", file); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

541 
} else { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

542 
rwops = SDL_RWFromFP(fp, 1); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

543 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

544 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

545 
#else 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

546 
SDL_SetError("SDL not compiled with stdio support"); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

547 
#endif /* !HAVE_STDIO_H */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

548 

8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

549 
return rwops; 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

550 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

551 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

552 
#ifdef HAVE_STDIO_H 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

553 
SDL_RWops * 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

554 
SDL_RWFromFP(FILE * fp, SDL_bool autoclose) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

555 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

556 
SDL_RWops *rwops = NULL; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

557 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

558 
rwops = SDL_AllocRW(); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

559 
if (rwops != NULL) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

560 
rwops>size = stdio_size; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

561 
rwops>seek = stdio_seek; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

562 
rwops>read = stdio_read; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

563 
rwops>write = stdio_write; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

564 
rwops>close = stdio_close; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

565 
rwops>hidden.stdio.fp = fp; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

566 
rwops>hidden.stdio.autoclose = autoclose; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

567 
rwops>type = SDL_RWOPS_STDFILE; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

568 
} 
8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

569 
return rwops; 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

570 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

571 
#else 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

572 
SDL_RWops * 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

573 
SDL_RWFromFP(void * fp, SDL_bool autoclose) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

574 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

575 
SDL_SetError("SDL not compiled with stdio support"); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

576 
return NULL; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

577 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

578 
#endif /* HAVE_STDIO_H */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

579 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

580 
SDL_RWops * 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

581 
SDL_RWFromMem(void *mem, int size) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

582 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

583 
SDL_RWops *rwops = NULL; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

584 
if (!mem) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

585 
SDL_InvalidParamError("mem"); 
8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

586 
return rwops; 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

587 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

588 
if (!size) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

589 
SDL_InvalidParamError("size"); 
8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

590 
return rwops; 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

591 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

592 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

593 
rwops = SDL_AllocRW(); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

594 
if (rwops != NULL) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

595 
rwops>size = mem_size; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

596 
rwops>seek = mem_seek; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

597 
rwops>read = mem_read; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

598 
rwops>write = mem_write; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

599 
rwops>close = mem_close; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

600 
rwops>hidden.mem.base = (Uint8 *) mem; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

601 
rwops>hidden.mem.here = rwops>hidden.mem.base; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

602 
rwops>hidden.mem.stop = rwops>hidden.mem.base + size; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

603 
rwops>type = SDL_RWOPS_MEMORY; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

604 
} 
8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

605 
return rwops; 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

606 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

607 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

608 
SDL_RWops * 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

609 
SDL_RWFromConstMem(const void *mem, int size) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

610 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

611 
SDL_RWops *rwops = NULL; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

612 
if (!mem) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

613 
SDL_InvalidParamError("mem"); 
8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

614 
return rwops; 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

615 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

616 
if (!size) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

617 
SDL_InvalidParamError("size"); 
8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

618 
return rwops; 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

619 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

620 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

621 
rwops = SDL_AllocRW(); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

622 
if (rwops != NULL) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

623 
rwops>size = mem_size; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

624 
rwops>seek = mem_seek; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

625 
rwops>read = mem_read; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

626 
rwops>write = mem_writeconst; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

627 
rwops>close = mem_close; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

628 
rwops>hidden.mem.base = (Uint8 *) mem; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

629 
rwops>hidden.mem.here = rwops>hidden.mem.base; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

630 
rwops>hidden.mem.stop = rwops>hidden.mem.base + size; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

631 
rwops>type = SDL_RWOPS_MEMORY_RO; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

632 
} 
8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

633 
return rwops; 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

634 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

635 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

636 
SDL_RWops * 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

637 
SDL_AllocRW(void) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

638 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

639 
SDL_RWops *area; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

640 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

641 
area = (SDL_RWops *) SDL_malloc(sizeof *area); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

642 
if (area == NULL) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

643 
SDL_OutOfMemory(); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

644 
} else { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

645 
area>type = SDL_RWOPS_UNKNOWN; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

646 
} 
8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

647 
return area; 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

648 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

649 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

650 
void 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

651 
SDL_FreeRW(SDL_RWops * area) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

652 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

653 
SDL_free(area); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

654 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

655 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

656 
/* Functions for dynamically reading and writing endianspecific values */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

657 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

658 
Uint8 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

659 
SDL_ReadU8(SDL_RWops * src) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

660 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

661 
Uint8 value = 0; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

662 

8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

663 
SDL_RWread(src, &value, sizeof (value), 1); 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

664 
return value; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

665 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

666 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

667 
Uint16 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

668 
SDL_ReadLE16(SDL_RWops * src) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

669 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

670 
Uint16 value = 0; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

671 

8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

672 
SDL_RWread(src, &value, sizeof (value), 1); 
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

673 
return SDL_SwapLE16(value); 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

674 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

675 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

676 
Uint16 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

677 
SDL_ReadBE16(SDL_RWops * src) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

678 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

679 
Uint16 value = 0; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

680 

8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

681 
SDL_RWread(src, &value, sizeof (value), 1); 
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

682 
return SDL_SwapBE16(value); 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

683 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

684 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

685 
Uint32 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

686 
SDL_ReadLE32(SDL_RWops * src) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

687 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

688 
Uint32 value = 0; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

689 

8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

690 
SDL_RWread(src, &value, sizeof (value), 1); 
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

691 
return SDL_SwapLE32(value); 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

692 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

693 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

694 
Uint32 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

695 
SDL_ReadBE32(SDL_RWops * src) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

696 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

697 
Uint32 value = 0; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

698 

8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

699 
SDL_RWread(src, &value, sizeof (value), 1); 
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

700 
return SDL_SwapBE32(value); 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

701 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

702 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

703 
Uint64 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

704 
SDL_ReadLE64(SDL_RWops * src) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

705 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

706 
Uint64 value = 0; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

707 

8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

708 
SDL_RWread(src, &value, sizeof (value), 1); 
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

709 
return SDL_SwapLE64(value); 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

710 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

711 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

712 
Uint64 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

713 
SDL_ReadBE64(SDL_RWops * src) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

714 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

715 
Uint64 value = 0; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

716 

8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

717 
SDL_RWread(src, &value, sizeof (value), 1); 
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

718 
return SDL_SwapBE64(value); 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

719 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

720 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

721 
size_t 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

722 
SDL_WriteU8(SDL_RWops * dst, Uint8 value) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

723 
{ 
8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

724 
return SDL_RWwrite(dst, &value, sizeof (value), 1); 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

725 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

726 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

727 
size_t 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

728 
SDL_WriteLE16(SDL_RWops * dst, Uint16 value) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

729 
{ 
8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

730 
const Uint16 swapped = SDL_SwapLE16(value); 
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

731 
return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1); 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

732 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

733 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

734 
size_t 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

735 
SDL_WriteBE16(SDL_RWops * dst, Uint16 value) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

736 
{ 
8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

737 
const Uint16 swapped = SDL_SwapBE16(value); 
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

738 
return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1); 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

739 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

740 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

741 
size_t 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

742 
SDL_WriteLE32(SDL_RWops * dst, Uint32 value) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

743 
{ 
8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

744 
const Uint32 swapped = SDL_SwapLE32(value); 
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

745 
return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1); 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

746 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

747 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

748 
size_t 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

749 
SDL_WriteBE32(SDL_RWops * dst, Uint32 value) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

750 
{ 
8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

751 
const Uint32 swapped = SDL_SwapBE32(value); 
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

752 
return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1); 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

753 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

754 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

755 
size_t 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

756 
SDL_WriteLE64(SDL_RWops * dst, Uint64 value) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

757 
{ 
8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

758 
const Uint64 swapped = SDL_SwapLE64(value); 
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

759 
return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1); 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

760 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

761 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

762 
size_t 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

763 
SDL_WriteBE64(SDL_RWops * dst, Uint64 value) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

764 
{ 
8162
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

765 
const Uint64 swapped = SDL_SwapBE64(value); 
b6083d2078c0
Fixed some compiler warnings from the latest Clang, cleaned up some things.
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset

766 
return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1); 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

767 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

768 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8535
diff
changeset

769 
/* vi: set ts=4 sw=4 expandtab: */ 