From 968be3baa59031944bdebc77c7adb44a7f4175f3 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Fri, 5 Sep 2003 20:44:20 +0000 Subject: (pipe_lines, pipe_bytes): Don't assign 0 or SAFE_READ_ERROR to tmp->nbytes. (struct linebuffer, struct charbuffer): Change nbytes and nlines from unsigned int to size_t. unsigned int is safe (after the 2003-09-03 patch) but size_t is cleaner. (pipe_bytes): Likewise for local variable 'i', which was 'int'. Standardize on BUFSIZ as opposed to other macro names and values. (BUFSIZ) [!defined BUFSIZ]: Remove. stdio.h has always defined it, and other code already assumes it's defined. --- src/tail.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/tail.c b/src/tail.c index 019130362..c89f5a2d2 100644 --- a/src/tail.c +++ b/src/tail.c @@ -57,11 +57,6 @@ /* Number of items to tail. */ #define DEFAULT_N_LINES 10 -/* Size of atomic reads. */ -#ifndef BUFSIZ -# define BUFSIZ (512 * 8) -#endif - /* A special value for dump_remainder's N_BYTES parameter. */ #define COPY_TO_EOF OFF_T_MAX @@ -518,8 +513,9 @@ pipe_lines (const char *pretty_filename, int fd, uintmax_t n_lines, { struct linebuffer { - unsigned int nbytes, nlines; char buffer[BUFSIZ]; + size_t nbytes; + size_t nlines; struct linebuffer *next; }; typedef struct linebuffer LBUFFER; @@ -537,9 +533,9 @@ pipe_lines (const char *pretty_filename, int fd, uintmax_t n_lines, while (1) { n_read = safe_read (fd, tmp->buffer, BUFSIZ); - tmp->nbytes = n_read; if (n_read == 0 || n_read == SAFE_READ_ERROR) break; + tmp->nbytes = n_read; *read_pos += n_read; tmp->nlines = 0; tmp->next = NULL; @@ -656,13 +652,13 @@ pipe_bytes (const char *pretty_filename, int fd, uintmax_t n_bytes, { struct charbuffer { - unsigned int nbytes; char buffer[BUFSIZ]; + size_t nbytes; struct charbuffer *next; }; typedef struct charbuffer CBUFFER; CBUFFER *first, *last, *tmp; - int i; /* Index into buffers. */ + size_t i; /* Index into buffers. */ size_t total_bytes = 0; /* Total characters in all buffers. */ int errors = 0; size_t n_read; @@ -676,11 +672,11 @@ pipe_bytes (const char *pretty_filename, int fd, uintmax_t n_bytes, while (1) { n_read = safe_read (fd, tmp->buffer, BUFSIZ); - tmp->nbytes = n_read; - tmp->next = NULL; if (n_read == 0 || n_read == SAFE_READ_ERROR) break; *read_pos += n_read; + tmp->nbytes = n_read; + tmp->next = NULL; total_bytes += tmp->nbytes; /* If there is enough room in the last buffer read, just append the new -- cgit v1.2.3-54-g00ecf