summaryrefslogtreecommitdiffstats
path: root/text-utils/rev.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 19:33:30 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 19:33:30 +0000
commitc61e14d3a8412cd50d98aab604e607692c844c8a (patch)
tree4925aca0e6b64c8664ea2f3fdfa99a52dc93d5da /text-utils/rev.c
parentAdding upstream version 2.39.3. (diff)
downloadutil-linux-c61e14d3a8412cd50d98aab604e607692c844c8a.tar.xz
util-linux-c61e14d3a8412cd50d98aab604e607692c844c8a.zip
Adding upstream version 2.40.upstream/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.c23
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;
}
-