diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2006-08-09 18:07:43 +0000 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2006-08-09 18:07:43 +0000 |
commit | b1a2656bdb41940f41deaa27d390ec311a06da2b (patch) | |
tree | 10663a458f3b103f943f539037170d7a7f1b6123 /src | |
parent | a5e7cc0811dcf543078c0f7f79fa159232a0ea6f (diff) | |
download | coreutils-b1a2656bdb41940f41deaa27d390ec311a06da2b.tar.xz |
(next_line): New function.
(read_input): Use it, to avoid relying on GCC-specific behavior
with void * arithmetic.
Diffstat (limited to 'src')
-rw-r--r-- | src/shuf.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/shuf.c b/src/shuf.c index ac1d469c9..4d215ee67 100644 --- a/src/shuf.c +++ b/src/shuf.c @@ -129,6 +129,16 @@ input_from_argv (char **operand, int n_operands, char eolbyte) operand[n_operands] = p; } +/* Return the start of the next line after LINE. The current line + ends in EOLBYTE, and is guaranteed to end before LINE + N. */ + +static char * +next_line (char *line, char eolbyte, size_t n) +{ + char *p = memchr (line, eolbyte, n); + return p + 1; +} + /* Read data from file IN. Input lines are delimited by EOLBYTE; silently append a trailing EOLBYTE if the file ends in some other byte. Store a pointer to the resulting array of lines into *PLINE. @@ -193,14 +203,14 @@ read_input (FILE *in, char eolbyte, char ***pline) lim = buf + used; n_lines = 0; - for (p = buf; p < lim; p = memchr (p, eolbyte, lim - p) + 1) + for (p = buf; p < lim; p = next_line (p, eolbyte, lim - p)) n_lines++; *pline = line = xnmalloc (n_lines + 1, sizeof *line); line[0] = p = buf; for (i = 1; i <= n_lines; i++) - line[i] = p = memchr (p, eolbyte, lim - p) + 1; + line[i] = p = next_line (p, eolbyte, lim - p); errno = fread_errno; return n_lines; |