diff options
author | Joris Vink <joris@cvs.openbsd.org> | 2009-03-25 21:19:21 +0000 |
---|---|---|
committer | Joris Vink <joris@cvs.openbsd.org> | 2009-03-25 21:19:21 +0000 |
commit | 0be2ee121749034bfda448b74a45f397b47b227c (patch) | |
tree | b78d2806044f30291c0efc764c6be0efdc60eb46 /usr.bin/cvs/buf.c | |
parent | 632cb1a265894d5f3dccaa8e80410fde4f33c5a5 (diff) |
remove unused functions, definitions and outdated comments
from the stone ages.
Diffstat (limited to 'usr.bin/cvs/buf.c')
-rw-r--r-- | usr.bin/cvs/buf.c | 153 |
1 files changed, 12 insertions, 141 deletions
diff --git a/usr.bin/cvs/buf.c b/usr.bin/cvs/buf.c index 2aff95a20b3..1c402c47cca 100644 --- a/usr.bin/cvs/buf.c +++ b/usr.bin/cvs/buf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buf.c,v 1.73 2009/03/23 18:21:23 joris Exp $ */ +/* $OpenBSD: buf.c,v 1.74 2009/03/25 21:19:20 joris Exp $ */ /* * Copyright (c) 2003 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -38,30 +38,24 @@ #include "buf.h" #define BUF_INCR 128 +#define BUF_GROW(bp, len) \ + do { \ + b->cb_buf = xrealloc(b->cb_buf, 1, b->cb_size + len); \ + b->cb_size += len; \ + } while (0); struct cvs_buf { - /* buffer handle, buffer size, and data length */ u_char *cb_buf; size_t cb_size; size_t cb_len; }; -static void cvs_buf_grow(BUF *, size_t); - -/* - * cvs_buf_alloc() - * - * Create a new buffer structure and return a pointer to it. This structure - * uses dynamically-allocated memory and must be freed with cvs_buf_free(), - * once the buffer is no longer needed. - */ BUF * cvs_buf_alloc(size_t len) { BUF *b; b = xmalloc(sizeof(*b)); - /* Postpone creation of zero-sized buffers */ if (len > 0) b->cb_buf = xcalloc(1, len); else @@ -110,11 +104,6 @@ cvs_buf_load_fd(int fd) return (buf); } -/* - * cvs_buf_free() - * - * Free the buffer <b> and all associated data. - */ void cvs_buf_free(BUF *b) { @@ -123,13 +112,6 @@ cvs_buf_free(BUF *b) xfree(b); } -/* - * cvs_buf_release() - * - * Free the buffer <b>'s structural information but do not free the contents - * of the buffer. Instead, they are returned and should be freed later using - * free(). - */ u_char * cvs_buf_release(BUF *b) { @@ -140,23 +122,6 @@ cvs_buf_release(BUF *b) return (tmp); } -/* - * cvs_buf_empty() - * - * Empty the contents of the buffer <b> and reset pointers. - */ -void -cvs_buf_empty(BUF *b) -{ - memset(b->cb_buf, 0, b->cb_size); - b->cb_len = 0; -} - -/* - * cvs_buf_putc() - * - * Append a single character <c> to the end of the buffer <b>. - */ void cvs_buf_putc(BUF *b, int c) { @@ -164,48 +129,19 @@ cvs_buf_putc(BUF *b, int c) bp = b->cb_buf + b->cb_len; if (bp == (b->cb_buf + b->cb_size)) { - /* extend */ - cvs_buf_grow(b, (size_t)BUF_INCR); - - /* the buffer might have been moved */ + BUF_GROW(b, BUF_INCR); bp = b->cb_buf + b->cb_len; } *bp = (u_char)c; b->cb_len++; } -/* - * cvs_buf_puts() - * - * Wrapper function for constant strings to cvs_buf_append. - */ void cvs_buf_puts(BUF *b, const char *str) { cvs_buf_append(b, str, strlen(str)); } -/* - * cvs_buf_getc() - * - * Return u_char at buffer position <pos>. - * - */ -u_char -cvs_buf_getc(BUF *b, size_t pos) -{ - return (b->cb_buf[pos]); -} - -/* - * cvs_buf_append() - * - * Append <len> bytes of data pointed to by <data> to the buffer <b>. If the - * buffer is too small to accept all data, it will attempt to append as much - * data as possible, or if the BUF_AUTOEXT flag is set for the buffer, it - * will get resized to an appropriate size to accept all data. - * Returns the number of bytes successfully appended to the buffer. - */ void cvs_buf_append(BUF *b, const void *data, size_t len) { @@ -217,7 +153,7 @@ cvs_buf_append(BUF *b, const void *data, size_t len) left = bep - bp; if (left < len) { - cvs_buf_grow(b, len - left); + BUF_GROW(b, len - left); bp = b->cb_buf + b->cb_len; } @@ -225,22 +161,12 @@ cvs_buf_append(BUF *b, const void *data, size_t len) b->cb_len += len; } -/* - * cvs_buf_len() - * - * Returns the size of the buffer that is being used. - */ size_t cvs_buf_len(BUF *b) { return (b->cb_len); } -/* - * cvs_buf_write_fd() - * - * Write the contents of the buffer <b> to the specified <fd> - */ int cvs_buf_write_fd(BUF *b, int fd) { @@ -249,17 +175,11 @@ cvs_buf_write_fd(BUF *b, int fd) return (0); } -/* - * cvs_buf_write() - * - * Write the contents of the buffer <b> to the file whose path is given in - * <path>. If the file does not exist, it is created with mode <mode>. - */ int cvs_buf_write(BUF *b, const char *path, mode_t mode) { int fd; - open: +open: if ((fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, mode)) == -1) { if (errno == EACCES && unlink(path) != -1) goto open; @@ -280,13 +200,6 @@ cvs_buf_write(BUF *b, const char *path, mode_t mode) return (0); } -/* - * cvs_buf_write_stmp() - * - * Write the contents of the buffer <b> to a temporary file whose path is - * specified using <template> (see mkstemp.3). NB. This function will modify - * <template>, as per mkstemp - */ int cvs_buf_write_stmp(BUF *b, char *template, struct timeval *tv) { @@ -313,52 +226,10 @@ cvs_buf_write_stmp(BUF *b, char *template, struct timeval *tv) return (fd); } -/* - * cvs_buf_grow() - * - * Grow the buffer <b> by <len> bytes. The contents are unchanged by this - * operation regardless of the result. - */ -static void -cvs_buf_grow(BUF *b, size_t len) -{ - b->cb_buf = xrealloc(b->cb_buf, 1, b->cb_size + len); - b->cb_size += len; -} - -/* - * cvs_buf_copy() - * - * Copy the first <len> bytes of data in the buffer <b> starting at offset - * <off> in the destination buffer <dst>, which can accept up to <len> bytes. - * Returns the number of bytes successfully copied, or -1 on failure. - */ -ssize_t -cvs_buf_copy(BUF *b, size_t off, void *dst, size_t len) -{ - size_t rc; - - if (off > b->cb_len) - fatal("cvs_buf_copy failed"); - - rc = MIN(len, (b->cb_len - off)); - memcpy(dst, b->cb_buf + off, rc); - - return (ssize_t)rc; -} - -/* - * cvs_buf_peek() - * - * Peek at the contents of the buffer <b> at offset <off>. - */ -const u_char * -cvs_buf_peek(BUF *b, size_t off) +u_char * +cvs_buf_get(BUF *bp) { - if (off >= b->cb_len) - return (NULL); - - return (b->cb_buf + off); + return (bp->cb_buf); } int |