src/core/android/SDL_android.cpp
changeset 6642 b716011e53ce
parent 6630 55910871076b
child 6650 d36232135316
     1.1 --- a/src/core/android/SDL_android.cpp	Sat Nov 03 12:11:49 2012 -0400
     1.2 +++ b/src/core/android/SDL_android.cpp	Sat Nov 03 18:43:36 2012 -0700
     1.3 @@ -696,9 +696,14 @@
     1.4  }
     1.5  
     1.6  
     1.7 -extern "C" long Android_JNI_FileSeek(SDL_RWops* ctx, long offset, int whence)
     1.8 +extern "C" Sint64 Android_JNI_FileSize(SDL_RWops* ctx)
     1.9  {
    1.10 -    long newPosition;
    1.11 +    return ctx->hidden.androidio.size;
    1.12 +}
    1.13 +
    1.14 +extern "C" Sint64 Android_JNI_FileSeek(SDL_RWops* ctx, Sint64 offset, int whence)
    1.15 +{
    1.16 +    Sint64 newPosition;
    1.17  
    1.18      switch (whence) {
    1.19          case RW_SEEK_SET:
    1.20 @@ -714,27 +719,27 @@
    1.21              SDL_SetError("Unknown value for 'whence'");
    1.22              return -1;
    1.23      }
    1.24 +
    1.25 +    /* Validate the new position */
    1.26      if (newPosition < 0) {
    1.27 -        newPosition = 0;
    1.28 +        SDL_Error(SDL_EFSEEK);
    1.29 +        return -1;
    1.30      }
    1.31      if (newPosition > ctx->hidden.androidio.size) {
    1.32          newPosition = ctx->hidden.androidio.size;
    1.33      }
    1.34  
    1.35 -    long movement = newPosition - ctx->hidden.androidio.position;
    1.36 -    jobject inputStream = (jobject)ctx->hidden.androidio.inputStreamRef;
    1.37 -
    1.38 +    Sint64 movement = newPosition - ctx->hidden.androidio.position;
    1.39      if (movement > 0) {
    1.40          unsigned char buffer[1024];
    1.41  
    1.42          // The easy case where we're seeking forwards
    1.43          while (movement > 0) {
    1.44 -            long amount = (long) sizeof (buffer);
    1.45 +            Sint64 amount = sizeof (buffer);
    1.46              if (amount > movement) {
    1.47                  amount = movement;
    1.48              }
    1.49              size_t result = Android_JNI_FileRead(ctx, buffer, 1, amount);
    1.50 -
    1.51              if (result <= 0) {
    1.52                  // Failed to read/skip the required amount, so fail
    1.53                  return -1;
    1.54 @@ -742,6 +747,7 @@
    1.55  
    1.56              movement -= result;
    1.57          }
    1.58 +
    1.59      } else if (movement < 0) {
    1.60          // We can't seek backwards so we have to reopen the file and seek
    1.61          // forwards which obviously isn't very efficient
    1.62 @@ -750,8 +756,6 @@
    1.63          Android_JNI_FileSeek(ctx, newPosition, RW_SEEK_SET);
    1.64      }
    1.65  
    1.66 -    ctx->hidden.androidio.position = newPosition;
    1.67 -
    1.68      return ctx->hidden.androidio.position;
    1.69  }
    1.70