- uns rf = f->bstop - f->bptr;
- uns tbuflen = t->bufend - t->buffer;
-
- ASSERT(f->close == bfd_close);
- ASSERT(t->close == bfd_close);
- if (!l)
- return;
- if (rf)
- {
- uns k = MIN(rf, l);
- bwrite(t, f->bptr, k);
- f->bptr += k;
- l -= k;
- if (!l)
- return;
- }
- while (l >= tbuflen)
- {
- t->spout(t);
- if ((uns) read(FB_FILE(f)->fd, t->buffer, tbuflen) != tbuflen)
- die("bbcopy: %s exhausted", f->name);
- f->pos += tbuflen;
- f->bstop = f->bptr = f->buffer;
- t->bptr = t->bufend;
- l -= tbuflen;
- }
- while (l)
- {
- uns k = t->bufend - t->bptr;
-
- if (!k)
- {
- t->spout(t);
- k = t->bufend - t->bptr;
- }
- if (k > l)
- k = l;
- bread(f, t->bptr, k);
- t->bptr += k;
- l -= k;
- }
+ struct fastbuf *f = bfdopen(fd, buflen);
+ FB_FILE(f)->is_temp_file = -1;
+ return f;
+}
+
+void
+bfilesync(struct fastbuf *b)
+{
+ bflush(b);
+ if (fsync(FB_FILE(b)->fd) < 0)
+ log(L_ERROR, "fsync(%s) failed: %m", b->name);