=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/cvs/buf.c,v retrieving revision 1.6 retrieving revision 1.7 diff -c -r1.6 -r1.7 *** src/usr.bin/cvs/buf.c 2004/12/07 17:10:56 1.6 --- src/usr.bin/cvs/buf.c 2004/12/08 21:11:07 1.7 *************** *** 1,4 **** ! /* $OpenBSD: buf.c,v 1.6 2004/12/07 17:10:56 tedu Exp $ */ /* * Copyright (c) 2003 Jean-Francois Brousseau * All rights reserved. --- 1,4 ---- ! /* $OpenBSD: buf.c,v 1.7 2004/12/08 21:11:07 djm Exp $ */ /* * Copyright (c) 2003 Jean-Francois Brousseau * All rights reserved. *************** *** 34,39 **** --- 34,40 ---- #include #include #include + #include #include "buf.h" #include "log.h" *************** *** 370,403 **** /* ! * cvs_buf_write() * ! * Write the contents of the buffer to the file whose path is given in ! * . If the file does not exist, it is created with mode . */ int ! cvs_buf_write(BUF *b, const char *path, mode_t mode) { - int fd; u_char *bp; size_t len; ssize_t ret; - fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, mode); - if (fd == -1) { - cvs_log(LP_ERRNO, "failed to open file `%s'", path); - return (-1); - } - len = b->cb_len; bp = b->cb_cur; do { ret = write(fd, bp, MIN(len, 8192)); if (ret == -1) { ! cvs_log(LP_ERRNO, "failed to write to file `%s'", path); ! (void)close(fd); ! (void)unlink(path); return (-1); } --- 371,395 ---- /* ! * cvs_buf_write_fd() * ! * Write the contents of the buffer to the specified */ int ! cvs_buf_write_fd(BUF *b, int fd) { u_char *bp; size_t len; ssize_t ret; len = b->cb_len; bp = b->cb_cur; do { ret = write(fd, bp, MIN(len, 8192)); if (ret == -1) { ! if (errno == EINTR || errno == EAGAIN) ! continue; return (-1); } *************** *** 405,415 **** bp += (size_t)ret; } while (len > 0); (void)close(fd); ! return (0); } /* * cvs_buf_grow() --- 397,465 ---- bp += (size_t)ret; } while (len > 0); + return (0); + } + + /* + * cvs_buf_write() + * + * Write the contents of the buffer to the file whose path is given in + * . If the file does not exist, it is created with mode . + */ + + int + cvs_buf_write(BUF *b, const char *path, mode_t mode) + { + int ret, fd; + + fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, mode); + if (fd == -1) { + cvs_log(LP_ERRNO, "failed to open file `%s': %s", + path, strerror(errno)); + return (-1); + } + + ret = cvs_buf_write_fd(b, fd); + if (ret == -1) { + cvs_log(LP_ERRNO, "failed to write to file `%s': %s", + path, strerror(errno)); + (void)unlink(path); + } (void)close(fd); ! return (ret); } + /* + * cvs_buf_write_stmp() + * + * Write the contents of the buffer to a temporary file whose path is + * specified using