X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Ffb-file.c;h=9ef992a8b6bf9cf80f3006a579f4000923ddfbc6;hb=ba92e10cb8a623a5c59305b51f8ef364998cd871;hp=169f25e1a027ac858600b3824a7015a12994fbc7;hpb=49edfa12025a3552d1cfcd2a936201c1da95148a;p=libucw.git diff --git a/lib/fb-file.c b/lib/fb-file.c index 169f25e1..9ef992a8 100644 --- a/lib/fb-file.c +++ b/lib/fb-file.c @@ -1,8 +1,7 @@ /* - * Sherlock Library -- Fast Buffered I/O on Files + * UCW Library -- Fast Buffered I/O on Files * * (c) 1997--2004 Martin Mares - * (c) 2004 Robert Spalek * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -12,7 +11,6 @@ #include "lib/fastbuf.h" #include "lib/lfs.h" -#include #include #include #include @@ -120,20 +118,26 @@ bfdopen_internal(int fd, uns buflen, byte *name) } struct fastbuf * -bopen(byte *name, uns mode, uns buflen) +bopen_try(byte *name, uns mode, uns buflen) { - struct fastbuf *b; - int fd; + int fd = sh_open(name, mode, 0666); + if (fd < 0) + return NULL; + struct fastbuf *b = bfdopen_internal(fd, buflen, name); + if (mode & O_APPEND) + bfd_seek(b, 0, SEEK_END); + return b; +} +struct fastbuf * +bopen(byte *name, uns mode, uns buflen) +{ if (!buflen) return bopen_mm(name, mode); - fd = sh_open(name, mode, 0666); - if (fd < 0) + struct fastbuf *b = bopen_try(name, mode, buflen); + if (!b) die("Unable to %s file %s: %m", (mode & O_CREAT) ? "create" : "open", name); - b = bfdopen_internal(fd, buflen, name); - if (mode & O_APPEND) - bfd_seek(b, 0, SEEK_END); return b; } @@ -154,6 +158,14 @@ bfdopen_shared(int fd, uns buflen) return f; } +void +bfilesync(struct fastbuf *b) +{ + bflush(b); + if (fsync(FB_FILE(b)->fd) < 0) + log(L_ERROR, "fsync(%s) failed: %m", b->name); +} + #ifdef TEST int main(int argc, char **argv)