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