extras/physfsrwops.c
changeset 654 c0ae01de361d
parent 576 5da65f8e9a50
child 767 db29bf06d171
equal deleted inserted replaced
653:89d56fcb2b40 654:c0ae01de361d
    23 #include <stdio.h>  /* used for SEEK_SET, SEEK_CUR, SEEK_END ... */
    23 #include <stdio.h>  /* used for SEEK_SET, SEEK_CUR, SEEK_END ... */
    24 #include "physfsrwops.h"
    24 #include "physfsrwops.h"
    25 
    25 
    26 static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence)
    26 static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence)
    27 {
    27 {
    28     PHYSFS_file *handle = (PHYSFS_file *) rw->hidden.unknown.data1;
    28     PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
    29     int pos = 0;
    29     int pos = 0;
    30 
    30 
    31     if (whence == SEEK_SET)
    31     if (whence == SEEK_SET)
    32     {
    32     {
    33         pos = offset;
    33         pos = offset;
    97 } /* physfsrwops_seek */
    97 } /* physfsrwops_seek */
    98 
    98 
    99 
    99 
   100 static int physfsrwops_read(SDL_RWops *rw, void *ptr, int size, int maxnum)
   100 static int physfsrwops_read(SDL_RWops *rw, void *ptr, int size, int maxnum)
   101 {
   101 {
   102     PHYSFS_file *handle = (PHYSFS_file *) rw->hidden.unknown.data1;
   102     PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
   103     PHYSFS_sint64 rc = PHYSFS_read(handle, ptr, size, maxnum);
   103     PHYSFS_sint64 rc = PHYSFS_read(handle, ptr, size, maxnum);
   104     if (rc != maxnum)
   104     if (rc != maxnum)
   105     {
   105     {
   106         if (!PHYSFS_eof(handle)) /* not EOF? Must be an error. */
   106         if (!PHYSFS_eof(handle)) /* not EOF? Must be an error. */
   107             SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
   107             SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
   111 } /* physfsrwops_read */
   111 } /* physfsrwops_read */
   112 
   112 
   113 
   113 
   114 static int physfsrwops_write(SDL_RWops *rw, const void *ptr, int size, int num)
   114 static int physfsrwops_write(SDL_RWops *rw, const void *ptr, int size, int num)
   115 {
   115 {
   116     PHYSFS_file *handle = (PHYSFS_file *) rw->hidden.unknown.data1;
   116     PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
   117     PHYSFS_sint64 rc = PHYSFS_write(handle, ptr, size, num);
   117     PHYSFS_sint64 rc = PHYSFS_write(handle, ptr, size, num);
   118     if (rc != num)
   118     if (rc != num)
   119         SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
   119         SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
   120 
   120 
   121     return((int) rc);
   121     return((int) rc);
   122 } /* physfsrwops_write */
   122 } /* physfsrwops_write */
   123 
   123 
   124 
   124 
   125 static int physfsrwops_close(SDL_RWops *rw)
   125 static int physfsrwops_close(SDL_RWops *rw)
   126 {
   126 {
   127     PHYSFS_file *handle = (PHYSFS_file *) rw->hidden.unknown.data1;
   127     PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
   128     if (!PHYSFS_close(handle))
   128     if (!PHYSFS_close(handle))
   129     {
   129     {
   130         SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
   130         SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
   131         return(-1);
   131         return(-1);
   132     } /* if */
   132     } /* if */
   134     SDL_FreeRW(rw);
   134     SDL_FreeRW(rw);
   135     return(0);
   135     return(0);
   136 } /* physfsrwops_close */
   136 } /* physfsrwops_close */
   137 
   137 
   138 
   138 
   139 static SDL_RWops *create_rwops(PHYSFS_file *handle)
   139 static SDL_RWops *create_rwops(PHYSFS_File *handle)
   140 {
   140 {
   141     SDL_RWops *retval = NULL;
   141     SDL_RWops *retval = NULL;
   142 
   142 
   143     if (handle == NULL)
   143     if (handle == NULL)
   144         SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
   144         SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
   157 
   157 
   158     return(retval);
   158     return(retval);
   159 } /* create_rwops */
   159 } /* create_rwops */
   160 
   160 
   161 
   161 
   162 SDL_RWops *PHYSFSRWOPS_makeRWops(PHYSFS_file *handle)
   162 SDL_RWops *PHYSFSRWOPS_makeRWops(PHYSFS_File *handle)
   163 {
   163 {
   164     SDL_RWops *retval = NULL;
   164     SDL_RWops *retval = NULL;
   165     if (handle == NULL)
   165     if (handle == NULL)
   166         SDL_SetError("NULL pointer passed to PHYSFSRWOPS_makeRWops().");
   166         SDL_SetError("NULL pointer passed to PHYSFSRWOPS_makeRWops().");
   167     else
   167     else