summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-09-05 20:45:26 +0000
committerJim Meyering <jim@meyering.net>2003-09-05 20:45:26 +0000
commit1061c7028464919cedc575b67ab77b21594c1fad (patch)
tree72a3e202b4cdfbb44c73ce62c10d06eee53300bd /src
parent968be3baa59031944bdebc77c7adb44a7f4175f3 (diff)
downloadcoreutils-1061c7028464919cedc575b67ab77b21594c1fad.tar.xz
(elide_tail_lines_pipe): Don't assign 0 or SAFE_READ_ERROR to tmp->nbytes.
(struct linebuffer): 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. Standardize on BUFSIZ as opposed to other macro names and values. (BUFSIZE): Remove. All uses changed to BUFSIZ.
Diffstat (limited to 'src')
-rw-r--r--src/head.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/head.c b/src/head.c
index aa58075ce..cf28bbe94 100644
--- a/src/head.c
+++ b/src/head.c
@@ -49,9 +49,6 @@
/* Number of lines/chars/blocks to head. */
#define DEFAULT_NUMBER 10
-/* Size of atomic reads. */
-#define BUFSIZE (512 * 8)
-
/* Useful only when eliding tail bytes or lines.
If nonzero, skip the is-regular-file test used to determine whether
to use the lseek optimization. Instead, use the more general (and
@@ -183,7 +180,7 @@ write_header (const char *filename)
static enum Copy_fd_status
copy_fd (int src_fd, FILE *o_stream, uintmax_t n_bytes)
{
- char buf[BUFSIZE];
+ char buf[BUFSIZ];
const size_t buf_size = sizeof (buf);
/* Copy the file contents. */
@@ -215,7 +212,7 @@ elide_tail_bytes_pipe (const char *filename, int fd, uintmax_t n_elide_0)
size_t n_elide = n_elide_0;
#ifndef HEAD_TAIL_PIPE_READ_BUFSIZE
-# define HEAD_TAIL_PIPE_READ_BUFSIZE BUFSIZE
+# define HEAD_TAIL_PIPE_READ_BUFSIZE BUFSIZ
#endif
#define READ_BUFSIZE HEAD_TAIL_PIPE_READ_BUFSIZE
@@ -476,8 +473,9 @@ elide_tail_lines_pipe (const char *filename, int fd, uintmax_t n_elide)
{
struct linebuffer
{
- unsigned int nbytes, nlines;
char buffer[BUFSIZ];
+ size_t nbytes;
+ size_t nlines;
struct linebuffer *next;
};
typedef struct linebuffer LBUFFER;
@@ -497,9 +495,9 @@ elide_tail_lines_pipe (const char *filename, int fd, uintmax_t n_elide)
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;
tmp->nlines = 0;
tmp->next = NULL;
@@ -753,8 +751,8 @@ elide_tail_lines_file (const char *filename, int fd, uintmax_t n_elide)
static int
head_bytes (const char *filename, int fd, uintmax_t bytes_to_write)
{
- char buffer[BUFSIZE];
- size_t bytes_to_read = BUFSIZE;
+ char buffer[BUFSIZ];
+ size_t bytes_to_read = BUFSIZ;
/* Need BINARY I/O for the byte counts to be accurate. */
SET_BINARY2 (fd, fileno (stdout));
@@ -782,7 +780,7 @@ head_bytes (const char *filename, int fd, uintmax_t bytes_to_write)
static int
head_lines (const char *filename, int fd, uintmax_t lines_to_write)
{
- char buffer[BUFSIZE];
+ char buffer[BUFSIZ];
/* Need BINARY I/O for the byte counts to be accurate. */
/* FIXME: do we really need this when counting *lines*? */
@@ -790,7 +788,7 @@ head_lines (const char *filename, int fd, uintmax_t lines_to_write)
while (lines_to_write)
{
- size_t bytes_read = safe_read (fd, buffer, BUFSIZE);
+ size_t bytes_read = safe_read (fd, buffer, BUFSIZ);
size_t bytes_to_write = 0;
if (bytes_read == SAFE_READ_ERROR)