src/file/SDL_rwops.c
changeset 8460 f483e8bdae3c
parent 8440 29e693ff8706
parent 7037 3fedf1f25b94
child 8464 a2a909304cfe
     1.1 --- a/src/file/SDL_rwops.c	Sat Apr 13 23:03:46 2013 -0400
     1.2 +++ b/src/file/SDL_rwops.c	Sun Apr 14 11:42:55 2013 -0400
     1.3 @@ -37,11 +37,6 @@
     1.4  #include "../core/android/SDL_android.h"
     1.5  #endif
     1.6  
     1.7 -#ifdef __NDS__
     1.8 -/* include libfat headers for fatInitDefault(). */
     1.9 -#include <fat.h>
    1.10 -#endif /* __NDS__ */
    1.11 -
    1.12  #ifdef __WIN32__
    1.13  
    1.14  /* Functions to read/write Win32 API file pointers */
    1.15 @@ -92,8 +87,7 @@
    1.16      context->hidden.windowsio.buffer.data =
    1.17          (char *) SDL_malloc(READAHEAD_BUFFER_SIZE);
    1.18      if (!context->hidden.windowsio.buffer.data) {
    1.19 -        SDL_OutOfMemory();
    1.20 -        return -1;
    1.21 +        return SDL_OutOfMemory();
    1.22      }
    1.23      /* Do not open a dialog box if failure */
    1.24      old_error_mode =
    1.25 @@ -129,13 +123,11 @@
    1.26      LARGE_INTEGER size;
    1.27  
    1.28      if (!context || context->hidden.windowsio.h == INVALID_HANDLE_VALUE) {
    1.29 -        SDL_SetError("windows_file_size: invalid context/file not opened");
    1.30 -        return -1;
    1.31 +        return SDL_SetError("windows_file_size: invalid context/file not opened");
    1.32      }
    1.33  
    1.34      if (!GetFileSizeEx(context->hidden.windowsio.h, &size)) {
    1.35 -        WIN_SetError("windows_file_size");
    1.36 -        return -1;
    1.37 +        return WIN_SetError("windows_file_size");
    1.38      }
    1.39  
    1.40      return size.QuadPart;
    1.41 @@ -148,8 +140,7 @@
    1.42      LARGE_INTEGER windowsoffset;
    1.43  
    1.44      if (!context || context->hidden.windowsio.h == INVALID_HANDLE_VALUE) {
    1.45 -        SDL_SetError("windows_file_seek: invalid context/file not opened");
    1.46 -        return -1;
    1.47 +        return SDL_SetError("windows_file_seek: invalid context/file not opened");
    1.48      }
    1.49  
    1.50      /* FIXME: We may be able to satisfy the seek within buffered data */
    1.51 @@ -169,14 +160,12 @@
    1.52          windowswhence = FILE_END;
    1.53          break;
    1.54      default:
    1.55 -        SDL_SetError("windows_file_seek: Unknown value for 'whence'");
    1.56 -        return -1;
    1.57 +        return SDL_SetError("windows_file_seek: Unknown value for 'whence'");
    1.58      }
    1.59  
    1.60      windowsoffset.QuadPart = offset;
    1.61      if (!SetFilePointerEx(context->hidden.windowsio.h, windowsoffset, &windowsoffset, windowswhence)) {
    1.62 -        WIN_SetError("windows_file_seek");
    1.63 -        return -1;
    1.64 +        return WIN_SetError("windows_file_seek");
    1.65      }
    1.66      return windowsoffset.QuadPart;
    1.67  }
    1.68 @@ -334,8 +323,7 @@
    1.69          return (ftell(context->hidden.stdio.fp));
    1.70      }
    1.71  #endif
    1.72 -    SDL_Error(SDL_EFSEEK);
    1.73 -    return (-1);
    1.74 +    return SDL_Error(SDL_EFSEEK);
    1.75  }
    1.76  
    1.77  static size_t SDLCALL
    1.78 @@ -370,8 +358,7 @@
    1.79          if (context->hidden.stdio.autoclose) {
    1.80              /* WARNING:  Check the return value here! */
    1.81              if (fclose(context->hidden.stdio.fp) != 0) {
    1.82 -                SDL_Error(SDL_EFWRITE);
    1.83 -                status = -1;
    1.84 +                status = SDL_Error(SDL_EFWRITE);
    1.85              }
    1.86          }
    1.87          SDL_FreeRW(context);
    1.88 @@ -404,8 +391,7 @@
    1.89          newpos = context->hidden.mem.stop + offset;
    1.90          break;
    1.91      default:
    1.92 -        SDL_SetError("Unknown value for 'whence'");
    1.93 -        return (-1);
    1.94 +        return SDL_SetError("Unknown value for 'whence'");
    1.95      }
    1.96      if (newpos < context->hidden.mem.base) {
    1.97          newpos = context->hidden.mem.base;
    1.98 @@ -455,7 +441,7 @@
    1.99  mem_writeconst(SDL_RWops * context, const void *ptr, size_t size, size_t num)
   1.100  {
   1.101      SDL_SetError("Can't write to read-only memory");
   1.102 -    return (-1);
   1.103 +    return (0);
   1.104  }
   1.105  
   1.106  static int SDLCALL
   1.107 @@ -517,6 +503,7 @@
   1.108      rwops->read = Android_JNI_FileRead;
   1.109      rwops->write = Android_JNI_FileWrite;
   1.110      rwops->close = Android_JNI_FileClose;
   1.111 +    rwops->type = SDL_RWOPS_JNIFILE;
   1.112  
   1.113  #elif defined(__WIN32__)
   1.114      rwops = SDL_AllocRW();
   1.115 @@ -531,6 +518,7 @@
   1.116      rwops->read = windows_file_read;
   1.117      rwops->write = windows_file_write;
   1.118      rwops->close = windows_file_close;
   1.119 +    rwops->type = SDL_RWOPS_WINFILE;
   1.120  
   1.121  #elif HAVE_STDIO_H
   1.122      {
   1.123 @@ -561,13 +549,6 @@
   1.124  {
   1.125      SDL_RWops *rwops = NULL;
   1.126  
   1.127 -#if 0
   1.128 -/*#ifdef __NDS__*/
   1.129 -    /* set it up so we can use stdio file function */
   1.130 -    fatInitDefault();
   1.131 -    printf("called fatInitDefault()");
   1.132 -#endif /* __NDS__ */
   1.133 -
   1.134      rwops = SDL_AllocRW();
   1.135      if (rwops != NULL) {
   1.136          rwops->size = stdio_size;
   1.137 @@ -577,6 +558,7 @@
   1.138          rwops->close = stdio_close;
   1.139          rwops->hidden.stdio.fp = fp;
   1.140          rwops->hidden.stdio.autoclose = autoclose;
   1.141 +        rwops->type = SDL_RWOPS_STDFILE;
   1.142      }
   1.143      return (rwops);
   1.144  }
   1.145 @@ -592,7 +574,15 @@
   1.146  SDL_RWops *
   1.147  SDL_RWFromMem(void *mem, int size)
   1.148  {
   1.149 -    SDL_RWops *rwops;
   1.150 +    SDL_RWops *rwops = NULL;
   1.151 +    if (!mem) {
   1.152 +      SDL_InvalidParamError("mem");
   1.153 +      return (rwops);
   1.154 +    }
   1.155 +    if (!size) {
   1.156 +      SDL_InvalidParamError("size");
   1.157 +      return (rwops);
   1.158 +    }
   1.159  
   1.160      rwops = SDL_AllocRW();
   1.161      if (rwops != NULL) {
   1.162 @@ -604,6 +594,7 @@
   1.163          rwops->hidden.mem.base = (Uint8 *) mem;
   1.164          rwops->hidden.mem.here = rwops->hidden.mem.base;
   1.165          rwops->hidden.mem.stop = rwops->hidden.mem.base + size;
   1.166 +        rwops->type = SDL_RWOPS_MEMORY;
   1.167      }
   1.168      return (rwops);
   1.169  }
   1.170 @@ -611,7 +602,15 @@
   1.171  SDL_RWops *
   1.172  SDL_RWFromConstMem(const void *mem, int size)
   1.173  {
   1.174 -    SDL_RWops *rwops;
   1.175 +    SDL_RWops *rwops = NULL;
   1.176 +    if (!mem) {
   1.177 +      SDL_InvalidParamError("mem");
   1.178 +      return (rwops);
   1.179 +    }
   1.180 +    if (!size) {
   1.181 +      SDL_InvalidParamError("size");
   1.182 +      return (rwops);
   1.183 +    }
   1.184  
   1.185      rwops = SDL_AllocRW();
   1.186      if (rwops != NULL) {
   1.187 @@ -623,6 +622,7 @@
   1.188          rwops->hidden.mem.base = (Uint8 *) mem;
   1.189          rwops->hidden.mem.here = rwops->hidden.mem.base;
   1.190          rwops->hidden.mem.stop = rwops->hidden.mem.base + size;
   1.191 +        rwops->type = SDL_RWOPS_MEMORY_RO;
   1.192      }
   1.193      return (rwops);
   1.194  }
   1.195 @@ -636,6 +636,7 @@
   1.196      if (area == NULL) {
   1.197          SDL_OutOfMemory();
   1.198      }
   1.199 +    area->type = SDL_RWOPS_UNKNOWN;
   1.200      return (area);
   1.201  }
   1.202