Lines Matching refs:fd
291 int fd; /* file descriptor for .gz file, opened read/write */ member
350 int fd; in log_lock() local
354 while ((fd = open(log->path, O_CREAT | O_EXCL, 0644)) < 0) { in log_lock()
363 close(fd); in log_lock()
415 if (lseek(log->fd, 0, SEEK_SET) < 0 || in log_head()
416 read(log->fd, buf, HEAD + EXTRA) != HEAD + EXTRA || in log_head()
450 fsync(log->fd); in log_mark()
451 ret = lseek(log->fd, HEAD, SEEK_SET) < 0 || in log_mark()
452 write(log->fd, ext, EXTRA) != EXTRA ? -1 : 0; in log_mark()
453 fsync(log->fd); in log_mark()
476 if (back != 8 && (lseek(log->fd, log->last - len, SEEK_SET) < 0 || in log_last()
477 read(log->fd, buf, 1) != 1)) in log_last()
491 return lseek(log->fd, log->last - len, SEEK_SET) < 0 || in log_last()
492 write(log->fd, buf + 2 - len, len + 4) != len + 4 || in log_last()
493 lseek(log->fd, log->stored, SEEK_CUR) < 0 ? -1 : 0; in log_last()
521 if (write(log->fd, data, put) != put) in log_append()
552 if (write(log->fd, buf, 8) != 8 || in log_append()
553 (end = lseek(log->fd, 0, SEEK_CUR)) < 0 || ftruncate(log->fd, end)) in log_append()
610 int fd; in log_compress() local
629 fd = open(log->path, O_RDONLY, 0); in log_compress()
630 if (fd >= 0) { in log_compress()
631 dict = read(fd, buf, DICT); in log_compress()
632 close(fd); in log_compress()
644 if (lseek(log->fd, log->first - (log->back > 8 ? 2 : 1), in log_compress()
646 read(log->fd, buf, 1) != 1 || lseek(log->fd, -1, SEEK_CUR) < 0) { in log_compress()
663 if (got && write(log->fd, buf, got) != got) { in log_compress()
677 if ((log->first = lseek(log->fd, -1, SEEK_CUR)) < 0 || in log_compress()
678 read(log->fd, buf, 1) != 1) in log_compress()
704 if (log_last(log, 1) || write(log->fd, buf, 8) != 8 || in log_compress()
705 (end = lseek(log->fd, 0, SEEK_CUR)) < 0 || ftruncate(log->fd, end)) in log_compress()
740 int fd, ret = 0; in log_recover() local
758 if ((fd = open(log->path, O_RDONLY, 0)) < 0) { in log_recover()
762 ret = (size_t)read(fd, data, len) != len; in log_recover()
763 close(fd); in log_recover()
798 if (log->fd >= 0) in log_close()
799 close(log->fd); in log_close()
800 log->fd = -1; in log_close()
819 if (log->fd >= 0) in log_open()
820 close(log->fd); in log_open()
821 log->fd = -1; in log_open()
829 log->fd = open(log->path, O_RDWR | O_CREAT, 0644); in log_open()
830 if (log->fd < 0) { in log_open()
836 if (lseek(log->fd, 0, SEEK_END) == 0) { in log_open()
837 if (write(log->fd, log_gzhead, HEAD) != HEAD || in log_open()
838 write(log->fd, log_gzext, EXTRA) != EXTRA || in log_open()
839 write(log->fd, log_gzbody, BODY) != BODY) { in log_open()
879 log->fd = -1; in gzlog_open()
910 int fd, ret; in gzlog_compress() local
935 if (lseek(log->fd, log->first - 1, SEEK_SET) < 0) in gzlog_compress()
939 if (read(log->fd, buf, 5) != 5) in gzlog_compress()
943 read(log->fd, (char *)data + next, block) != block) in gzlog_compress()
947 if (lseek(log->fd, 0, SEEK_CUR) != log->last + 4 + log->stored) in gzlog_compress()
953 fd = open(log->path, O_WRONLY | O_CREAT | O_TRUNC, 0644); in gzlog_compress()
954 if (fd < 0) in gzlog_compress()
956 ret = (size_t)write(fd, data, len) != len; in gzlog_compress()
957 if (ret | close(fd)) in gzlog_compress()
963 fd = open(log->path, O_WRONLY | O_CREAT | O_TRUNC, 0644); in gzlog_compress()
964 if (fd < 0) in gzlog_compress()
967 ret = (size_t)write(fd, (char *)data + len - next, next) != next; in gzlog_compress()
968 if (ret | close(fd)) in gzlog_compress()
997 int fd, ret; in gzlog_write() local
1014 fd = open(log->path, O_WRONLY | O_CREAT | O_TRUNC, 0644); in gzlog_write()
1015 if (fd < 0) in gzlog_write()
1017 ret = (size_t)write(fd, data, len) != len; in gzlog_write()
1018 if (ret | close(fd)) in gzlog_write()