]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(pipe_lines, pipe_bytes): Don't assign 0 or SAFE_READ_ERROR to tmp->nbytes.
authorJim Meyering <jim@meyering.net>
Fri, 5 Sep 2003 20:44:20 +0000 (20:44 +0000)
committerJim Meyering <jim@meyering.net>
Fri, 5 Sep 2003 20:44:20 +0000 (20:44 +0000)
(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

index 019130362ee159729f74c81b1e510352941ac081..c89f5a2d2b11ba25c4083d32203c2944bcbe8b3c 100644 (file)
 /* 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