[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
coreutils minor int cleanups for factor, fold, head
From: |
Paul Eggert |
Subject: |
coreutils minor int cleanups for factor, fold, head |
Date: |
Mon, 02 Aug 2004 23:19:14 -0700 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) |
I installed the following minor cleanups. The only real change to
behavior on current architectures is that "fold -w" now allows values
up to SIZE_MAX - TAB_WIDTH - 1, instead of an artificial limit at
INT_MAX; the distinction matters on 64-bit hosts.
2004-08-02 Paul Eggert <address@hidden>
* src/factor.c (wheel_tab): Use unsigned char instead of unsigned
int, since it suffices.
(factor, print_factors): Use size_t for sizes.
(print_factors, do_stdin, main): Use bool for booleans.
* src/fold.c (TAB_WIDTH): New macro; use it instead of "8".
(fold_file, main): Use bool for booleans.
(fold_file, main): Use size_t for sizes.
(main): Allow -w options up to SIZE_MAX - TAB_WIDTH - 1, instead
of prohibiting widths greater than INT_MAX.
* src/head.c (presume_input_pipe, print_headers, have_read_stdin,
write_header, elide_tail_bytes_pipe, elide_tail_bytes_file,
elide_tail_lines_pipe, elide_tail_lines_seekable,
elide_tail_lines_file, head_bytes, head_lines, head, head_file,
string_to_integer, main):
Use bool for booleans.
(main): Rewrite to avoid cast.
Index: src/factor.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/factor.c,v
retrieving revision 1.66
diff -p -u -r1.66 factor.c
--- src/factor.c 21 Mar 2004 18:45:37 -0000 1.66
+++ src/factor.c 17 Jul 2004 05:30:10 -0000
@@ -51,7 +51,7 @@
http://www.utm.edu/research/primes/glossary/WheelFactorization.html */
#include "wheel-size.h" /* For the definition of WHEEL_SIZE. */
-static const unsigned int wheel_tab[] =
+static const unsigned char wheel_tab[] =
{
#include "wheel.h"
};
@@ -93,12 +93,12 @@ Print the prime factors of each NUMBER.\
/* FIXME: comment */
-static int
-factor (uintmax_t n0, int max_n_factors, uintmax_t *factors)
+static size_t
+factor (uintmax_t n0, size_t max_n_factors, uintmax_t *factors)
{
register uintmax_t n = n0, d, q;
- int n_factors = 0;
- unsigned int const *w = wheel_tab;
+ size_t n_factors = 0;
+ unsigned char const *w = wheel_tab;
if (n < 1)
return n_factors;
@@ -139,13 +139,13 @@ factor (uintmax_t n0, int max_n_factors,
/* FIXME: comment */
-static int
+static bool
print_factors (const char *s)
{
uintmax_t factors[MAX_N_FACTORS];
uintmax_t n;
- int n_factors;
- int i;
+ size_t n_factors;
+ size_t i;
char buf[INT_BUFSIZE_BOUND (uintmax_t)];
strtol_error err;
@@ -155,20 +155,20 @@ print_factors (const char *s)
error (0, 0, _("`%s' is too large"), s);
else
error (0, 0, _("`%s' is not a valid positive integer"), s);
- return 1;
+ return false;
}
n_factors = factor (n, MAX_N_FACTORS, factors);
printf ("%s:", umaxtostr (n, buf));
for (i = 0; i < n_factors; i++)
printf (" %s", umaxtostr (factors[i], buf));
putchar ('\n');
- return 0;
+ return true;
}
-static int
+static bool
do_stdin (void)
{
- int fail = 0;
+ bool ok = true;
token_buffer tokenbuffer;
init_tokenbuffer (&tokenbuffer);
@@ -179,17 +179,17 @@ do_stdin (void)
&tokenbuffer);
if (token_length == (size_t) -1)
break;
- fail |= print_factors (tokenbuffer.buffer);
+ ok &= print_factors (tokenbuffer.buffer);
}
free (tokenbuffer.buffer);
- return fail;
+ return ok;
}
int
main (int argc, char **argv)
{
- int fail;
+ bool ok;
initialize_main (&argc, &argv);
program_name = argv[0];
@@ -209,17 +209,16 @@ main (int argc, char **argv)
++argv;
}
- fail = 0;
if (argc == 1)
- fail = do_stdin ();
+ ok = do_stdin ();
else
{
int i;
for (i = 1; i < argc; i++)
- fail |= print_factors (argv[i]);
- if (fail)
- usage (EXIT_FAILURE);
+ if (! print_factors (argv[i]))
+ usage (EXIT_FAILURE);
+ ok = true;
}
- exit (fail ? EXIT_FAILURE : EXIT_SUCCESS);
+ exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
}
Index: src/fold.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/fold.c,v
retrieving revision 1.78
diff -p -u -r1.78 fold.c
--- src/fold.c 21 Jan 2004 23:07:28 -0000 1.78
+++ src/fold.c 17 Jul 2004 05:17:01 -0000
@@ -28,6 +28,8 @@
#include "posixver.h"
#include "xstrtol.h"
+#define TAB_WIDTH 8
+
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME "fold"
@@ -104,7 +106,7 @@ adjust_column (size_t column, char c)
else if (c == '\r')
column = 0;
else if (c == '\t')
- column = column + 8 - column % 8;
+ column += TAB_WIDTH - column % TAB_WIDTH;
else /* if (isprint (c)) */
column++;
}
@@ -115,10 +117,10 @@ adjust_column (size_t column, char c)
/* Fold file FILENAME, or standard input if FILENAME is "-",
to stdout, with maximum line length WIDTH.
- Return 0 if successful, 1 if an error occurs. */
+ Return true if successful. */
-static int
-fold_file (char *filename, int width)
+static bool
+fold_file (char *filename, size_t width)
{
FILE *istream;
register int c;
@@ -139,7 +141,7 @@ fold_file (char *filename, int width)
if (istream == NULL)
{
error (0, errno, "%s", filename);
- return 1;
+ return false;
}
while ((c = getc (istream)) != EOF)
@@ -224,24 +226,24 @@ fold_file (char *filename, int width)
error (0, saved_errno, "%s", filename);
if (!STREQ (filename, "-"))
fclose (istream);
- return 1;
+ return false;
}
if (!STREQ (filename, "-") && fclose (istream) == EOF)
{
error (0, errno, "%s", filename);
- return 1;
+ return false;
}
- return 0;
+ return true;
}
int
main (int argc, char **argv)
{
- int width = 80;
+ size_t width = 80;
int i;
int optc;
- int errs = 0;
+ bool ok;
initialize_main (&argc, &argv);
program_name = argv[0];
@@ -295,12 +297,12 @@ main (int argc, char **argv)
case 'w': /* Line width. */
{
- long int tmp_long;
- if (xstrtol (optarg, NULL, 10, &tmp_long, "") != LONGINT_OK
- || tmp_long <= 0 || tmp_long > INT_MAX)
+ unsigned long int tmp_ulong;
+ if (! (xstrtoul (optarg, NULL, 10, &tmp_ulong, "") == LONGINT_OK
+ && 0 < tmp_ulong && tmp_ulong < SIZE_MAX - TAB_WIDTH))
error (EXIT_FAILURE, 0,
_("invalid number of columns: `%s'"), optarg);
- width = (int) tmp_long;
+ width = tmp_ulong;
}
break;
@@ -314,13 +316,16 @@ main (int argc, char **argv)
}
if (argc == optind)
- errs |= fold_file ("-", width);
+ ok = fold_file ("-", width);
else
- for (i = optind; i < argc; i++)
- errs |= fold_file (argv[i], width);
+ {
+ ok = true;
+ for (i = optind; i < argc; i++)
+ ok &= fold_file (argv[i], width);
+ }
if (have_read_stdin && fclose (stdin) == EOF)
error (EXIT_FAILURE, errno, "-");
- exit (errs == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
+ exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
}
Index: src/head.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/head.c,v
retrieving revision 1.94
diff -p -u -r1.94 head.c
--- src/head.c 6 May 2004 14:24:16 -0000 1.94
+++ src/head.c 17 Jul 2004 05:20:57 -0000
@@ -50,13 +50,13 @@
#define DEFAULT_NUMBER 10
/* Useful only when eliding tail bytes or lines.
- If nonzero, skip the is-regular-file test used to determine whether
+ If true, skip the is-regular-file test used to determine whether
to use the lseek optimization. Instead, use the more general (and
more expensive) code unconditionally. Intended solely for testing. */
-static int presume_input_pipe;
+static bool presume_input_pipe;
-/* If nonzero, print filename headers. */
-static int print_headers;
+/* If true, print filename headers. */
+static bool print_headers;
/* When to print the filename banners. */
enum header_mode
@@ -71,7 +71,7 @@ static char const header_mode_option[][4
char *program_name;
/* Have we ever read standard input? */
-static int have_read_stdin;
+static bool have_read_stdin;
enum Copy_fd_status
{
@@ -168,10 +168,10 @@ diagnose_copy_fd_failure (enum Copy_fd_s
static void
write_header (const char *filename)
{
- static int first_file = 1;
+ static bool first_file = true;
printf ("%s==> %s <==\n", (first_file ? "" : "\n"), filename);
- first_file = 0;
+ first_file = false;
}
/* Copy no more than N_BYTES from file descriptor SRC_FD to O_STREAM.
@@ -204,9 +204,9 @@ copy_fd (int src_fd, FILE *o_stream, uin
}
/* Print all but the last N_ELIDE lines from the input available via
- the non-seekable file descriptor FD. Return zero upon success.
- Give a diagnostic and return nonzero upon error. */
-static int
+ the non-seekable file descriptor FD. Return true upon success.
+ Give a diagnostic and return false upon error. */
+static bool
elide_tail_bytes_pipe (const char *filename, int fd, uintmax_t n_elide_0)
{
size_t n_elide = n_elide_0;
@@ -248,16 +248,16 @@ elide_tail_bytes_pipe (const char *filen
if (n_elide <= HEAD_TAIL_PIPE_BYTECOUNT_THRESHOLD)
{
- int fail = 0;
+ bool ok = true;
bool first = true;
bool eof = false;
size_t n_to_read = READ_BUFSIZE + n_elide;
- unsigned int i;
+ bool i;
char *b[2];
b[0] = xnmalloc (2, n_to_read);
b[1] = b[0] + n_to_read;
- for (i = 0; ! eof ; i = !i)
+ for (i = false; ! eof ; i = !i)
{
size_t n_read = full_read (fd, b[i], n_to_read);
size_t delta = 0;
@@ -266,7 +266,7 @@ elide_tail_bytes_pipe (const char *filen
if (errno != 0)
{
error (0, errno, _("error reading %s"), quote (filename));
- fail = 1;
+ ok = false;
break;
}
@@ -302,20 +302,20 @@ elide_tail_bytes_pipe (const char *filen
&& fwrite (b[i], 1, n_read - n_elide, stdout) < n_read - n_elide)
{
error (0, errno, _("write error"));
- fail = 1;
+ ok = false;
break;
}
}
free (b[0]);
- return fail;
+ return ok;
}
else
{
/* Read blocks of size READ_BUFSIZE, until we've read at least n_elide
bytes. Then, for each new buffer we read, also write an old one. */
- int fail = 0;
+ bool ok = true;
bool eof = false;
size_t n_read;
bool buffered_enough;
@@ -338,7 +338,7 @@ elide_tail_bytes_pipe (const char *filen
if (errno != 0)
{
error (0, errno, _("error reading %s"), quote (filename));
- fail = 1;
+ ok = false;
goto free_mem;
}
eof = true;
@@ -352,7 +352,7 @@ elide_tail_bytes_pipe (const char *filen
if (fwrite (b[i_next], 1, n_read, stdout) < n_read)
{
error (0, errno, _("write error"));
- fail = 1;
+ ok = false;
goto free_mem;
}
}
@@ -400,18 +400,18 @@ elide_tail_bytes_pipe (const char *filen
free (b[i]);
free (b);
- return fail;
+ return ok;
}
}
/* Print all but the last N_ELIDE lines from the input available
- via file descriptor FD. Return zero upon success.
- Give a diagnostic and return nonzero upon error. */
+ via file descriptor FD. Return true upon success.
+ Give a diagnostic and return false upon error. */
/* NOTE: if the input file shrinks by more than N_ELIDE bytes between
the length determination and the actual reading, then head fails. */
-static int
+static bool
elide_tail_bytes_file (const char *filename, int fd, uintmax_t n_elide)
{
struct stat stats;
@@ -435,7 +435,7 @@ elide_tail_bytes_file (const char *filen
|| (end_pos = lseek (fd, (off_t) 0, SEEK_END)) == -1)
{
error (0, errno, _("cannot lseek %s"), quote (filename));
- return 1;
+ return false;
}
/* Be careful here. The current position may actually be
@@ -443,7 +443,7 @@ elide_tail_bytes_file (const char *filen
bytes_remaining = (diff = end_pos - current_pos) < 0 ? 0 : diff;
if (bytes_remaining <= n_elide)
- return 0;
+ return true;
/* Seek back to `current' position, then copy the required
number of bytes from fd. */
@@ -451,24 +451,24 @@ elide_tail_bytes_file (const char *filen
{
error (0, errno, _("%s: cannot lseek back to original position"),
quote (filename));
- return 1;
+ return false;
}
err = copy_fd (fd, stdout, bytes_remaining - n_elide);
if (err == COPY_FD_OK)
- return 0;
+ return true;
diagnose_copy_fd_failure (err, filename);
- return 1;
+ return false;
}
}
/* Print all but the last N_ELIDE lines from the input stream
open for reading via file descriptor FD.
Buffer the specified number of lines as a linked list of LBUFFERs,
- adding them as needed. Return 0 if successful, 1 upon error. */
+ adding them as needed. Return true if successful. */
-static int
+static bool
elide_tail_lines_pipe (const char *filename, int fd, uintmax_t n_elide)
{
struct linebuffer
@@ -481,7 +481,7 @@ elide_tail_lines_pipe (const char *filen
typedef struct linebuffer LBUFFER;
LBUFFER *first, *last, *tmp;
size_t total_lines = 0; /* Total number of newlines in all buffers. */
- int errors = 0;
+ bool ok = true;
size_t n_read; /* Size in bytes of most recent read */
first = last = xmalloc (sizeof (LBUFFER));
@@ -547,7 +547,7 @@ elide_tail_lines_pipe (const char *filen
if (n_read == SAFE_READ_ERROR)
{
error (0, errno, _("error reading %s"), quote (filename));
- errors = 1;
+ ok = false;
goto free_lbuffers;
}
@@ -587,7 +587,7 @@ free_lbuffers:
free (first);
first = tmp;
}
- return errors;
+ return ok;
}
/* Output all but the last N_LINES lines of the input stream defined by
@@ -595,13 +595,13 @@ free_lbuffers:
START_POS is the starting position of the read pointer for the file
associated with FD (may be nonzero).
END_POS is the file offset of EOF (one larger than offset of last byte).
- Return zero upon success.
- Give a diagnostic and return nonzero upon error.
+ Return true upon success.
+ Give a diagnostic and return false upon error.
NOTE: this code is very similar to that of tail.c's file_lines function.
Unfortunately, factoring out some common core looks like it'd result
in a less efficient implementation or a messy interface. */
-static int
+static bool
elide_tail_lines_seekable (const char *pretty_filename, int fd,
uintmax_t n_lines,
off_t start_pos, off_t end_pos)
@@ -623,13 +623,13 @@ elide_tail_lines_seekable (const char *p
char offset_buf[INT_BUFSIZE_BOUND (off_t)];
error (0, errno, _("%s: cannot seek to offset %s"),
pretty_filename, offtostr (pos, offset_buf));
- return 1;
+ return false;
}
bytes_read = safe_read (fd, buffer, bytes_read);
if (bytes_read == SAFE_READ_ERROR)
{
error (0, errno, _("error reading %s"), quote (pretty_filename));
- return 1;
+ return false;
}
/* Count the incomplete line on files that don't end with a newline. */
@@ -662,14 +662,14 @@ elide_tail_lines_seekable (const char *p
error (0, errno,
"%s: unable to restore file pointer to initial offset",
quote (pretty_filename));
- return 1;
+ return false;
}
err = copy_fd (fd, stdout, pos - start_pos);
if (err != COPY_FD_OK)
{
diagnose_copy_fd_failure (err, pretty_filename);
- return 1;
+ return false;
}
}
@@ -678,7 +678,7 @@ elide_tail_lines_seekable (const char *p
Don't bother testing for failure for such a small amount.
Any failure will be detected upon close. */
fwrite (buffer, 1, n + 1, stdout);
- return 0;
+ return true;
}
}
@@ -686,7 +686,7 @@ elide_tail_lines_seekable (const char *p
if (pos == start_pos)
{
/* Not enough lines in the file. */
- return 0;
+ return true;
}
pos -= BUFSIZ;
if (lseek (fd, pos, SEEK_SET) < 0)
@@ -694,28 +694,28 @@ elide_tail_lines_seekable (const char *p
char offset_buf[INT_BUFSIZE_BOUND (off_t)];
error (0, errno, _("%s: cannot seek to offset %s"),
pretty_filename, offtostr (pos, offset_buf));
- return 1;
+ return false;
}
bytes_read = safe_read (fd, buffer, BUFSIZ);
if (bytes_read == SAFE_READ_ERROR)
{
error (0, errno, _("error reading %s"), quote (pretty_filename));
- return 1;
+ return false;
}
/* FIXME: is this dead code?
Consider the test, pos == start_pos, above. */
if (bytes_read == 0)
- return 0;
+ return true;
}
}
/* Print all but the last N_ELIDE lines from the input available
- via file descriptor FD. Return zero upon success.
+ via file descriptor FD. Return true upon success.
Give a diagnostic and return nonzero upon error. */
-static int
+static bool
elide_tail_lines_file (const char *filename, int fd, uintmax_t n_elide)
{
/* We need binary input, since `head' relies on `lseek' and byte counts,
@@ -727,7 +727,7 @@ elide_tail_lines_file (const char *filen
/* Find the offset, OFF, of the Nth newline from the end,
but not counting the last byte of the file.
If found, write from current position to OFF, inclusive.
- Otherwise, just return 0. */
+ Otherwise, just return true. */
off_t start_pos = lseek (fd, (off_t) 0, SEEK_CUR);
off_t end_pos = lseek (fd, (off_t) 0, SEEK_END);
@@ -735,7 +735,7 @@ elide_tail_lines_file (const char *filen
{
/* If the file is empty, we're done. */
if (end_pos == 0)
- return 0;
+ return true;
return elide_tail_lines_seekable (filename, fd, n_elide,
start_pos, end_pos);
@@ -748,7 +748,7 @@ elide_tail_lines_file (const char *filen
return elide_tail_lines_pipe (filename, fd, n_elide);
}
-static int
+static bool
head_bytes (const char *filename, int fd, uintmax_t bytes_to_write)
{
char buffer[BUFSIZ];
@@ -766,7 +766,7 @@ head_bytes (const char *filename, int fd
if (bytes_read == SAFE_READ_ERROR)
{
error (0, errno, _("error reading %s"), quote (filename));
- return 1;
+ return false;
}
if (bytes_read == 0)
break;
@@ -774,10 +774,10 @@ head_bytes (const char *filename, int fd
error (EXIT_FAILURE, errno, _("write error"));
bytes_to_write -= bytes_read;
}
- return 0;
+ return true;
}
-static int
+static bool
head_lines (const char *filename, int fd, uintmax_t lines_to_write)
{
char buffer[BUFSIZ];
@@ -794,7 +794,7 @@ head_lines (const char *filename, int fd
if (bytes_read == SAFE_READ_ERROR)
{
error (0, errno, _("error reading %s"), quote (filename));
- return 1;
+ return false;
}
if (bytes_read == 0)
break;
@@ -818,12 +818,12 @@ head_lines (const char *filename, int fd
if (fwrite (buffer, 1, bytes_to_write, stdout) < bytes_to_write)
error (EXIT_FAILURE, errno, _("write error"));
}
- return 0;
+ return true;
}
-static int
-head (const char *filename, int fd, uintmax_t n_units, int count_lines,
- int elide_from_end)
+static bool
+head (const char *filename, int fd, uintmax_t n_units, bool count_lines,
+ bool elide_from_end)
{
if (print_headers)
write_header (filename);
@@ -845,16 +845,16 @@ head (const char *filename, int fd, uint
return head_bytes (filename, fd, n_units);
}
-static int
-head_file (const char *filename, uintmax_t n_units, int count_lines,
- int elide_from_end)
+static bool
+head_file (const char *filename, uintmax_t n_units, bool count_lines,
+ bool elide_from_end)
{
int fd;
- int fail;
+ bool ok;
if (STREQ (filename, "-"))
{
- have_read_stdin = 1;
+ have_read_stdin = true;
fd = STDIN_FILENO;
filename = _("standard input");
}
@@ -864,17 +864,17 @@ head_file (const char *filename, uintmax
if (fd < 0)
{
error (0, errno, _("cannot open %s for reading"), quote (filename));
- return 1;
+ return false;
}
}
- fail = head (filename, fd, n_units, count_lines, elide_from_end);
+ ok = head (filename, fd, n_units, count_lines, elide_from_end);
if (fd != STDIN_FILENO && close (fd) == -1)
{
error (0, errno, _("closing %s"), quote (filename));
- fail = 1;
+ return false;
}
- return fail;
+ return ok;
}
/* Convert a string of decimal digits, N_STRING, with a single, optional suffix
@@ -884,7 +884,7 @@ head_file (const char *filename, uintmax
of lines. It is used solely to give a more specific diagnostic. */
static uintmax_t
-string_to_integer (int count_lines, const char *n_string)
+string_to_integer (bool count_lines, const char *n_string)
{
strtol_error s_err;
uintmax_t n;
@@ -913,20 +913,20 @@ int
main (int argc, char **argv)
{
enum header_mode header_mode = multiple_files;
- int exit_status = 0;
+ bool ok = true;
int c;
size_t i;
/* Number of items to print. */
uintmax_t n_units = DEFAULT_NUMBER;
- /* If nonzero, interpret the numeric argument as the number of lines.
+ /* If true, interpret the numeric argument as the number of lines.
Otherwise, interpret it as the number of bytes. */
- int count_lines = 1;
+ bool count_lines = true;
/* Elide the specified number of lines or bytes, counting from
the end of the file. */
- int elide_from_end = 0;
+ bool elide_from_end = false;
/* Initializer for file_list if no file-arguments
were specified on the command line. */
@@ -941,9 +941,9 @@ main (int argc, char **argv)
atexit (close_stdout);
- have_read_stdin = 0;
+ have_read_stdin = false;
- print_headers = 0;
+ print_headers = false;
if (1 < argc && argv[1][0] == '-' && ISDIGIT (argv[1][1]))
{
@@ -966,19 +966,19 @@ main (int argc, char **argv)
switch (*a)
{
case 'c':
- count_lines = 0;
+ count_lines = false;
multiplier_char = 0;
break;
case 'b':
case 'k':
case 'm':
- count_lines = 0;
+ count_lines = false;
multiplier_char = *a;
break;
case 'l':
- count_lines = 1;
+ count_lines = true;
break;
case 'q':
@@ -997,9 +997,10 @@ main (int argc, char **argv)
if (200112 <= posix2_version ())
{
+ int n_string_prefix_len = end_n_string - n_string;
error (0, 0, _("`-%s' option is obsolete; use `-%c %.*s%.*s%s'"),
n_string, count_lines ? 'n' : 'c',
- (int) (end_n_string - n_string), n_string,
+ n_string_prefix_len, n_string,
multiplier_char != 0, &multiplier_char,
header_mode_option[header_mode]);
usage (EXIT_FAILURE);
@@ -1030,11 +1031,11 @@ main (int argc, char **argv)
break;
case PRESUME_INPUT_PIPE_OPTION:
- presume_input_pipe = 1;
+ presume_input_pipe = true;
break;
case 'c':
- count_lines = 0;
+ count_lines = false;
elide_from_end = (*optarg == '-');
if (elide_from_end)
++optarg;
@@ -1042,7 +1043,7 @@ main (int argc, char **argv)
break;
case 'n':
- count_lines = 1;
+ count_lines = true;
elide_from_end = (*optarg == '-');
if (elide_from_end)
++optarg;
@@ -1068,7 +1069,7 @@ main (int argc, char **argv)
if (header_mode == always
|| (header_mode == multiple_files && optind < argc - 1))
- print_headers = 1;
+ print_headers = true;
if ( ! count_lines && elide_from_end && OFF_T_MAX < n_units)
{
@@ -1082,11 +1083,10 @@ main (int argc, char **argv)
: default_file_list);
for (i = 0; file_list[i]; ++i)
- exit_status |= head_file (file_list[i], n_units, count_lines,
- elide_from_end);
+ ok &= head_file (file_list[i], n_units, count_lines, elide_from_end);
if (have_read_stdin && close (STDIN_FILENO) < 0)
error (EXIT_FAILURE, errno, "-");
- exit (exit_status == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
+ exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- coreutils minor int cleanups for factor, fold, head,
Paul Eggert <=
- Prev by Date:
coreutils minor cleanups for csplit, cut, date, env, expr
- Next by Date:
coreutils minor fixes for id.c, setuidgid.c
- Previous by thread:
coreutils minor cleanups for csplit, cut, date, env, expr
- Next by thread:
coreutils minor fixes for id.c, setuidgid.c
- Index(es):