Lines Matching refs:bfp

108 	struct bf *bfp;
132 bfp = (struct bf *) sm_malloc(sizeof(struct bf));
133 if (bfp == NULL)
143 bfp->bf_buf = (char *) sm_malloc(bsize);
144 if (bfp->bf_buf == NULL)
146 bfp->bf_bufsize = 0;
147 sm_free(bfp);
153 bfp->bf_buf = NULL;
156 bfp->bf_committed = false;
157 bfp->bf_ondisk = false;
158 bfp->bf_flags = sflags;
159 bfp->bf_bufsize = bsize;
160 bfp->bf_buffilled = 0;
162 bfp->bf_filename = (char *) sm_malloc(l);
163 if (bfp->bf_filename == NULL)
165 if (bfp->bf_buf != NULL)
166 sm_free(bfp->bf_buf);
167 sm_free(bfp);
171 (void) sm_strlcpy(bfp->bf_filename, filename, l);
172 bfp->bf_filemode = fmode;
173 bfp->bf_offset = 0;
174 bfp->bf_size = 0;
175 bfp->bf_disk_fd = -1;
176 fp->f_cookie = bfp;
268 struct bf *bfp;
270 bfp = (struct bf *) fp->f_cookie;
274 return bfp->bf_disk_fd;
276 return bfp->bf_size;
302 struct bf *bfp;
305 bfp = (struct bf *) fp->f_cookie;
308 if (bfp->bf_ondisk && !bfp->bf_committed)
309 unlink(bfp->bf_filename);
310 sm_free(bfp->bf_filename);
312 if (bfp->bf_disk_fd != -1)
313 close(bfp->bf_disk_fd);
316 if (bfp->bf_bufsize > 0)
317 sm_free(bfp->bf_buf);
320 sm_free(bfp);
346 struct bf *bfp;
351 bfp = (struct bf *) fp->f_cookie;
353 if (bfp->bf_offset < bfp->bf_buffilled)
357 if ((bfp->bf_offset + count) > bfp->bf_buffilled)
358 count = bfp->bf_buffilled - bfp->bf_offset;
360 memcpy(buf, bfp->bf_buf + bfp->bf_offset, count);
363 if ((bfp->bf_offset + nbytes) > bfp->bf_buffilled)
366 if (!bfp->bf_ondisk)
371 bfp->bf_filename);
376 if (bfp->bf_disk_fd < 0)
382 if (lseek(bfp->bf_disk_fd,
383 bfp->bf_offset + count, SEEK_SET) < 0)
400 retval = read(bfp->bf_disk_fd,
416 bfp->bf_offset += count;
443 struct bf *bfp;
446 bfp = (struct bf *) fp->f_cookie;
451 bfp->bf_offset = offset;
455 bfp->bf_offset += offset;
459 bfp->bf_offset = bfp->bf_size + offset;
466 return bfp->bf_offset;
491 struct bf *bfp;
496 bfp = (struct bf *) fp->f_cookie;
499 if (bfp->bf_committed)
501 if (lseek(bfp->bf_disk_fd, bfp->bf_offset, SEEK_SET) < 0)
516 count = write(bfp->bf_disk_fd, buf, nbytes);
525 if (bfp->bf_offset < bfp->bf_bufsize)
529 if ((bfp->bf_offset + count) > bfp->bf_bufsize)
530 count = bfp->bf_bufsize - bfp->bf_offset;
532 memcpy(bfp->bf_buf + bfp->bf_offset, buf, count);
533 if ((bfp->bf_offset + count) > bfp->bf_buffilled)
534 bfp->bf_buffilled = bfp->bf_offset + count;
537 if ((bfp->bf_offset + nbytes) > bfp->bf_bufsize)
540 if (!bfp->bf_ondisk)
547 retval = OPEN(bfp->bf_filename,
549 bfp->bf_filemode, bfp->bf_flags);
575 bfp->bf_disk_fd = retval;
576 bfp->bf_ondisk = true;
580 if (bfp->bf_ondisk && bfp->bf_disk_fd < 0)
586 if (lseek(bfp->bf_disk_fd,
587 bfp->bf_offset + count, SEEK_SET) < 0)
604 retval = write(bfp->bf_disk_fd, buf + count,
617 bfp->bf_offset += count;
618 if (bfp->bf_offset > bfp->bf_size)
619 bfp->bf_size = bfp->bf_offset;
675 struct bf *bfp;
680 bfp = (struct bf *) fp->f_cookie;
683 if (bfp->bf_committed)
687 if (!bfp->bf_ondisk)
695 sm_dprintf("bfcommit(%s): to disk\n", bfp->bf_filename);
698 (unsigned int) bfp->bf_filemode,
699 bfp->bf_flags);
702 if (stat(bfp->bf_filename, &st) == 0)
710 retval = OPEN(bfp->bf_filename,
712 bfp->bf_filemode, bfp->bf_flags);
724 bfp->bf_disk_fd = retval;
725 bfp->bf_ondisk = true;
729 if (bfp->bf_buffilled > 0)
733 if (lseek(bfp->bf_disk_fd, 0, SEEK_SET) < 0)
739 while (byteswritten < bfp->bf_buffilled)
741 retval = write(bfp->bf_disk_fd,
742 bfp->bf_buf + byteswritten,
743 bfp->bf_buffilled - byteswritten);
753 bfp->bf_committed = true;
756 bfp->bf_buffilled = 0;
757 if (bfp->bf_bufsize > 0)
760 bfp->bf_bufsize = 0;
761 sm_free(bfp->bf_buf);
788 struct bf *bfp;
794 bfp = (struct bf *) fp->f_cookie;
795 bfp->bf_buffilled = 0;
796 bfp->bf_size = 0;
799 if (bfp->bf_bufsize > 0)
800 memset(bfp->bf_buf, '\0', bfp->bf_bufsize);
801 if (bfp->bf_ondisk)
808 return ftruncate(bfp->bf_disk_fd, 0);
830 struct bf *bfp;
834 bfp = (struct bf *) fp->f_cookie;
839 bfp->bf_bufsize = bsize;
844 bfp->bf_buf = (char *) sm_malloc(bsize);
845 if (bfp->bf_buf == NULL)
847 bfp->bf_bufsize = 0;
853 bfp->bf_buf = NULL;