diff options
-rw-r--r-- | examples/example_custom.c | 4 | ||||
-rw-r--r-- | include/kitchensink/kitsource.h | 2 | ||||
-rw-r--r-- | src/kitsource.c | 17 |
3 files changed, 11 insertions, 12 deletions
diff --git a/examples/example_custom.c b/examples/example_custom.c index 2f84b99..d666550 100644 --- a/examples/example_custom.c +++ b/examples/example_custom.c @@ -24,8 +24,8 @@ int read_callback(void *userdata, uint8_t *buf, int buf_size) { int64_t seek_callback(void *userdata, int64_t offset, int whence) { FILE *fd = (FILE*)userdata; - if(whence == 3) { // AVSEEK_SIZE - return -1; // Not supported + if(whence != SEEK_SET && whence != SEEK_END && whence != SEEK_CUR) { + return -1; // AVSEEK_SIZE, AVSEEK_FORCE Not supported } if(fseek(fd, offset, whence)) { return ftell(fd); diff --git a/include/kitchensink/kitsource.h b/include/kitchensink/kitsource.h index 533e233..9b744ca 100644 --- a/include/kitchensink/kitsource.h +++ b/include/kitchensink/kitsource.h @@ -87,6 +87,8 @@ typedef int (*Kit_ReadCallback)(void *userdata, uint8_t *buf, int size); * - SEEK_CUR: Reference position is the current position of the file pointer * - SEEK_END: Reference position is the end of the file * - AVSEEK_SIZE: Optional. Does not seek, instead finds the size of the source file. + * - AVSEEK_FORCE: Optional. Suggests that seeking should be done at any cost. May be passed alongside + * any of the SEEK_* flags, eg. SEEK_SET|AVSEEK_FORCE. * * The function must return the position (in bytes) we seeked to or <0 on error or on unsupported operation. * diff --git a/src/kitsource.c b/src/kitsource.c index fddb410..71a73b0 100644 --- a/src/kitsource.c +++ b/src/kitsource.c @@ -137,17 +137,14 @@ static int64_t _RWGetSize(SDL_RWops *rw_ops) { static int64_t _RWSeekCallback(void *userdata, int64_t offset, int whence) { int rw_whence = 0; - // Looking for file size. Will return size of -1 if not supported. - if(whence == AVSEEK_SIZE) { + if(whence & AVSEEK_SIZE) return _RWGetSize(userdata); - } - - // RW and normal seeks *should* be the same, but it's not guaranteed by docs. - switch(whence) { - case SEEK_CUR: rw_whence = RW_SEEK_CUR; break; - case SEEK_SET: rw_whence = RW_SEEK_SET; break; - case SEEK_END: rw_whence = RW_SEEK_END; break; - } + if((whence & ~AVSEEK_FORCE) == SEEK_CUR) + rw_whence = RW_SEEK_CUR; + if((whence & ~AVSEEK_FORCE) == SEEK_SET) + rw_whence = RW_SEEK_SET; + if((whence & ~AVSEEK_FORCE) == SEEK_END) + rw_whence = RW_SEEK_END; if(SDL_RWseek((SDL_RWops*)userdata, offset, rw_whence) < 0) { return -1; |