]> mj.ucw.cz Git - libucw.git/blobdiff - lib/fb-file.c
Started v2.5.
[libucw.git] / lib / fb-file.c
index b5e6b6466f21c1c5bc5ba8fcc24c002562fea63d..cfc586bb3a69918ed27c1004b1fa717593709e17 100644 (file)
 #include <fcntl.h>
 #include <unistd.h>
 
+struct fb_file {
+  struct fastbuf fb;
+  int fd;                              /* File descriptor, -1 if not a real file */
+  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)
+
 static int
 bfd_refill(struct fastbuf *f)
 {
@@ -74,6 +81,19 @@ bfd_close(struct fastbuf *f)
   xfree(f);
 }
 
+static int
+bfd_config(struct fastbuf *f, uns item, int value)
+{
+  switch (item)
+    {
+    case BCONFIG_IS_TEMP_FILE:
+      FB_FILE(f)->is_temp_file = value;
+      return 0;
+    default:
+      return -1;
+    }
+}
+
 static struct fastbuf *
 bfdopen_internal(int fd, uns buflen, byte *name)
 {
@@ -92,6 +112,7 @@ bfdopen_internal(int fd, uns buflen, byte *name)
   f->spout = bfd_spout;
   f->seek = bfd_seek;
   f->close = bfd_close;
+  f->config = bfd_config;
   return f;
 }
 
@@ -99,7 +120,11 @@ struct fastbuf *
 bopen(byte *name, uns mode, uns buffer)
 {
   struct fastbuf *b;
-  int fd = sh_open(name, mode, 0666);
+  int fd;
+
+  if (!buffer)
+    return bopen_mm(name, mode);
+  fd = sh_open(name, mode, 0666);
   if (fd < 0)
     die("Unable to %s file %s: %m",
        (mode & O_CREAT) ? "create" : "open", name);