diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 19:33:34 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 19:33:34 +0000 |
commit | 1272be04be0cb803eec87f602edb2e3e6f111aea (patch) | |
tree | bce17f6478cdd9f3c4ec3d751135dc42786d6a56 /text-utils/rev.c | |
parent | Releasing progress-linux version 2.39.3-11~progress7.99u1. (diff) | |
download | util-linux-1272be04be0cb803eec87f602edb2e3e6f111aea.tar.xz util-linux-1272be04be0cb803eec87f602edb2e3e6f111aea.zip |
Merging upstream version 2.40.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'text-utils/rev.c')
-rw-r--r-- | text-utils/rev.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/text-utils/rev.c b/text-utils/rev.c index fbf04d1..4b73189 100644 --- a/text-utils/rev.c +++ b/text-utils/rev.c @@ -79,8 +79,8 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_("Reverse lines characterwise.\n"), out); fputs(USAGE_OPTIONS, out); - printf(USAGE_HELP_OPTIONS(16)); - printf(USAGE_MAN_TAIL("rev(1)")); + fprintf(out, USAGE_HELP_OPTIONS(16)); + fprintf(out, USAGE_MAN_TAIL("rev(1)")); exit(EXIT_SUCCESS); } @@ -157,7 +157,7 @@ int main(int argc, char *argv[]) argc -= optind; argv += optind; - buf = xmalloc(bufsiz * sizeof(wchar_t)); + buf = xreallocarray(NULL, bufsiz, sizeof(wchar_t)); do { if (*argv) { @@ -173,8 +173,6 @@ int main(int argc, char *argv[]) line = 0; while (!feof(fp)) { len = read_line(sep, buf, bufsiz, fp); - if (len == 0) - continue; /* This is my hack from setpwnam.c -janl */ while (len == bufsiz && !feof(fp)) { @@ -182,19 +180,23 @@ int main(int argc, char *argv[]) /* So now we double the buffer size */ bufsiz *= 2; - buf = xrealloc(buf, bufsiz * sizeof(wchar_t)); + buf = xreallocarray(buf, bufsiz, sizeof(wchar_t)); /* And fill the rest of the buffer */ len += read_line(sep, &buf[len], bufsiz/2, fp); } + if (ferror(fp)) { + warn("%s: %ju", filename, line); + rval = EXIT_FAILURE; + break; + } + if (len == 0) + continue; + reverse_str(buf, buf[len - 1] == sep ? len - 1 : len); write_line(buf, len, stdout); line++; } - if (ferror(fp)) { - warn("%s: %ju", filename, line); - rval = EXIT_FAILURE; - } if (fp != stdin) fclose(fp); } while(*argv); @@ -202,4 +204,3 @@ int main(int argc, char *argv[]) free(buf); return rval; } - |