extras/physfsrwops.c
changeset 1631 1aec60db9326
parent 1630 5123a32160af
equal deleted inserted replaced
1630:5123a32160af 1631:1aec60db9326
    68     {
    68     {
    69         const PHYSFS_sint64 current = PHYSFS_tell(handle);
    69         const PHYSFS_sint64 current = PHYSFS_tell(handle);
    70         if (current == -1)
    70         if (current == -1)
    71         {
    71         {
    72             SDL_SetError("Can't find position in file: %s",
    72             SDL_SetError("Can't find position in file: %s",
    73                           PHYSFS_getLastError());
    73                           PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
    74             return -1;
    74             return -1;
    75         } /* if */
    75         } /* if */
    76 
    76 
    77         if (offset == 0)  /* this is a "tell" call. We're done. */
    77         if (offset == 0)  /* this is a "tell" call. We're done. */
    78         {
    78         {
    89     else if (whence == RW_SEEK_END)
    89     else if (whence == RW_SEEK_END)
    90     {
    90     {
    91         const PHYSFS_sint64 len = PHYSFS_fileLength(handle);
    91         const PHYSFS_sint64 len = PHYSFS_fileLength(handle);
    92         if (len == -1)
    92         if (len == -1)
    93         {
    93         {
    94             SDL_SetError("Can't find end of file: %s", PHYSFS_getLastError());
    94             SDL_SetError("Can't find end of file: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
    95             return -1;
    95             return -1;
    96         } /* if */
    96         } /* if */
    97 
    97 
    98         pos = len + ((PHYSFS_sint64) offset);
    98         pos = len + ((PHYSFS_sint64) offset);
    99     } /* else if */
    99     } /* else if */
   110         return -1;
   110         return -1;
   111     } /* if */
   111     } /* if */
   112     
   112     
   113     if (!PHYSFS_seek(handle, (PHYSFS_uint64) pos))
   113     if (!PHYSFS_seek(handle, (PHYSFS_uint64) pos))
   114     {
   114     {
   115         SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
   115         SDL_SetError("PhysicsFS error: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
   116         return -1;
   116         return -1;
   117     } /* if */
   117     } /* if */
   118 
   118 
   119     #if TARGET_SDL2
   119     #if TARGET_SDL2
   120     return (Sint64) pos;
   120     return (Sint64) pos;
   136     const PHYSFS_sint64 rc = PHYSFS_readBytes(handle, ptr, readlen);
   136     const PHYSFS_sint64 rc = PHYSFS_readBytes(handle, ptr, readlen);
   137     if (rc != ((PHYSFS_sint64) readlen))
   137     if (rc != ((PHYSFS_sint64) readlen))
   138     {
   138     {
   139         if (!PHYSFS_eof(handle)) /* not EOF? Must be an error. */
   139         if (!PHYSFS_eof(handle)) /* not EOF? Must be an error. */
   140         {
   140         {
   141             SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
   141             SDL_SetError("PhysicsFS error: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
   142 
   142 
   143             #if TARGET_SDL2
   143             #if TARGET_SDL2
   144             return 0;
   144             return 0;
   145             #else
   145             #else
   146             return -1;
   146             return -1;
   165 {
   165 {
   166     PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
   166     PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
   167     const PHYSFS_uint64 writelen = (PHYSFS_uint64) (num * size);
   167     const PHYSFS_uint64 writelen = (PHYSFS_uint64) (num * size);
   168     const PHYSFS_sint64 rc = PHYSFS_writeBytes(handle, ptr, writelen);
   168     const PHYSFS_sint64 rc = PHYSFS_writeBytes(handle, ptr, writelen);
   169     if (rc != ((PHYSFS_sint64) writelen))
   169     if (rc != ((PHYSFS_sint64) writelen))
   170         SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
   170         SDL_SetError("PhysicsFS error: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
   171 
   171 
   172     #if TARGET_SDL2
   172     #if TARGET_SDL2
   173     return (size_t) rc;
   173     return (size_t) rc;
   174     #else
   174     #else
   175     return (int) rc;
   175     return (int) rc;
   180 static int physfsrwops_close(SDL_RWops *rw)
   180 static int physfsrwops_close(SDL_RWops *rw)
   181 {
   181 {
   182     PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
   182     PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
   183     if (!PHYSFS_close(handle))
   183     if (!PHYSFS_close(handle))
   184     {
   184     {
   185         SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
   185         SDL_SetError("PhysicsFS error: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
   186         return -1;
   186         return -1;
   187     } /* if */
   187     } /* if */
   188 
   188 
   189     SDL_FreeRW(rw);
   189     SDL_FreeRW(rw);
   190     return 0;
   190     return 0;
   194 static SDL_RWops *create_rwops(PHYSFS_File *handle)
   194 static SDL_RWops *create_rwops(PHYSFS_File *handle)
   195 {
   195 {
   196     SDL_RWops *retval = NULL;
   196     SDL_RWops *retval = NULL;
   197 
   197 
   198     if (handle == NULL)
   198     if (handle == NULL)
   199         SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
   199         SDL_SetError("PhysicsFS error: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
   200     else
   200     else
   201     {
   201     {
   202         retval = SDL_AllocRW();
   202         retval = SDL_AllocRW();
   203         if (retval != NULL)
   203         if (retval != NULL)
   204         {
   204         {