X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Ffb-file.c;h=04f2f4cf444442141fcfb3b4e74d5e852a9f1a99;hb=580fd9c443c2a4faba5a703d49f366de5d3968c9;hp=9ef992a8b6bf9cf80f3006a579f4000923ddfbc6;hpb=4f3517ad5229aa39d1bbe403577328813800f8d2;p=libucw.git diff --git a/lib/fb-file.c b/lib/fb-file.c index 9ef992a8..04f2f4cf 100644 --- a/lib/fb-file.c +++ b/lib/fb-file.c @@ -11,13 +11,14 @@ #include "lib/fastbuf.h" #include "lib/lfs.h" +#include #include #include #include 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) @@ -53,18 +54,14 @@ bfd_spout(struct fastbuf *f) f->bptr = f->buffer = FB_BUFFER(f); } -static void +static int 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) - die("lseek on %s: %m", f->name); + return 0; f->pos = l; + return 1; } static void @@ -74,7 +71,7 @@ bfd_close(struct fastbuf *f) { case 1: if (unlink(f->name) < 0) - log(L_ERROR, "unlink(%s): %m", f->name); + msg(L_ERROR, "unlink(%s): %m", f->name); case 0: close(FB_FILE(f)->fd); } @@ -95,7 +92,7 @@ bfd_config(struct fastbuf *f, uns item, int value) } static struct fastbuf * -bfdopen_internal(int fd, uns buflen, byte *name) +bfdopen_internal(int fd, uns buflen, const char *name) { int namelen = strlen(name) + 1; struct fb_file *F = xmalloc(sizeof(struct fb_file) + buflen + namelen); @@ -118,7 +115,7 @@ bfdopen_internal(int fd, uns buflen, byte *name) } struct fastbuf * -bopen_try(byte *name, uns mode, uns buflen) +bopen_try(const char *name, uns mode, uns buflen) { int fd = sh_open(name, mode, 0666); if (fd < 0) @@ -130,7 +127,7 @@ bopen_try(byte *name, uns mode, uns buflen) } struct fastbuf * -bopen(byte *name, uns mode, uns buflen) +bopen(const char *name, uns mode, uns buflen) { if (!buflen) return bopen_mm(name, mode); @@ -163,12 +160,12 @@ bfilesync(struct fastbuf *b) { bflush(b); if (fsync(FB_FILE(b)->fd) < 0) - log(L_ERROR, "fsync(%s) failed: %m", b->name); + msg(L_ERROR, "fsync(%s) failed: %m", b->name); } #ifdef TEST -int main(int argc, char **argv) +int main(int argc UNUSED, char **argv UNUSED) { struct fastbuf *f, *t;