]> mj.ucw.cz Git - libucw.git/blobdiff - lib/fb-file.c
Implemented base-224 encoder and decoder.
[libucw.git] / lib / fb-file.c
index 07b4ec5ddf2d5f79343c979468d60053717724f2..ac25dcf3e954b1c663dcc5b288ba33625302abd4 100644 (file)
@@ -4,15 +4,15 @@
  *     (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/lib.h"
-#include "lib/fastbuf.h"
-#include "lib/lfs.h"
-
 static int
 bfd_refill(struct fastbuf *f)
 {
@@ -64,13 +64,15 @@ static void
 bfd_close(struct fastbuf *f)
 {
   close(f->fd);
+  if (f->is_temp_file && unlink(f->name) < 0)
+    die("unlink(%s): %m", f->name);
 }
 
 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);
@@ -78,7 +80,6 @@ bfdopen_internal(int fd, uns buflen, byte *name)
   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;