]> mj.ucw.cz Git - libucw.git/blobdiff - lib/fb-file.c
Patrik needs lib/binsearch.h in the library package.
[libucw.git] / lib / fb-file.c
index 9ef992a8b6bf9cf80f3006a579f4000923ddfbc6..a7290cbf8688f9de261a38c4e50dbb9584eee91e 100644 (file)
 #include "lib/fastbuf.h"
 #include "lib/lfs.h"
 
 #include "lib/fastbuf.h"
 #include "lib/lfs.h"
 
+#include <stdio.h>
 #include <string.h>
 #include <fcntl.h>
 #include <unistd.h>
 
 struct fb_file {
   struct fastbuf fb;
 #include <string.h>
 #include <fcntl.h>
 #include <unistd.h>
 
 struct fb_file {
   struct fastbuf fb;
-  int fd;                              /* File descriptor, -1 if not a real file */
+  int fd;                              /* File descriptor */
   int is_temp_file;                    /* 0=normal file, 1=temporary file, delete on close, -1=shared FD */
 };
 #define FB_FILE(f) ((struct fb_file *)(f)->is_fastbuf)
   int is_temp_file;                    /* 0=normal file, 1=temporary file, delete on close, -1=shared FD */
 };
 #define FB_FILE(f) ((struct fb_file *)(f)->is_fastbuf)
@@ -53,18 +54,14 @@ bfd_spout(struct fastbuf *f)
   f->bptr = f->buffer = FB_BUFFER(f);
 }
 
   f->bptr = f->buffer = FB_BUFFER(f);
 }
 
-static void
+static int
 bfd_seek(struct fastbuf *f, sh_off_t pos, int whence)
 {
 bfd_seek(struct fastbuf *f, sh_off_t pos, int whence)
 {
-  sh_off_t l;
-
-  if (whence == SEEK_SET && pos == f->pos)
-    return;
-
-  l = sh_seek(FB_FILE(f)->fd, pos, whence);
+  sh_off_t l = sh_seek(FB_FILE(f)->fd, pos, whence);
   if (l < 0)
   if (l < 0)
-    die("lseek on %s: %m", f->name);
+    return 0;
   f->pos = l;
   f->pos = l;
+  return 1;
 }
 
 static void
 }
 
 static void
@@ -168,7 +165,7 @@ bfilesync(struct fastbuf *b)
 
 #ifdef TEST
 
 
 #ifdef TEST
 
-int main(int argc, char **argv)
+int main(int argc UNUSED, char **argv UNUSED)
 {
   struct fastbuf *f, *t;
 
 {
   struct fastbuf *f, *t;