src/file/SDL_rwops.c
changeset 6430 48d519500f7e
parent 6375 93f9a24d1c02
child 6629 8e2c731103e6
child 8316 88f011703f39
equal deleted inserted replaced
6429:ff5e34883bf8 6430:48d519500f7e
    41 #endif /* __NDS__ */
    41 #endif /* __NDS__ */
    42 
    42 
    43 #ifdef __WIN32__
    43 #ifdef __WIN32__
    44 
    44 
    45 /* Functions to read/write Win32 API file pointers */
    45 /* Functions to read/write Win32 API file pointers */
    46 /* Will not use it on WinCE because stdio is buffered, it means
       
    47    faster, and all stdio functions anyway are embedded in coredll.dll - 
       
    48    the main wince dll*/
       
    49 
    46 
    50 #include "../core/windows/SDL_windows.h"
    47 #include "../core/windows/SDL_windows.h"
    51 
    48 
    52 #ifndef INVALID_SET_FILE_POINTER
    49 #ifndef INVALID_SET_FILE_POINTER
    53 #define INVALID_SET_FILE_POINTER 0xFFFFFFFF
    50 #define INVALID_SET_FILE_POINTER 0xFFFFFFFF
    56 #define READAHEAD_BUFFER_SIZE	1024
    53 #define READAHEAD_BUFFER_SIZE	1024
    57 
    54 
    58 static int SDLCALL
    55 static int SDLCALL
    59 windows_file_open(SDL_RWops * context, const char *filename, const char *mode)
    56 windows_file_open(SDL_RWops * context, const char *filename, const char *mode)
    60 {
    57 {
    61 #ifndef _WIN32_WCE
       
    62     UINT old_error_mode;
    58     UINT old_error_mode;
    63 #endif
       
    64     HANDLE h;
    59     HANDLE h;
    65     DWORD r_right, w_right;
    60     DWORD r_right, w_right;
    66     DWORD must_exist, truncate;
    61     DWORD must_exist, truncate;
    67     int a_mode;
    62     int a_mode;
    68 
    63 
    96         (char *) SDL_malloc(READAHEAD_BUFFER_SIZE);
    91         (char *) SDL_malloc(READAHEAD_BUFFER_SIZE);
    97     if (!context->hidden.windowsio.buffer.data) {
    92     if (!context->hidden.windowsio.buffer.data) {
    98         SDL_OutOfMemory();
    93         SDL_OutOfMemory();
    99         return -1;
    94         return -1;
   100     }
    95     }
   101 #ifdef _WIN32_WCE
    96     /* Do not open a dialog box if failure */
       
    97     old_error_mode =
       
    98         SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS);
       
    99 
   102     {
   100     {
   103         LPTSTR tstr = WIN_UTF8ToString(filename);
   101         LPTSTR tstr = WIN_UTF8ToString(filename);
   104         h = CreateFile(tstr, (w_right | r_right),
   102         h = CreateFile(tstr, (w_right | r_right),
   105                        (w_right) ? 0 : FILE_SHARE_READ, NULL,
   103                        (w_right) ? 0 : FILE_SHARE_READ, NULL,
   106                        (must_exist | truncate | a_mode),
   104                        (must_exist | truncate | a_mode),
   107                        FILE_ATTRIBUTE_NORMAL, NULL);
   105                        FILE_ATTRIBUTE_NORMAL, NULL);
   108         SDL_free(tstr);
   106         SDL_free(tstr);
   109     }
   107     }
   110 #else
       
   111     /* Do not open a dialog box if failure */
       
   112     old_error_mode =
       
   113         SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS);
       
   114 
       
   115     {
       
   116         LPTSTR tstr = WIN_UTF8ToString(filename);
       
   117         h = CreateFile(tstr, (w_right | r_right),
       
   118                        (w_right) ? 0 : FILE_SHARE_READ, NULL,
       
   119                        (must_exist | truncate | a_mode),
       
   120                        FILE_ATTRIBUTE_NORMAL, NULL);
       
   121         SDL_free(tstr);
       
   122     }
       
   123 
   108 
   124     /* restore old behavior */
   109     /* restore old behavior */
   125     SetErrorMode(old_error_mode);
   110     SetErrorMode(old_error_mode);
   126 #endif /* _WIN32_WCE */
       
   127 
   111 
   128     if (h == INVALID_HANDLE_VALUE) {
   112     if (h == INVALID_HANDLE_VALUE) {
   129         SDL_free(context->hidden.windowsio.buffer.data);
   113         SDL_free(context->hidden.windowsio.buffer.data);
   130         context->hidden.windowsio.buffer.data = NULL;
   114         context->hidden.windowsio.buffer.data = NULL;
   131         SDL_SetError("Couldn't open %s", filename);
   115         SDL_SetError("Couldn't open %s", filename);