changeset 3138:3eca96f6a73f trunk

Rewrite VFSBufferedFile::fseek(), now far less buggy!
author William Pitcock <nenolod@atheme-project.org>
date Sat, 21 Jul 2007 15:50:13 -0500
parents 25f92bfd50c4
children c7fca96bfc78
files src/audacious/vfs_buffered_file.c
diffstat 1 files changed, 26 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/vfs_buffered_file.c	Fri Jul 20 20:59:15 2007 -0500
+++ b/src/audacious/vfs_buffered_file.c	Sat Jul 21 15:50:13 2007 -0500
@@ -116,14 +116,33 @@
 
     vfs_fseek(handle->buffer, offset, whence);
 
-    /* if we go OOB, switch to live FD */
-    if (vfs_ftell(handle->buffer) > ((VFSBuffer *) handle->buffer->handle)->size)
+    switch(whence)
     {
-        vfs_rewind(handle->buffer);
-        handle->which = TRUE;
-        vfs_fseek(handle->buffer, offset, whence);
+        case SEEK_END:
+            handle->which = TRUE;
+            vfs_fseek(handle->fd, offset, whence);
+            break;
+        case SEEK_CUR:
+            if (vfs_ftell(handle->buffer) + offset > ((VFSBuffer *) handle->buffer->handle)->size)
+            {
+                handle->which = TRUE;
+                vfs_fseek(handle->fd, offset, whence);
+            }                
+            break;
+        case SEEK_SET:
+        default:
+            if (offset > ((VFSBuffer *) handle->buffer->handle)->size)
+            {
+                handle->which = TRUE;
+                vfs_fseek(handle->fd, offset, whence);
+            }
+            else
+            {
+                handle->which = FALSE;
+                vfs_fseek(handle->buffer, offset, whence);
+            }
+            break;
     }
-
     return 0;
 }
 
@@ -215,6 +234,7 @@
     }
 
     sz = vfs_fread(fd->mem, 1, 40000, fd->fd);
+    vfs_rewind(fd->fd);
 
     if (!sz)
     {