misc/libphyslayer/physfsrwops.c
changeset 13538 f8c0a62fa3ac
parent 11656 227718170097
child 13912 d178a834f1f4
equal deleted inserted replaced
13537:ecdf6ce2301e 13538:f8c0a62fa3ac
    54     {
    54     {
    55         const PHYSFS_sint64 current = PHYSFS_tell(handle);
    55         const PHYSFS_sint64 current = PHYSFS_tell(handle);
    56         if (current == -1)
    56         if (current == -1)
    57         {
    57         {
    58             SDL_SetError("Can't find position in file: %s",
    58             SDL_SetError("Can't find position in file: %s",
    59                           PHYSFS_getLastError());
    59                           PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
    60             return -1;
    60             return -1;
    61         } /* if */
    61         } /* if */
    62 
    62 
    63         if (offset == 0)  /* this is a "tell" call. We're done. */
    63         if (offset == 0)  /* this is a "tell" call. We're done. */
    64         {
    64         {
    75     else if (whence == SEEK_END)
    75     else if (whence == SEEK_END)
    76     {
    76     {
    77         const PHYSFS_sint64 len = PHYSFS_fileLength(handle);
    77         const PHYSFS_sint64 len = PHYSFS_fileLength(handle);
    78         if (len == -1)
    78         if (len == -1)
    79         {
    79         {
    80             SDL_SetError("Can't find end of file: %s", PHYSFS_getLastError());
    80             SDL_SetError("Can't find end of file: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
    81             return -1;
    81             return -1;
    82         } /* if */
    82         } /* if */
    83 
    83 
    84         pos = len + ((PHYSFS_sint64) offset);
    84         pos = len + ((PHYSFS_sint64) offset);
    85     } /* else if */
    85     } /* else if */
    96         return -1;
    96         return -1;
    97     } /* if */
    97     } /* if */
    98 
    98 
    99     if (!PHYSFS_seek(handle, (PHYSFS_uint64) pos))
    99     if (!PHYSFS_seek(handle, (PHYSFS_uint64) pos))
   100     {
   100     {
   101         SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
   101         SDL_SetError("PhysicsFS error: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
   102         return -1;
   102         return -1;
   103     } /* if */
   103     } /* if */
   104 
   104 
   105     #if TARGET_SDL13
   105     #if TARGET_SDL13
   106     return (long) pos;
   106     return (long) pos;
   121     const PHYSFS_uint64 readlen = (PHYSFS_uint64) (maxnum * size);
   121     const PHYSFS_uint64 readlen = (PHYSFS_uint64) (maxnum * size);
   122     const PHYSFS_sint64 rc = PHYSFS_readBytes(handle, ptr, readlen);
   122     const PHYSFS_sint64 rc = PHYSFS_readBytes(handle, ptr, readlen);
   123     if (rc != ((PHYSFS_sint64) readlen))
   123     if (rc != ((PHYSFS_sint64) readlen))
   124     {
   124     {
   125         if (!PHYSFS_eof(handle)) /* not EOF? Must be an error. */
   125         if (!PHYSFS_eof(handle)) /* not EOF? Must be an error. */
   126             SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
   126             SDL_SetError("PhysicsFS error: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
   127     } /* if */
   127     } /* if */
   128 
   128 
   129     #if TARGET_SDL13
   129     #if TARGET_SDL13
   130     return (size_t) rc;
   130     return (size_t) rc;
   131     #else
   131     #else
   143 {
   143 {
   144     PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
   144     PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
   145     const PHYSFS_uint64 writelen = (PHYSFS_uint64) (num * size);
   145     const PHYSFS_uint64 writelen = (PHYSFS_uint64) (num * size);
   146     const PHYSFS_sint64 rc = PHYSFS_writeBytes(handle, ptr, writelen);
   146     const PHYSFS_sint64 rc = PHYSFS_writeBytes(handle, ptr, writelen);
   147     if (rc != ((PHYSFS_sint64) writelen))
   147     if (rc != ((PHYSFS_sint64) writelen))
   148         SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
   148         SDL_SetError("PhysicsFS error: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
   149 
   149 
   150     #if TARGET_SDL13
   150     #if TARGET_SDL13
   151     return (size_t) rc;
   151     return (size_t) rc;
   152     #else
   152     #else
   153     return (int) rc;
   153     return (int) rc;
   158 static int physfsrwops_close(SDL_RWops *rw)
   158 static int physfsrwops_close(SDL_RWops *rw)
   159 {
   159 {
   160     PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
   160     PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
   161     if (!PHYSFS_close(handle))
   161     if (!PHYSFS_close(handle))
   162     {
   162     {
   163         SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
   163         SDL_SetError("PhysicsFS error: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
   164         return -1;
   164         return -1;
   165     } /* if */
   165     } /* if */
   166 
   166 
   167     SDL_FreeRW(rw);
   167     SDL_FreeRW(rw);
   168     return 0;
   168     return 0;
   172 static SDL_RWops *create_rwops(PHYSFS_File *handle)
   172 static SDL_RWops *create_rwops(PHYSFS_File *handle)
   173 {
   173 {
   174     SDL_RWops *retval = NULL;
   174     SDL_RWops *retval = NULL;
   175 
   175 
   176     if (handle == NULL)
   176     if (handle == NULL)
   177         SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
   177         SDL_SetError("PhysicsFS error: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
   178     else
   178     else
   179     {
   179     {
   180         retval = SDL_AllocRW();
   180         retval = SDL_AllocRW();
   181         if (retval != NULL)
   181         if (retval != NULL)
   182         {
   182         {