diff options
author | Ray Lai <ray@cvs.openbsd.org> | 2007-02-02 04:34:50 +0000 |
---|---|---|
committer | Ray Lai <ray@cvs.openbsd.org> | 2007-02-02 04:34:50 +0000 |
commit | afa4f3dfb364a20fd987b5b2893d647ff09fda0e (patch) | |
tree | e472ca5e5ff89800301e583c3dd24152c5e84f4c /usr.bin/rcs/buf.c | |
parent | 6922d99a37d1348e27229fd72eaa57d3f68118dd (diff) |
Remove cb_cur or replace with cb_buf; cb_cur was the same as cb_buf
most of the time and was never of much use.
OK niallo@.
Diffstat (limited to 'usr.bin/rcs/buf.c')
-rw-r--r-- | usr.bin/rcs/buf.c | 31 |
1 files changed, 10 insertions, 21 deletions
diff --git a/usr.bin/rcs/buf.c b/usr.bin/rcs/buf.c index 19b22375b6a..11428bf9a07 100644 --- a/usr.bin/rcs/buf.c +++ b/usr.bin/rcs/buf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buf.c,v 1.9 2007/02/02 04:24:09 ray Exp $ */ +/* $OpenBSD: buf.c,v 1.10 2007/02/02 04:34:49 ray Exp $ */ /* * Copyright (c) 2003 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -35,17 +35,13 @@ struct rcs_buf { u_int cb_flags; - /* buffer handle and size */ + /* buffer handle, buffer size, and data length */ u_char *cb_buf; size_t cb_size; - - /* start and length of valid data in buffer */ - u_char *cb_cur; size_t cb_len; }; -#define SIZE_LEFT(b) (b->cb_size - (size_t)(b->cb_cur - b->cb_buf) \ - - b->cb_len) +#define SIZE_LEFT(b) (b->cb_size - b->cb_len) static void rcs_buf_grow(BUF *, size_t); @@ -70,7 +66,6 @@ rcs_buf_alloc(size_t len, u_int flags) b->cb_flags = flags; b->cb_size = len; - b->cb_cur = b->cb_buf; b->cb_len = 0; return (b); @@ -107,7 +102,7 @@ rcs_buf_load(const char *path, u_int flags) goto out; } buf = rcs_buf_alloc(st.st_size, flags); - for (bp = buf->cb_cur; ; bp += (size_t)ret) { + for (bp = buf->cb_buf; ; bp += (size_t)ret) { len = SIZE_LEFT(buf); ret = read(fd, bp, len); if (ret == -1) { @@ -185,7 +180,6 @@ void rcs_buf_empty(BUF *b) { memset(b->cb_buf, 0, b->cb_size); - b->cb_cur = b->cb_buf; b->cb_len = 0; } @@ -199,7 +193,7 @@ rcs_buf_putc(BUF *b, int c) { u_char *bp; - bp = b->cb_cur + b->cb_len; + bp = b->cb_buf + b->cb_len; if (bp == (b->cb_buf + b->cb_size)) { /* extend */ if (b->cb_flags & BUF_AUTOEXT) @@ -208,7 +202,7 @@ rcs_buf_putc(BUF *b, int c) errx(1, "rcs_buf_putc failed"); /* the buffer might have been moved */ - bp = b->cb_cur + b->cb_len; + bp = b->cb_buf + b->cb_len; } *bp = (u_char)c; b->cb_len++; @@ -223,7 +217,7 @@ rcs_buf_putc(BUF *b, int c) u_char rcs_buf_getc(BUF *b, size_t pos) { - return (b->cb_cur[pos]); + return (b->cb_buf[pos]); } /* @@ -241,7 +235,7 @@ rcs_buf_append(BUF *b, const void *data, size_t len) size_t left, rlen; u_char *bp, *bep; - bp = b->cb_cur + b->cb_len; + bp = b->cb_buf + b->cb_len; bep = b->cb_buf + b->cb_size; left = bep - bp; rlen = len; @@ -249,7 +243,7 @@ rcs_buf_append(BUF *b, const void *data, size_t len) if (left < len) { if (b->cb_flags & BUF_AUTOEXT) { rcs_buf_grow(b, len - left); - bp = b->cb_cur + b->cb_len; + bp = b->cb_buf + b->cb_len; } else rlen = bep - bp; } @@ -308,7 +302,7 @@ rcs_buf_write_fd(BUF *b, int fd) ssize_t ret; len = b->cb_len; - bp = b->cb_cur; + bp = b->cb_buf; do { ret = write(fd, bp, len); @@ -391,13 +385,8 @@ static void rcs_buf_grow(BUF *b, size_t len) { void *tmp; - size_t diff; - diff = b->cb_cur - b->cb_buf; tmp = xrealloc(b->cb_buf, 1, b->cb_size + len); b->cb_buf = tmp; b->cb_size += len; - - /* readjust pointers in case the buffer moved in memory */ - b->cb_cur = b->cb_buf + diff; } |