* (c) 1997--2000 Martin Mares <mj@ucw.cz>
*/
+#include "lib/lib.h"
+#include "lib/fastbuf.h"
+#include "lib/lfs.h"
+
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
-#include "lib.h"
-#include "fastbuf.h"
-#include "lfs.h"
-
static int
bfd_refill(struct fastbuf *f)
{
bfd_close(struct fastbuf *f)
{
close(f->fd);
+ if (f->is_temp_file && unlink(f->name) < 0)
+ die("unlink(%s): %m", f->name);
}
-struct fastbuf *
+static struct fastbuf *
bfdopen_internal(int fd, uns buflen, byte *name)
{
int namelen = strlen(name) + 1;
- struct fastbuf *b = xmalloc(sizeof(struct fastbuf) + buflen + namelen);
+ struct fastbuf *b = xmalloc_zero(sizeof(struct fastbuf) + buflen + namelen);
b->buflen = buflen;
b->buffer = (char *)(b+1);
b->bufend = b->buffer + buflen;
b->name = b->bufend;
strcpy(b->name, name);
- b->pos = b->fdpos = 0;
b->fd = fd;
b->refill = bfd_refill;
b->spout = bfd_spout;