From ed8350422e9472b657034367f39ab133f7913862 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Thu, 25 Jun 2009 06:05:47 +0000 Subject: [PATCH] Nuke unused buffer functions. Found by lint. Also remove some old debug output which was #if 0. --- buffer-poll.c | 43 -------------------------- buffer.c | 85 --------------------------------------------------- tmux.h | 10 ------ 3 files changed, 138 deletions(-) diff --git a/buffer-poll.c b/buffer-poll.c index 4dd4d234..cb645194 100644 --- a/buffer-poll.c +++ b/buffer-poll.c @@ -23,37 +23,17 @@ #include "tmux.h" -/* Set up pollfd for buffers. */ -void -buffer_set( - struct pollfd *pfd, int fd, unused struct buffer *in, struct buffer *out) -{ - pfd->fd = fd; - pfd->events = POLLIN; - if (BUFFER_USED(out) > 0) - pfd->events |= POLLOUT; -} - /* Fill buffers from socket based on poll results. */ int buffer_poll(struct pollfd *pfd, struct buffer *in, struct buffer *out) { ssize_t n; -#if 0 - log_debug("buffer_poll (%ld): fd=%d, revents=%d; out=%zu in=%zu", - (long) getpid(), - pfd->fd, pfd->revents, BUFFER_USED(out), BUFFER_USED(in)); -#endif - if (pfd->revents & (POLLERR|POLLNVAL|POLLHUP)) return (-1); if (pfd->revents & POLLIN) { buffer_ensure(in, BUFSIZ); n = read(pfd->fd, BUFFER_IN(in), BUFFER_FREE(in)); -#if 0 - log_debug("buffer_poll: fd=%d, read=%zd", pfd->fd, n); -#endif if (n == 0) return (-1); if (n == -1) { @@ -64,9 +44,6 @@ buffer_poll(struct pollfd *pfd, struct buffer *in, struct buffer *out) } if (BUFFER_USED(out) > 0 && pfd->revents & POLLOUT) { n = write(pfd->fd, BUFFER_OUT(out), BUFFER_USED(out)); -#if 0 - log_debug("buffer_poll: fd=%d, write=%zd", pfd->fd, n); -#endif if (n == -1) { if (errno != EINTR && errno != EAGAIN) return (-1); @@ -75,23 +52,3 @@ buffer_poll(struct pollfd *pfd, struct buffer *in, struct buffer *out) } return (0); } - -/* Flush buffer output to socket. */ -void -buffer_flush(int fd, struct buffer *in, struct buffer *out) -{ - struct pollfd pfd; - - while (BUFFER_USED(out) > 0) { - buffer_set(&pfd, fd, in, out); - - if (poll(&pfd, 1, INFTIM) == -1) { - if (errno == EAGAIN || errno == EINTR) - continue; - fatal("poll failed"); - } - - if (buffer_poll(&pfd, in, out) != 0) - break; - } -} diff --git a/buffer.c b/buffer.c index eea1fce7..f52d6352 100644 --- a/buffer.c +++ b/buffer.c @@ -47,14 +47,6 @@ buffer_destroy(struct buffer *b) xfree(b); } -/* Empty a buffer. */ -void -buffer_clear(struct buffer *b) -{ - b->size = 0; - b->off = 0; -} - /* Ensure free space for size in buffer. */ void buffer_ensure(struct buffer *b, size_t size) @@ -91,18 +83,6 @@ buffer_add(struct buffer *b, size_t size) b->size += size; } -/* Reverse buffer add. */ -void -buffer_reverse_add(struct buffer *b, size_t size) -{ - if (size == 0) - fatalx("zero size"); - if (size > b->size) - fatalx("underflow"); - - b->size -= size; -} - /* Adjust buffer after data removed. */ void buffer_remove(struct buffer *b, size_t size) @@ -116,50 +96,6 @@ buffer_remove(struct buffer *b, size_t size) b->off += size; } -/* Reverse buffer remove. */ -void -buffer_reverse_remove(struct buffer *b, size_t size) -{ - if (size == 0) - fatalx("zero size"); - if (size > b->off) - fatalx("overflow"); - - b->size += size; - b->off -= size; -} - -/* Insert a section into the buffer. */ -void -buffer_insert_range(struct buffer *b, size_t base, size_t size) -{ - if (size == 0) - fatalx("zero size"); - if (base > b->size) - fatalx("range outside buffer"); - - buffer_ensure(b, size); - memmove(b->base + b->off + base + size, - b->base + b->off + base, b->size - base); - b->size += size; -} - -/* Delete a section from the buffer. */ -void -buffer_delete_range(struct buffer *b, size_t base, size_t size) -{ - if (size == 0) - fatalx("zero size"); - if (size > b->size) - fatalx("size too big"); - if (base + size > b->size) - fatalx("range outside buffer"); - - memmove(b->base + b->off + base, - b->base + b->off + base + size, b->size - base - size); - b->size -= size; -} - /* Copy data into a buffer. */ void buffer_write(struct buffer *b, const void *data, size_t size) @@ -194,16 +130,6 @@ buffer_write8(struct buffer *b, uint8_t n) buffer_add(b, 1); } -/* Store a 16-bit value. */ -void -buffer_write16(struct buffer *b, uint16_t n) -{ - buffer_ensure(b, 2); - BUFFER_IN(b)[0] = n & 0xff; - BUFFER_IN(b)[1] = n >> 8; - buffer_add(b, 2); -} - /* Extract an 8-bit value. */ uint8_t buffer_read8(struct buffer *b) @@ -214,14 +140,3 @@ buffer_read8(struct buffer *b) buffer_remove(b, 1); return (n); } - -/* Extract a 16-bit value. */ -uint16_t -buffer_read16(struct buffer *b) -{ - uint16_t n; - - n = BUFFER_OUT(b)[0] | (BUFFER_OUT(b)[1] << 8); - buffer_remove(b, 2); - return (n); -} diff --git a/tmux.h b/tmux.h index ba8fdd1d..48c54c91 100644 --- a/tmux.h +++ b/tmux.h @@ -1533,26 +1533,16 @@ char *get_proc_name(int, char *); /* buffer.c */ struct buffer *buffer_create(size_t); void buffer_destroy(struct buffer *); -void buffer_clear(struct buffer *); void buffer_ensure(struct buffer *, size_t); void buffer_add(struct buffer *, size_t); -void buffer_reverse_add(struct buffer *, size_t); void buffer_remove(struct buffer *, size_t); -void buffer_reverse_remove(struct buffer *, size_t); -void buffer_insert_range(struct buffer *, size_t, size_t); -void buffer_delete_range(struct buffer *, size_t, size_t); void buffer_write(struct buffer *, const void *, size_t); void buffer_read(struct buffer *, void *, size_t); void buffer_write8(struct buffer *, uint8_t); -void buffer_write16(struct buffer *, uint16_t); uint8_t buffer_read8(struct buffer *); -uint16_t buffer_read16(struct buffer *); /* buffer-poll.c */ -void buffer_set( - struct pollfd *, int, struct buffer *, struct buffer *); int buffer_poll(struct pollfd *, struct buffer *, struct buffer *); -void buffer_flush(int, struct buffer *n, struct buffer *); /* log.c */ #define LOG_FACILITY LOG_DAEMON