changeset 296:d8c0315deba9

Updated to fix bugs and deal with API breakage in PhysicsFS.
author Ryan C. Gordon <icculus@icculus.org>
date Mon, 25 Mar 2002 08:39:11 +0000
parents 5a7d5055823d
children e8d9255f1a42
files playsound/physfsrwops.c playsound/physfsrwops.h
diffstat 2 files changed, 30 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/playsound/physfsrwops.c	Mon Mar 18 04:52:19 2002 +0000
+++ b/playsound/physfsrwops.c	Mon Mar 25 08:39:11 2002 +0000
@@ -34,7 +34,7 @@
 
     else if (whence == SEEK_CUR)
     {
-        int current = PHYSFS_tell(handle);
+        PHYSFS_sint64 current = PHYSFS_tell(handle);
         if (current == -1)
         {
             SDL_SetError("Can't find position in file: %s",
@@ -42,22 +42,36 @@
             return(-1);
         } /* if */
 
+        pos = (int) current;
+        if ( ((PHYSFS_sint64) pos) != current )
+        {
+            SDL_SetError("Can't fit current file position in an int!");
+            return(-1);
+        } /* if */
+
         if (offset == 0)  /* this is a "tell" call. We're done. */
-            return(offset);
+            return(pos);
 
-        pos = current + offset;
+        pos += offset;
     } /* else if */
 
     else if (whence == SEEK_END)
     {
-        int len = PHYSFS_fileLength(handle);
+        PHYSFS_sint64 len = PHYSFS_fileLength(handle);
         if (len == -1)
         {
             SDL_SetError("Can't find end of file: %s", PHYSFS_getLastError());
             return(-1);
         } /* if */
 
-        pos = len + offset;
+        pos = (int) len;
+        if ( ((PHYSFS_sint64) pos) != len )
+        {
+            SDL_SetError("Can't fit end-of-file position in an int!");
+            return(-1);
+        } /* if */
+
+        pos += offset;
     } /* else if */
 
     else
@@ -66,7 +80,13 @@
         return(-1);
     } /* else */
 
-    if (!PHYSFS_seek(handle, pos))
+    if ( pos < 0 )
+    {
+        SDL_SetError("Attempt to seek past start of file.");
+        return(-1);
+    } /* if */
+    
+    if (!PHYSFS_seek(handle, (PHYSFS_uint64) pos))
     {
         SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
         return(-1);
@@ -79,25 +99,25 @@
 static int physfsrwops_read(SDL_RWops *rw, void *ptr, int size, int maxnum)
 {
     PHYSFS_file *handle = (PHYSFS_file *) rw->hidden.unknown.data1;
-    int rc = PHYSFS_read(handle, ptr, size, maxnum);
+    PHYSFS_sint64 rc = PHYSFS_read(handle, ptr, size, maxnum);
     if (rc != maxnum)
     {
         if (!PHYSFS_eof(handle)) /* not EOF? Must be an error. */
             SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
     } /* if */
 
-    return(rc);
+    return((int) rc);
 } /* physfsrwops_read */
 
 
 static int physfsrwops_write(SDL_RWops *rw, const void *ptr, int size, int num)
 {
     PHYSFS_file *handle = (PHYSFS_file *) rw->hidden.unknown.data1;
-    int rc = PHYSFS_write(handle, ptr, size, num);
+    PHYSFS_sint64 rc = PHYSFS_write(handle, ptr, size, num);
     if (rc != num)
         SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
 
-    return(rc);
+    return((int) rc);
 } /* physfsrwops_write */
 
 
--- a/playsound/physfsrwops.h	Mon Mar 18 04:52:19 2002 +0000
+++ b/playsound/physfsrwops.h	Mon Mar 25 08:39:11 2002 +0000
@@ -29,12 +29,6 @@
 extern "C" {
 #endif
 
-#if (defined _MSC_VER)
-#define __EXPORT__ __declspec(dllexport)
-#else
-#define __EXPORT__
-#endif
-
 /**
  * Open a platform-independent filename for reading, and make it accessible
  *  via an SDL_RWops structure. The file will be closed in PhysicsFS when the