src/file/SDL_rwops.c
changeset 5062 e8916fe9cfc8
parent 4454 be387681d876
child 5086 c2539ff054c8
     1.1 --- a/src/file/SDL_rwops.c	Thu Jan 20 17:33:06 2011 -0800
     1.2 +++ b/src/file/SDL_rwops.c	Thu Jan 20 18:04:05 2011 -0800
     1.3 @@ -37,7 +37,7 @@
     1.4  #include <fat.h>
     1.5  #endif /* __NDS__ */
     1.6  
     1.7 -#ifdef __WIN32__
     1.8 +#ifdef __WINDOWS__
     1.9  
    1.10  /* Functions to read/write Win32 API file pointers */
    1.11  /* Will not use it on WinCE because stdio is buffered, it means
    1.12 @@ -54,7 +54,7 @@
    1.13  #define READAHEAD_BUFFER_SIZE	1024
    1.14  
    1.15  static int SDLCALL
    1.16 -win32_file_open(SDL_RWops * context, const char *filename, const char *mode)
    1.17 +windows_file_open(SDL_RWops * context, const char *filename, const char *mode)
    1.18  {
    1.19  #ifndef _WIN32_WCE
    1.20      UINT old_error_mode;
    1.21 @@ -67,10 +67,10 @@
    1.22      if (!context)
    1.23          return -1;              /* failed (invalid call) */
    1.24  
    1.25 -    context->hidden.win32io.h = INVALID_HANDLE_VALUE;   /* mark this as unusable */
    1.26 -    context->hidden.win32io.buffer.data = NULL;
    1.27 -    context->hidden.win32io.buffer.size = 0;
    1.28 -    context->hidden.win32io.buffer.left = 0;
    1.29 +    context->hidden.windowsio.h = INVALID_HANDLE_VALUE;   /* mark this as unusable */
    1.30 +    context->hidden.windowsio.buffer.data = NULL;
    1.31 +    context->hidden.windowsio.buffer.size = 0;
    1.32 +    context->hidden.windowsio.buffer.left = 0;
    1.33  
    1.34      /* "r" = reading, file must exist */
    1.35      /* "w" = writing, truncate existing, file may not exist */
    1.36 @@ -90,9 +90,9 @@
    1.37      if (!r_right && !w_right)   /* inconsistent mode */
    1.38          return -1;              /* failed (invalid call) */
    1.39  
    1.40 -    context->hidden.win32io.buffer.data =
    1.41 +    context->hidden.windowsio.buffer.data =
    1.42          (char *) SDL_malloc(READAHEAD_BUFFER_SIZE);
    1.43 -    if (!context->hidden.win32io.buffer.data) {
    1.44 +    if (!context->hidden.windowsio.buffer.data) {
    1.45          SDL_OutOfMemory();
    1.46          return -1;
    1.47      }
    1.48 @@ -104,8 +104,8 @@
    1.49          if (MultiByteToWideChar(CP_UTF8, 0, filename, -1, filenameW, size) ==
    1.50              0) {
    1.51              SDL_stack_free(filenameW);
    1.52 -            SDL_free(context->hidden.win32io.buffer.data);
    1.53 -            context->hidden.win32io.buffer.data = NULL;
    1.54 +            SDL_free(context->hidden.windowsio.buffer.data);
    1.55 +            context->hidden.windowsio.buffer.data = NULL;
    1.56              SDL_SetError("Unable to convert filename to Unicode");
    1.57              return -1;
    1.58          }
    1.59 @@ -130,51 +130,51 @@
    1.60  #endif /* _WIN32_WCE */
    1.61  
    1.62      if (h == INVALID_HANDLE_VALUE) {
    1.63 -        SDL_free(context->hidden.win32io.buffer.data);
    1.64 -        context->hidden.win32io.buffer.data = NULL;
    1.65 +        SDL_free(context->hidden.windowsio.buffer.data);
    1.66 +        context->hidden.windowsio.buffer.data = NULL;
    1.67          SDL_SetError("Couldn't open %s", filename);
    1.68          return -2;              /* failed (CreateFile) */
    1.69      }
    1.70 -    context->hidden.win32io.h = h;
    1.71 -    context->hidden.win32io.append = a_mode ? SDL_TRUE : SDL_FALSE;
    1.72 +    context->hidden.windowsio.h = h;
    1.73 +    context->hidden.windowsio.append = a_mode ? SDL_TRUE : SDL_FALSE;
    1.74  
    1.75      return 0;                   /* ok */
    1.76  }
    1.77  
    1.78  static long SDLCALL
    1.79 -win32_file_seek(SDL_RWops * context, long offset, int whence)
    1.80 +windows_file_seek(SDL_RWops * context, long offset, int whence)
    1.81  {
    1.82 -    DWORD win32whence;
    1.83 +    DWORD windowswhence;
    1.84      long file_pos;
    1.85  
    1.86 -    if (!context || context->hidden.win32io.h == INVALID_HANDLE_VALUE) {
    1.87 -        SDL_SetError("win32_file_seek: invalid context/file not opened");
    1.88 +    if (!context || context->hidden.windowsio.h == INVALID_HANDLE_VALUE) {
    1.89 +        SDL_SetError("windows_file_seek: invalid context/file not opened");
    1.90          return -1;
    1.91      }
    1.92  
    1.93      /* FIXME: We may be able to satisfy the seek within buffered data */
    1.94 -    if (whence == RW_SEEK_CUR && context->hidden.win32io.buffer.left) {
    1.95 -        offset -= (long)context->hidden.win32io.buffer.left;
    1.96 +    if (whence == RW_SEEK_CUR && context->hidden.windowsio.buffer.left) {
    1.97 +        offset -= (long)context->hidden.windowsio.buffer.left;
    1.98      }
    1.99 -    context->hidden.win32io.buffer.left = 0;
   1.100 +    context->hidden.windowsio.buffer.left = 0;
   1.101  
   1.102      switch (whence) {
   1.103      case RW_SEEK_SET:
   1.104 -        win32whence = FILE_BEGIN;
   1.105 +        windowswhence = FILE_BEGIN;
   1.106          break;
   1.107      case RW_SEEK_CUR:
   1.108 -        win32whence = FILE_CURRENT;
   1.109 +        windowswhence = FILE_CURRENT;
   1.110          break;
   1.111      case RW_SEEK_END:
   1.112 -        win32whence = FILE_END;
   1.113 +        windowswhence = FILE_END;
   1.114          break;
   1.115      default:
   1.116 -        SDL_SetError("win32_file_seek: Unknown value for 'whence'");
   1.117 +        SDL_SetError("windows_file_seek: Unknown value for 'whence'");
   1.118          return -1;
   1.119      }
   1.120  
   1.121      file_pos =
   1.122 -        SetFilePointer(context->hidden.win32io.h, offset, NULL, win32whence);
   1.123 +        SetFilePointer(context->hidden.windowsio.h, offset, NULL, windowswhence);
   1.124  
   1.125      if (file_pos != INVALID_SET_FILE_POINTER)
   1.126          return file_pos;        /* success */
   1.127 @@ -184,7 +184,7 @@
   1.128  }
   1.129  
   1.130  static size_t SDLCALL
   1.131 -win32_file_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum)
   1.132 +windows_file_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum)
   1.133  {
   1.134      size_t total_need;
   1.135      size_t total_read = 0;
   1.136 @@ -193,18 +193,18 @@
   1.137  
   1.138      total_need = size * maxnum;
   1.139  
   1.140 -    if (!context || context->hidden.win32io.h == INVALID_HANDLE_VALUE
   1.141 +    if (!context || context->hidden.windowsio.h == INVALID_HANDLE_VALUE
   1.142          || !total_need)
   1.143          return 0;
   1.144  
   1.145 -    if (context->hidden.win32io.buffer.left > 0) {
   1.146 -        void *data = (char *) context->hidden.win32io.buffer.data +
   1.147 -            context->hidden.win32io.buffer.size -
   1.148 -            context->hidden.win32io.buffer.left;
   1.149 +    if (context->hidden.windowsio.buffer.left > 0) {
   1.150 +        void *data = (char *) context->hidden.windowsio.buffer.data +
   1.151 +            context->hidden.windowsio.buffer.size -
   1.152 +            context->hidden.windowsio.buffer.left;
   1.153          read_ahead =
   1.154 -            SDL_min(total_need, context->hidden.win32io.buffer.left);
   1.155 +            SDL_min(total_need, context->hidden.windowsio.buffer.left);
   1.156          SDL_memcpy(ptr, data, read_ahead);
   1.157 -        context->hidden.win32io.buffer.left -= read_ahead;
   1.158 +        context->hidden.windowsio.buffer.left -= read_ahead;
   1.159  
   1.160          if (read_ahead == total_need) {
   1.161              return maxnum;
   1.162 @@ -216,19 +216,19 @@
   1.163  
   1.164      if (total_need < READAHEAD_BUFFER_SIZE) {
   1.165          if (!ReadFile
   1.166 -            (context->hidden.win32io.h, context->hidden.win32io.buffer.data,
   1.167 +            (context->hidden.windowsio.h, context->hidden.windowsio.buffer.data,
   1.168               READAHEAD_BUFFER_SIZE, &byte_read, NULL)) {
   1.169              SDL_Error(SDL_EFREAD);
   1.170              return 0;
   1.171          }
   1.172          read_ahead = SDL_min(total_need, (int) byte_read);
   1.173 -        SDL_memcpy(ptr, context->hidden.win32io.buffer.data, read_ahead);
   1.174 -        context->hidden.win32io.buffer.size = byte_read;
   1.175 -        context->hidden.win32io.buffer.left = byte_read - read_ahead;
   1.176 +        SDL_memcpy(ptr, context->hidden.windowsio.buffer.data, read_ahead);
   1.177 +        context->hidden.windowsio.buffer.size = byte_read;
   1.178 +        context->hidden.windowsio.buffer.left = byte_read - read_ahead;
   1.179          total_read += read_ahead;
   1.180      } else {
   1.181          if (!ReadFile
   1.182 -            (context->hidden.win32io.h, ptr, (DWORD)total_need, &byte_read, NULL)) {
   1.183 +            (context->hidden.windowsio.h, ptr, (DWORD)total_need, &byte_read, NULL)) {
   1.184              SDL_Error(SDL_EFREAD);
   1.185              return 0;
   1.186          }
   1.187 @@ -238,7 +238,7 @@
   1.188  }
   1.189  
   1.190  static size_t SDLCALL
   1.191 -win32_file_write(SDL_RWops * context, const void *ptr, size_t size,
   1.192 +windows_file_write(SDL_RWops * context, const void *ptr, size_t size,
   1.193                   size_t num)
   1.194  {
   1.195  
   1.196 @@ -248,20 +248,20 @@
   1.197  
   1.198      total_bytes = size * num;
   1.199  
   1.200 -    if (!context || context->hidden.win32io.h == INVALID_HANDLE_VALUE
   1.201 +    if (!context || context->hidden.windowsio.h == INVALID_HANDLE_VALUE
   1.202          || total_bytes <= 0 || !size)
   1.203          return 0;
   1.204  
   1.205 -    if (context->hidden.win32io.buffer.left) {
   1.206 -        SetFilePointer(context->hidden.win32io.h,
   1.207 -                       -(LONG)context->hidden.win32io.buffer.left, NULL,
   1.208 +    if (context->hidden.windowsio.buffer.left) {
   1.209 +        SetFilePointer(context->hidden.windowsio.h,
   1.210 +                       -(LONG)context->hidden.windowsio.buffer.left, NULL,
   1.211                         FILE_CURRENT);
   1.212 -        context->hidden.win32io.buffer.left = 0;
   1.213 +        context->hidden.windowsio.buffer.left = 0;
   1.214      }
   1.215  
   1.216      /* if in append mode, we must go to the EOF before write */
   1.217 -    if (context->hidden.win32io.append) {
   1.218 -        if (SetFilePointer(context->hidden.win32io.h, 0L, NULL, FILE_END) ==
   1.219 +    if (context->hidden.windowsio.append) {
   1.220 +        if (SetFilePointer(context->hidden.windowsio.h, 0L, NULL, FILE_END) ==
   1.221              INVALID_SET_FILE_POINTER) {
   1.222              SDL_Error(SDL_EFWRITE);
   1.223              return 0;
   1.224 @@ -269,7 +269,7 @@
   1.225      }
   1.226  
   1.227      if (!WriteFile
   1.228 -        (context->hidden.win32io.h, ptr, (DWORD)total_bytes, &byte_written, NULL)) {
   1.229 +        (context->hidden.windowsio.h, ptr, (DWORD)total_bytes, &byte_written, NULL)) {
   1.230          SDL_Error(SDL_EFWRITE);
   1.231          return 0;
   1.232      }
   1.233 @@ -279,23 +279,23 @@
   1.234  }
   1.235  
   1.236  static int SDLCALL
   1.237 -win32_file_close(SDL_RWops * context)
   1.238 +windows_file_close(SDL_RWops * context)
   1.239  {
   1.240  
   1.241      if (context) {
   1.242 -        if (context->hidden.win32io.h != INVALID_HANDLE_VALUE) {
   1.243 -            CloseHandle(context->hidden.win32io.h);
   1.244 -            context->hidden.win32io.h = INVALID_HANDLE_VALUE;   /* to be sure */
   1.245 +        if (context->hidden.windowsio.h != INVALID_HANDLE_VALUE) {
   1.246 +            CloseHandle(context->hidden.windowsio.h);
   1.247 +            context->hidden.windowsio.h = INVALID_HANDLE_VALUE;   /* to be sure */
   1.248          }
   1.249 -        if (context->hidden.win32io.buffer.data) {
   1.250 -            SDL_free(context->hidden.win32io.buffer.data);
   1.251 -            context->hidden.win32io.buffer.data = NULL;
   1.252 +        if (context->hidden.windowsio.buffer.data) {
   1.253 +            SDL_free(context->hidden.windowsio.buffer.data);
   1.254 +            context->hidden.windowsio.buffer.data = NULL;
   1.255          }
   1.256          SDL_FreeRW(context);
   1.257      }
   1.258      return (0);
   1.259  }
   1.260 -#endif /* __WIN32__ */
   1.261 +#endif /* __WINDOWS__ */
   1.262  
   1.263  #ifdef HAVE_STDIO_H
   1.264  
   1.265 @@ -449,18 +449,18 @@
   1.266          SDL_SetError("SDL_RWFromFile(): No file or no mode specified");
   1.267          return NULL;
   1.268      }
   1.269 -#if defined(__WIN32__)
   1.270 +#if defined(__WINDOWS__)
   1.271      rwops = SDL_AllocRW();
   1.272      if (!rwops)
   1.273          return NULL;            /* SDL_SetError already setup by SDL_AllocRW() */
   1.274 -    if (win32_file_open(rwops, file, mode) < 0) {
   1.275 +    if (windows_file_open(rwops, file, mode) < 0) {
   1.276          SDL_FreeRW(rwops);
   1.277          return NULL;
   1.278      }
   1.279 -    rwops->seek = win32_file_seek;
   1.280 -    rwops->read = win32_file_read;
   1.281 -    rwops->write = win32_file_write;
   1.282 -    rwops->close = win32_file_close;
   1.283 +    rwops->seek = windows_file_seek;
   1.284 +    rwops->read = windows_file_read;
   1.285 +    rwops->write = windows_file_write;
   1.286 +    rwops->close = windows_file_close;
   1.287  
   1.288  #elif HAVE_STDIO_H
   1.289  	#ifdef __APPLE__