]> mj.ucw.cz Git - libucw.git/blobdiff - lib/fb-file.c
workqueue: Added non-blocking wait functions.
[libucw.git] / lib / fb-file.c
index cbfe1b0ca31fc2771a92a4a5a5670d8f27a6d4b8..9ef992a8b6bf9cf80f3006a579f4000923ddfbc6 100644 (file)
@@ -11,7 +11,6 @@
 #include "lib/fastbuf.h"
 #include "lib/lfs.h"
 
-#include <stdlib.h>
 #include <string.h>
 #include <fcntl.h>
 #include <unistd.h>
@@ -119,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;
 }