summaryrefslogtreecommitdiffstats
path: root/text-utils
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 19:33:34 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 19:33:34 +0000
commit1272be04be0cb803eec87f602edb2e3e6f111aea (patch)
treebce17f6478cdd9f3c4ec3d751135dc42786d6a56 /text-utils
parentReleasing progress-linux version 2.39.3-11~progress7.99u1. (diff)
downloadutil-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')
-rw-r--r--text-utils/col.16
-rw-r--r--text-utils/col.c10
-rw-r--r--text-utils/colcrt.16
-rw-r--r--text-utils/colcrt.c4
-rw-r--r--text-utils/colrm.16
-rw-r--r--text-utils/colrm.c4
-rw-r--r--text-utils/column.16
-rw-r--r--text-utils/column.c8
-rw-r--r--text-utils/hexdump-display.c10
-rw-r--r--text-utils/hexdump-parse.c4
-rw-r--r--text-utils/hexdump.112
-rw-r--r--text-utils/hexdump.1.adoc5
-rw-r--r--text-utils/hexdump.c14
-rw-r--r--text-utils/line.16
-rw-r--r--text-utils/line.1.adoc6
-rw-r--r--text-utils/line.c11
-rw-r--r--text-utils/more.16
-rw-r--r--text-utils/more.c135
-rw-r--r--text-utils/pg.16
-rw-r--r--text-utils/pg.c10
-rw-r--r--text-utils/rev.16
-rw-r--r--text-utils/rev.c23
-rw-r--r--text-utils/ul.16
-rw-r--r--text-utils/ul.c6
24 files changed, 192 insertions, 124 deletions
diff --git a/text-utils/col.1 b/text-utils/col.1
index c18d4b2..1917720 100644
--- a/text-utils/col.1
+++ b/text-utils/col.1
@@ -2,12 +2,12 @@
.\" Title: col
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.20
-.\" Date: 2023-11-30
+.\" Date: 2024-01-31
.\" Manual: User Commands
-.\" Source: util-linux 2.39.3
+.\" Source: util-linux 2.40
.\" Language: English
.\"
-.TH "COL" "1" "2023-11-30" "util\-linux 2.39.3" "User Commands"
+.TH "COL" "1" "2024-01-31" "util\-linux 2.40" "User Commands"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
diff --git a/text-utils/col.c b/text-utils/col.c
index 56ccec9..f9bc3be 100644
--- a/text-utils/col.c
+++ b/text-utils/col.c
@@ -182,10 +182,10 @@ static void __attribute__((__noreturn__)) usage(void)
" -x, --spaces convert tabs to spaces\n"
" -l, --lines NUM buffer at least NUM lines\n"
));
- printf( " -H, --help %s\n", USAGE_OPTSTR_HELP);
- printf( " -V, --version %s\n", USAGE_OPTSTR_VERSION);
+ fprintf(out, " -H, --help %s\n", USAGE_OPTSTR_HELP);
+ fprintf(out, " -V, --version %s\n", USAGE_OPTSTR_VERSION);
- printf(USAGE_MAN_TAIL("col(1)"));
+ fprintf(out, USAGE_MAN_TAIL("col(1)"));
exit(EXIT_SUCCESS);
}
@@ -244,11 +244,11 @@ static void flush_line(struct col_ctl *ctl, struct col_line *l)
*/
if (sorted_size < l->l_lsize) {
sorted_size = l->l_lsize;
- sorted = xrealloc(sorted, sizeof(struct col_char) * sorted_size);
+ sorted = xreallocarray(sorted, sorted_size, sizeof(struct col_char));
}
if (count_size <= l->l_max_col) {
count_size = l->l_max_col + 1;
- count = xrealloc(count, sizeof(size_t) * count_size);
+ count = xreallocarray(count, count_size, sizeof(size_t));
}
memset(count, 0, sizeof(size_t) * l->l_max_col + 1);
for (i = nchars, c = l->l_line; c && 0 < i; i--, c++)
diff --git a/text-utils/colcrt.1 b/text-utils/colcrt.1
index 869a91b..e1369e5 100644
--- a/text-utils/colcrt.1
+++ b/text-utils/colcrt.1
@@ -2,12 +2,12 @@
.\" Title: colcrt
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.20
-.\" Date: 2023-10-23
+.\" Date: 2024-01-31
.\" Manual: User Commands
-.\" Source: util-linux 2.39.3
+.\" Source: util-linux 2.40
.\" Language: English
.\"
-.TH "COLCRT" "1" "2023-10-23" "util\-linux 2.39.3" "User Commands"
+.TH "COLCRT" "1" "2024-01-31" "util\-linux 2.40" "User Commands"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
diff --git a/text-utils/colcrt.c b/text-utils/colcrt.c
index 113e3d0..a6da499 100644
--- a/text-utils/colcrt.c
+++ b/text-utils/colcrt.c
@@ -89,9 +89,9 @@ static void __attribute__((__noreturn__)) usage(void)
fputs(_(" -2, --half-lines print all half-lines\n"), out);
fputs(USAGE_SEPARATOR, out);
- printf(USAGE_HELP_OPTIONS(25));
+ fprintf(out, USAGE_HELP_OPTIONS(25));
- printf(USAGE_MAN_TAIL("colcrt(1)"));
+ fprintf(out, USAGE_MAN_TAIL("colcrt(1)"));
exit(EXIT_SUCCESS);
}
diff --git a/text-utils/colrm.1 b/text-utils/colrm.1
index 54088ae..d0863b6 100644
--- a/text-utils/colrm.1
+++ b/text-utils/colrm.1
@@ -2,12 +2,12 @@
.\" Title: colrm
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.20
-.\" Date: 2023-10-23
+.\" Date: 2024-01-31
.\" Manual: User Commands
-.\" Source: util-linux 2.39.3
+.\" Source: util-linux 2.40
.\" Language: English
.\"
-.TH "COLRM" "1" "2023-10-23" "util\-linux 2.39.3" "User Commands"
+.TH "COLRM" "1" "2024-01-31" "util\-linux 2.40" "User Commands"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
diff --git a/text-utils/colrm.c b/text-utils/colrm.c
index 7df5a74..1225643 100644
--- a/text-utils/colrm.c
+++ b/text-utils/colrm.c
@@ -65,10 +65,10 @@ static void __attribute__((__noreturn__)) usage(void)
fputs(_("Filter out the specified columns.\n"), out);
fputs(USAGE_OPTIONS, out);
- printf(USAGE_HELP_OPTIONS(16));
+ fprintf(out, USAGE_HELP_OPTIONS(16));
fprintf(out, _("%s reads from standard input and writes to standard output\n\n"),
program_invocation_short_name);
- printf(USAGE_MAN_TAIL("colrm(1)"));
+ fprintf(out, USAGE_MAN_TAIL("colrm(1)"));
exit(EXIT_SUCCESS);
}
diff --git a/text-utils/column.1 b/text-utils/column.1
index 2ebeb5a..3883566 100644
--- a/text-utils/column.1
+++ b/text-utils/column.1
@@ -2,12 +2,12 @@
.\" Title: column
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.20
-.\" Date: 2023-11-21
+.\" Date: 2024-01-31
.\" Manual: User Commands
-.\" Source: util-linux 2.39.3
+.\" Source: util-linux 2.40
.\" Language: English
.\"
-.TH "COLUMN" "1" "2023-11-21" "util\-linux 2.39.3" "User Commands"
+.TH "COLUMN" "1" "2024-01-31" "util\-linux 2.40" "User Commands"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
diff --git a/text-utils/column.c b/text-utils/column.c
index 0f2e7e1..06aeaa0 100644
--- a/text-utils/column.c
+++ b/text-utils/column.c
@@ -585,7 +585,7 @@ static void add_entry(struct column_control *ctl, size_t *maxents, wchar_t *wcs)
{
if (ctl->nents <= *maxents) {
*maxents += 1000;
- ctl->ents = xrealloc(ctl->ents, *maxents * sizeof(wchar_t *));
+ ctl->ents = xreallocarray(ctl->ents, *maxents, sizeof(wchar_t *));
}
ctl->ents[ctl->nents] = wcs;
ctl->nents++;
@@ -662,6 +662,8 @@ static int read_input(struct column_control *ctl, FILE *fp)
}
} while (rc == 0);
+ free(buf);
+
return rc;
}
@@ -776,8 +778,8 @@ static void __attribute__((__noreturn__)) usage(void)
fputs(USAGE_SEPARATOR, out);
- printf(USAGE_HELP_OPTIONS(34));
- printf(USAGE_MAN_TAIL("column(1)"));
+ fprintf(out, USAGE_HELP_OPTIONS(34));
+ fprintf(out, USAGE_MAN_TAIL("column(1)"));
exit(EXIT_SUCCESS);
}
diff --git a/text-utils/hexdump-display.c b/text-utils/hexdump-display.c
index bc92bd0..c865127 100644
--- a/text-utils/hexdump-display.c
+++ b/text-utils/hexdump-display.c
@@ -250,6 +250,8 @@ void display(struct hexdump *hex)
struct list_head *p, *q, *r;
while ((bp = get(hex)) != NULL) {
+ ssize_t rem = hex->blocksize;
+
fs = &hex->fshead; savebp = bp; saveaddress = address;
list_for_each(p, fs) {
@@ -263,7 +265,7 @@ void display(struct hexdump *hex)
cnt = fu->reps;
- while (cnt) {
+ while (cnt && rem >= 0) {
list_for_each(r, &fu->prlist) {
pr = list_entry(r, struct hexdump_pr, prlist);
@@ -280,12 +282,18 @@ void display(struct hexdump *hex)
print(pr, bp);
address += pr->bcnt;
+
+ rem -= pr->bcnt;
+ if (rem < 0)
+ break;
+
bp += pr->bcnt;
}
--cnt;
}
}
bp = savebp;
+ rem = hex->blocksize;
address = saveaddress;
}
}
diff --git a/text-utils/hexdump-parse.c b/text-utils/hexdump-parse.c
index 272bb24..23fffc8 100644
--- a/text-utils/hexdump-parse.c
+++ b/text-utils/hexdump-parse.c
@@ -427,9 +427,7 @@ isint: cs[3] = '\0';
*/
savech = *p2;
p1[0] = '\0';
- pr->fmt = xmalloc(strlen(fmtp) + strlen(cs) + 1);
- strcpy(pr->fmt, fmtp);
- strcat(pr->fmt, cs);
+ xasprintf(&pr->fmt, "%s%s", fmtp, cs);
*p2 = savech;
pr->cchar = pr->fmt + (p1 - fmtp);
fmtp = p2;
diff --git a/text-utils/hexdump.1 b/text-utils/hexdump.1
index 3dc84a3..a56773b 100644
--- a/text-utils/hexdump.1
+++ b/text-utils/hexdump.1
@@ -2,12 +2,12 @@
.\" Title: hexdump
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.20
-.\" Date: 2023-12-01
+.\" Date: 2024-03-20
.\" Manual: User Commands
-.\" Source: util-linux 2.39.3
+.\" Source: util-linux 2.40
.\" Language: English
.\"
-.TH "HEXDUMP" "1" "2023-12-01" "util\-linux 2.39.3" "User Commands"
+.TH "HEXDUMP" "1" "2024-03-20" "util\-linux 2.40" "User Commands"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
@@ -29,6 +29,7 @@
.\}
.SH "NAME"
hexdump \- display file contents in hexadecimal, decimal, octal, or ascii
+.SH "SYNOPSIS"
.sp
\fBhexdump\fP \fIoptions file\fP ...
.sp
@@ -45,6 +46,11 @@ Below, the \fIlength\fP and \fIoffset\fP arguments may be followed by the multip
\fIOne\-byte octal display\fP. Display the input offset in hexadecimal, followed by sixteen space\-separated, three\-column, zero\-filled bytes of input data, in octal, per line.
.RE
.sp
+\fB\-X\fP, \fB\-\-one\-byte\-hex\fP
+.RS 4
+\fIOne\-byte hexadecimal display\fP. Display the input offset in hexadecimal, followed by sixteen space\-separated, two\-column, zero\-filled bytes of input data, in hexadecimal, per line.
+.RE
+.sp
\fB\-c\fP, \fB\-\-one\-byte\-char\fP
.RS 4
\fIOne\-byte character display\fP. Display the input offset in hexadecimal, followed by sixteen space\-separated, three\-column, space\-filled characters of input data per line.
diff --git a/text-utils/hexdump.1.adoc b/text-utils/hexdump.1.adoc
index 82c1e60..dd6247e 100644
--- a/text-utils/hexdump.1.adoc
+++ b/text-utils/hexdump.1.adoc
@@ -46,6 +46,8 @@ SUCH DAMAGE.
hexdump - display file contents in hexadecimal, decimal, octal, or ascii
+== SYNOPSIS
+
*hexdump* _options file_ ...
*hd* _options file_ ...
@@ -61,6 +63,9 @@ Below, the _length_ and _offset_ arguments may be followed by the multiplicative
*-b*, *--one-byte-octal*::
_One-byte octal display_. Display the input offset in hexadecimal, followed by sixteen space-separated, three-column, zero-filled bytes of input data, in octal, per line.
+*-X*, *--one-byte-hex*::
+_One-byte hexadecimal display_. Display the input offset in hexadecimal, followed by sixteen space-separated, two-column, zero-filled bytes of input data, in hexadecimal, per line.
+
*-c*, *--one-byte-char*::
_One-byte character display_. Display the input offset in hexadecimal, followed by sixteen space-separated, three-column, space-filled characters of input data per line.
diff --git a/text-utils/hexdump.c b/text-utils/hexdump.c
index 73b3a94..3674455 100644
--- a/text-utils/hexdump.c
+++ b/text-utils/hexdump.c
@@ -66,6 +66,7 @@ parse_args(int argc, char **argv, struct hexdump *hex)
static const struct option longopts[] = {
{"one-byte-octal", no_argument, NULL, 'b'},
+ {"one-byte-hex", no_argument, NULL, 'X'},
{"one-byte-char", no_argument, NULL, 'c'},
{"canonical", no_argument, NULL, 'C'},
{"two-bytes-decimal", no_argument, NULL, 'd'},
@@ -82,12 +83,16 @@ parse_args(int argc, char **argv, struct hexdump *hex)
{NULL, no_argument, NULL, 0}
};
- while ((ch = getopt_long(argc, argv, "bcCde:f:L::n:os:vxhV", longopts, NULL)) != -1) {
+ while ((ch = getopt_long(argc, argv, "bXcCde:f:L::n:os:vxhV", longopts, NULL)) != -1) {
switch (ch) {
case 'b':
add_fmt(hex_offt, hex);
add_fmt("\"%07.7_ax \" 16/1 \"%03o \" \"\\n\"", hex);
break;
+ case 'X':
+ add_fmt("\"%07.7_Ax\n\"", hex);
+ add_fmt("\"%07.7_ax \" 16/1 \" %02x \" \"\\n\"", hex);
+ break;
case 'c':
add_fmt(hex_offt, hex);
add_fmt("\"%07.7_ax \" 16/1 \"%3_c \" \"\\n\"", hex);
@@ -166,6 +171,7 @@ void __attribute__((__noreturn__)) usage(void)
fputs(USAGE_OPTIONS, out);
fputs(_(" -b, --one-byte-octal one-byte octal display\n"), out);
+ fputs(_(" -X, --one-byte-hex one-byte hexadecimal display\n"), out);
fputs(_(" -c, --one-byte-char one-byte character display\n"), out);
fputs(_(" -C, --canonical canonical hex+ASCII display\n"), out);
fputs(_(" -d, --two-bytes-decimal two-byte decimal display\n"), out);
@@ -181,12 +187,12 @@ void __attribute__((__noreturn__)) usage(void)
fputs(_(" -v, --no-squeezing output identical lines\n"), out);
fputs(USAGE_SEPARATOR, out);
- printf(USAGE_HELP_OPTIONS(27));
+ fprintf(out, USAGE_HELP_OPTIONS(27));
fputs(USAGE_ARGUMENTS, out);
- printf(USAGE_ARG_SIZE(_("<length> and <offset>")));
+ fprintf(out, USAGE_ARG_SIZE(_("<length> and <offset>")));
- printf(USAGE_MAN_TAIL("hexdump(1)"));
+ fprintf(out, USAGE_MAN_TAIL("hexdump(1)"));
exit(EXIT_SUCCESS);
}
diff --git a/text-utils/line.1 b/text-utils/line.1
index 0ea18b2..61ca1c7 100644
--- a/text-utils/line.1
+++ b/text-utils/line.1
@@ -2,12 +2,12 @@
.\" Title: line
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.20
-.\" Date: 2023-10-23
+.\" Date: 2024-03-20
.\" Manual: User Commands
-.\" Source: util-linux 2.39.3
+.\" Source: util-linux 2.40
.\" Language: English
.\"
-.TH "LINE" "1" "2023-10-23" "util\-linux 2.39.3" "User Commands"
+.TH "LINE" "1" "2024-03-20" "util\-linux 2.40" "User Commands"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
diff --git a/text-utils/line.1.adoc b/text-utils/line.1.adoc
index d3c929b..bed0d0d 100644
--- a/text-utils/line.1.adoc
+++ b/text-utils/line.1.adoc
@@ -1,4 +1,8 @@
-//po4a: entry man manual
+//
+// No copyright is claimed. This code is in the public domain; do with
+// it what you wish.
+//
+// po4a: entry man manual
// This page is in the public domain
= line(1)
:doctype: manpage
diff --git a/text-utils/line.c b/text-utils/line.c
index e894076..b7853a1 100644
--- a/text-utils/line.c
+++ b/text-utils/line.c
@@ -1,12 +1,11 @@
/*
+ * No copyright is claimed. This code is in the public domain; do with
+ * it what you wish.
+ *
* line - read one line
*
* Gunnar Ritter, Freiburg i. Br., Germany, December 2000.
*
- * Public Domain.
- */
-
-/*
* This command is deprecated. The utility is in maintenance mode,
* meaning we keep them in source tree for backward compatibility
* only. Do not waste time making this command better, unless the
@@ -34,8 +33,8 @@ static void __attribute__((__noreturn__)) usage(void)
fputs(_("Read one line.\n"), out);
fputs(USAGE_OPTIONS, out);
- printf(USAGE_HELP_OPTIONS(16));
- printf(USAGE_MAN_TAIL("line(1)"));
+ fprintf(out,USAGE_HELP_OPTIONS(16));
+ fprintf(out, USAGE_MAN_TAIL("line(1)"));
exit(EXIT_SUCCESS);
}
diff --git a/text-utils/more.1 b/text-utils/more.1
index c5cd80e..ee565bf 100644
--- a/text-utils/more.1
+++ b/text-utils/more.1
@@ -2,12 +2,12 @@
.\" Title: more
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.20
-.\" Date: 2023-11-21
+.\" Date: 2024-01-31
.\" Manual: User Commands
-.\" Source: util-linux 2.39.3
+.\" Source: util-linux 2.40
.\" Language: English
.\"
-.TH "MORE" "1" "2023-11-21" "util\-linux 2.39.3" "User Commands"
+.TH "MORE" "1" "2024-01-31" "util\-linux 2.40" "User Commands"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
diff --git a/text-utils/more.c b/text-utils/more.c
index 22adaab..1badf67 100644
--- a/text-utils/more.c
+++ b/text-utils/more.c
@@ -198,6 +198,7 @@ struct more_control {
magic_t magic; /* libmagic database entries */
#endif
unsigned int
+ ignore_stdin:1, /* POLLHUP; peer closed pipe */
bad_stdout:1, /* true if overwriting does not turn off standout */
catch_suspend:1, /* we should catch the SIGTSTP signal */
clear_line_ends:1, /* do not scroll, paint each screen from the top */
@@ -298,7 +299,7 @@ static void argscan(struct more_control *ctl, int as_argc, char **as_argv)
}
}
if (move) {
- as_argc = remote_entry(as_argv, opt, as_argc);
+ as_argc = remove_entry(as_argv, opt, as_argc);
opt--;
}
}
@@ -353,12 +354,12 @@ static void env_argscan(struct more_control *ctl, const char *s)
char *str = xstrdup(s);
char *key = NULL, *tok;
- env_argv = xmalloc(sizeof(char *) * size);
+ env_argv = xreallocarray(NULL, size, sizeof(char *));
env_argv[0] = _("MORE environment variable"); /* program name */
for (tok = strtok_r(str, delim, &key); tok; tok = strtok_r(NULL, delim, &key)) {
if (size == env_argc) {
size *= 2;
- env_argv = xrealloc(env_argv, sizeof(char *) * size);
+ env_argv = xreallocarray(env_argv, size, sizeof(char *));
}
env_argv[env_argc++] = tok;
}
@@ -625,9 +626,6 @@ static int get_line(struct more_control *ctl, int *length)
*p++ = 'L';
column += 2;
ctl->is_paused = 1;
- } else if (c == EOF) {
- *length = p - ctl->line_buf;
- return column;
} else {
#ifdef HAVE_WIDECHAR
if (ctl->fold_long_lines && MB_CUR_MAX > 1) {
@@ -1253,8 +1251,7 @@ static void __attribute__((__format__ (__printf__, 3, 4)))
}
va_end(argp);
- args = alloca(sizeof(char *) * (argcount + 1));
- args[argcount] = NULL;
+ args = xcalloc(argcount + 1, sizeof(char *));
va_start(argp, cmd);
arg = va_arg(argp, char *);
@@ -1352,50 +1349,92 @@ static void read_line(struct more_control *ctl)
*p = '\0';
}
+/* returns: 0 timeout or nothing; <0 error, >0 success */
static int more_poll(struct more_control *ctl, int timeout)
{
- struct pollfd pfd[2];
+ enum {
+ POLLFD_SIGNAL = 0,
+ POLLFD_STDIN,
+ POLLFD_STDERR,
+ };
+ struct pollfd pfd[] = {
+ [POLLFD_SIGNAL] = { .fd = ctl->sigfd, .events = POLLIN | POLLERR | POLLHUP },
+ [POLLFD_STDIN] = { .fd = STDIN_FILENO, .events = POLLIN | POLLERR | POLLHUP },
+ [POLLFD_STDERR] = { .fd = STDERR_FILENO, .events = POLLIN | POLLERR | POLLHUP }
+ };
+ int has_data = 0;
- pfd[0].fd = ctl->sigfd;
- pfd[0].events = POLLIN | POLLERR | POLLHUP;
- pfd[1].fd = STDIN_FILENO;
- pfd[1].events = POLLIN;
+ while (!has_data) {
+ int rc;
- if (poll(pfd, 2, timeout) < 0) {
- if (errno == EAGAIN)
- return 1;
- more_error(ctl, _("poll failed"));
- return 1;
- }
- if (pfd[0].revents != 0) {
- struct signalfd_siginfo info;
- ssize_t sz;
-
- sz = read(pfd[0].fd, &info, sizeof(info));
- assert(sz == sizeof(info));
- switch (info.ssi_signo) {
- case SIGINT:
- more_exit(ctl);
- break;
- case SIGQUIT:
- sigquit_handler(ctl);
- break;
- case SIGTSTP:
- sigtstp_handler(ctl);
- break;
- case SIGCONT:
- sigcont_handler(ctl);
- break;
- case SIGWINCH:
- sigwinch_handler(ctl);
- break;
- default:
- abort();
+ if (ctl->ignore_stdin)
+ pfd[POLLFD_STDIN].fd = -1; /* probably closed, ignore */
+
+ rc = poll(pfd, ARRAY_SIZE(pfd), timeout);
+
+ /* error */
+ if (rc < 0) {
+ if (errno == EAGAIN)
+ continue;
+
+ more_error(ctl, _("poll failed"));
+ return rc;
+ }
+
+ /* timeout */
+ if (rc == 0)
+ return 0;
+
+ /* event on signal FD */
+ if (pfd[POLLFD_SIGNAL].revents) {
+ struct signalfd_siginfo info;
+ ssize_t sz;
+
+ sz = read(pfd[POLLFD_SIGNAL].fd, &info, sizeof(info));
+ assert(sz == sizeof(info));
+ switch (info.ssi_signo) {
+ case SIGINT:
+ more_exit(ctl);
+ break;
+ case SIGQUIT:
+ sigquit_handler(ctl);
+ break;
+ case SIGTSTP:
+ sigtstp_handler(ctl);
+ break;
+ case SIGCONT:
+ sigcont_handler(ctl);
+ break;
+ case SIGWINCH:
+ sigwinch_handler(ctl);
+ break;
+ default:
+ abort();
+ }
}
+
+ /* event on stdin */
+ if (pfd[POLLFD_STDIN].revents) {
+ /* Check for POLLERR and POLLHUP in stdin revents */
+ if ((pfd[POLLFD_STDIN].revents & POLLERR) &&
+ (pfd[POLLFD_STDIN].revents & POLLHUP))
+ more_exit(ctl);
+
+ /* poll() return POLLHUP event after pipe close() and POLLNVAL
+ * means that fd is already closed. */
+ if ((pfd[POLLFD_STDIN].revents & POLLHUP) ||
+ (pfd[POLLFD_STDIN].revents & POLLNVAL))
+ ctl->ignore_stdin = 1;
+ else
+ has_data++;
+ }
+
+ /* event on stderr (we reads user commands from stderr!) */
+ if (pfd[POLLFD_STDERR].revents)
+ has_data++;
}
- if (pfd[1].revents == 0)
- return 1;
- return 0;
+
+ return has_data;
}
/* Search for nth occurrence of regular expression contained in buf in
@@ -1463,7 +1502,7 @@ static void search(struct more_control *ctl, char buf[], int n)
}
break;
}
- more_poll(ctl, 1);
+ more_poll(ctl, 0);
}
/* Move ctrl+c signal handling back to more_key_command(). */
signal(SIGINT, SIG_DFL);
@@ -1627,7 +1666,7 @@ static int more_key_command(struct more_control *ctl, char *filename)
ctl->report_errors = 0;
ctl->search_called = 0;
for (;;) {
- if (more_poll(ctl, -1) != 0)
+ if (more_poll(ctl, -1) <= 0)
continue;
cmd = read_command(ctl);
if (cmd.key == more_kc_unknown_command)
diff --git a/text-utils/pg.1 b/text-utils/pg.1
index 84817b9..1a91b1d 100644
--- a/text-utils/pg.1
+++ b/text-utils/pg.1
@@ -2,12 +2,12 @@
.\" Title: pg
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.20
-.\" Date: 2023-10-23
+.\" Date: 2024-01-31
.\" Manual: User Commands
-.\" Source: util-linux 2.39.3
+.\" Source: util-linux 2.40
.\" Language: English
.\"
-.TH "PG" "1" "2023-10-23" "util\-linux 2.39.3" "User Commands"
+.TH "PG" "1" "2024-01-31" "util\-linux 2.40" "User Commands"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
diff --git a/text-utils/pg.c b/text-utils/pg.c
index adb3840..30ed046 100644
--- a/text-utils/pg.c
+++ b/text-utils/pg.c
@@ -247,9 +247,9 @@ static void __attribute__((__noreturn__)) usage(void)
fputs(_(" +/pattern/ start at the line containing pattern\n"), out);
fputs(USAGE_SEPARATOR, out);
- printf(USAGE_HELP_OPTIONS(16));
+ fprintf(out, USAGE_HELP_OPTIONS(16));
- printf(USAGE_MAN_TAIL("pg(1)"));
+ fprintf(out, USAGE_MAN_TAIL("pg(1)"));
exit(0);
}
@@ -618,9 +618,9 @@ static void prompt(long long pageno)
if ((p = strstr(pstring, "%d")) == NULL) {
mesg(pstring);
} else {
- strcpy(b, pstring);
- sprintf(b + (p - pstring), "%lld", pageno);
- strcat(b, p + 2);
+ snprintf(b, sizeof(b),
+ "%.*s%lld%s", (int) (p - pstring), pstring,
+ pageno, p + 2);
mesg(b);
}
}
diff --git a/text-utils/rev.1 b/text-utils/rev.1
index 3351717..f0998ee 100644
--- a/text-utils/rev.1
+++ b/text-utils/rev.1
@@ -2,12 +2,12 @@
.\" Title: rev
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.20
-.\" Date: 2023-11-21
+.\" Date: 2024-01-31
.\" Manual: User Commands
-.\" Source: util-linux 2.39.3
+.\" Source: util-linux 2.40
.\" Language: English
.\"
-.TH "REV" "1" "2023-11-21" "util\-linux 2.39.3" "User Commands"
+.TH "REV" "1" "2024-01-31" "util\-linux 2.40" "User Commands"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
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;
}
-
diff --git a/text-utils/ul.1 b/text-utils/ul.1
index 2906ee3..ffd9b32 100644
--- a/text-utils/ul.1
+++ b/text-utils/ul.1
@@ -2,12 +2,12 @@
.\" Title: ul
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.20
-.\" Date: 2023-10-23
+.\" Date: 2024-01-31
.\" Manual: User Commands
-.\" Source: util-linux 2.39.3
+.\" Source: util-linux 2.40
.\" Language: English
.\"
-.TH "UL" "1" "2023-10-23" "util\-linux 2.39.3" "User Commands"
+.TH "UL" "1" "2024-01-31" "util\-linux 2.40" "User Commands"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
diff --git a/text-utils/ul.c b/text-utils/ul.c
index d5bca45..85fa86f 100644
--- a/text-utils/ul.c
+++ b/text-utils/ul.c
@@ -128,9 +128,9 @@ static void __attribute__((__noreturn__)) usage(void)
fputs(USAGE_OPTIONS, out);
fputs(_(" -t, -T, --terminal TERMINAL override the TERM environment variable\n"), out);
fputs(_(" -i, --indicated underlining is indicated via a separate line\n"), out);
- printf(USAGE_HELP_OPTIONS(30));
+ fprintf(out, USAGE_HELP_OPTIONS(30));
- printf(USAGE_MAN_TAIL("ul(1)"));
+ fprintf(out, USAGE_MAN_TAIL("ul(1)"));
exit(EXIT_SUCCESS);
}
@@ -141,7 +141,7 @@ static void need_column(struct ul_ctl *ctl, size_t new_max)
while (new_max >= ctl->buflen) {
ctl->buflen *= 2;
- ctl->buf = xrealloc(ctl->buf, sizeof(struct ul_char) * ctl->buflen);
+ ctl->buf = xreallocarray(ctl->buf, ctl->buflen, sizeof(struct ul_char));
}
}