Hello,

this patch adds support for SEEK_SET and SEEK_END seeking for XFILE in the HEAD
branch. I need it for the smbclient's command reput (i.e. continue with the put
where it finished when the connection had broken or transfer had been terminated).

Patch follows.

Josef


diff -ur samba.cvs/source/lib/xfile.c samba.seek/source/lib/xfile.c
--- samba.cvs/source/lib/xfile.c        Fri Jul 19 06:00:21 2002
+++ samba.seek/source/lib/xfile.c       Tue Aug 20 08:18:07 2002
@@ -25,7 +25,7 @@
   XFILE replaces stdio. It is less efficient, but at least it works
   when you have lots of files open
 
-  The main restriction on XFILE is that it doesn't support seeking,
+  The main restriction on XFILE is that it doesn't support SEEK_CUR
   and doesn't support O_RDWR. That keeps the code simple.
 */
 
@@ -341,3 +341,33 @@
        *s = 0;
        return s0;
 }
+
+off_t x_lseek(XFILE *f, off_t offset, int whence)
+{
+       if (x_ferror(f))
+               return -1;
+
+       /* only SEEK_SET and SEEK_END are supported */
+       /* SEEK_CUR needs internal offset counter */
+       if (whence != SEEK_SET && whence != SEEK_END) {
+               errno = EINVAL;
+               return -1;
+       }
+
+       /* empty the buffer */
+       switch (f->open_flags & O_ACCMODE) {
+       case O_RDONLY:
+               f->bufused = 0;
+               break;
+       case O_WRONLY:
+               if (x_fflush(f) != 0)
+                       return -1;
+               break;
+       default:
+               errno = EINVAL;
+               return -1;
+       }
+
+       f->flags &= ~X_FLAG_EOF;
+       return sys_lseek(f->fd, offset, whence);
+}

Reply via email to