=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/cvs/buf.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- src/usr.bin/cvs/buf.c 2005/07/25 12:05:43 1.15 +++ src/usr.bin/cvs/buf.c 2005/07/26 20:58:44 1.16 @@ -1,4 +1,4 @@ -/* $OpenBSD: buf.c,v 1.15 2005/07/25 12:05:43 xsa Exp $ */ +/* $OpenBSD: buf.c,v 1.16 2005/07/26 20:58:44 moritz Exp $ */ /* * Copyright (c) 2003 Jean-Francois Brousseau * All rights reserved. @@ -56,10 +56,10 @@ }; +#define SIZE_LEFT(b) (b->cb_size - (size_t)(b->cb_cur - b->cb_buf) \ + - b->cb_len) -#define SIZE_LEFT(b) ((size_t)(b->cb_buf - b->cb_cur) + b->cb_size) - static ssize_t cvs_buf_grow(BUF *, size_t); @@ -135,7 +135,7 @@ } for (bp = buf->cb_cur; ; bp += (size_t)ret) { - len = MIN(SIZE_LEFT(buf), 4096); + len = SIZE_LEFT(buf); ret = read(fd, bp, len); if (ret == -1) { cvs_log(LP_ERRNO, "read failed from buffer source"); @@ -193,6 +193,7 @@ void cvs_buf_empty(BUF *b) { + memset(b->cb_buf, 0, b->cb_size); b->cb_cur = b->cb_buf; b->cb_len = 0; } @@ -214,7 +215,7 @@ return (-1); rc = MIN(len, (b->cb_len - off)); - memcpy(dst, b->cb_buf, rc); + memcpy(dst, b->cb_buf + off, rc); return (ssize_t)rc; } @@ -223,11 +224,11 @@ /* * cvs_buf_set() * - * Set the contents of the buffer to the first bytes of data found - * at . If the buffer was not created with BUF_AUTOEXT, as many bytes - * as possible will be copied in the buffer. + * Set the contents of the buffer at offset to the first + * bytes of data found at . If the buffer was not created with + * BUF_AUTOEXT, as many bytes as possible will be copied in the buffer. */ -int +ssize_t cvs_buf_set(BUF *b, const void *src, size_t len, size_t off) { size_t rlen; @@ -248,7 +249,7 @@ b->cb_len = rlen; } - return (int)rlen; + return (rlen); } @@ -344,12 +345,12 @@ /* - * cvs_buf_size() + * cvs_buf_len() * * Returns the size of the buffer that is being used. */ size_t -cvs_buf_size(BUF *b) +cvs_buf_len(BUF *b) { return (b->cb_len); } @@ -386,7 +387,7 @@ bp = b->cb_cur; do { - ret = write(fd, bp, MIN(len, 8192)); + ret = write(fd, bp, len); if (ret == -1) { if (errno == EINTR || errno == EAGAIN) continue;