#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)
{
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)
{
f->spout = bfd_spout;
f->seek = bfd_seek;
f->close = bfd_close;
+ f->config = bfd_config;
return f;
}
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);