summaryrefslogtreecommitdiff
path: root/text-utils
diff options
context:
space:
mode:
Diffstat (limited to 'text-utils')
-rw-r--r--text-utils/col.14
-rw-r--r--text-utils/col.c82
-rw-r--r--text-utils/colcrt.14
-rw-r--r--text-utils/colrm.14
-rw-r--r--text-utils/column.14
-rw-r--r--text-utils/column.c6
-rw-r--r--text-utils/hexdump.14
-rw-r--r--text-utils/line.14
-rw-r--r--text-utils/more.14
-rw-r--r--text-utils/more.c18
-rw-r--r--text-utils/pg.14
-rw-r--r--text-utils/pg.c20
-rw-r--r--text-utils/rev.14
-rw-r--r--text-utils/rev.c7
-rw-r--r--text-utils/tailf.14
-rw-r--r--text-utils/tailf.c5
-rw-r--r--text-utils/ul.14
-rw-r--r--text-utils/ul.c20
18 files changed, 78 insertions, 124 deletions
diff --git a/text-utils/col.1 b/text-utils/col.1
index 86afba3d..0e6e1330 100644
--- a/text-utils/col.1
+++ b/text-utils/col.1
@@ -137,5 +137,5 @@ A
command
appeared in Version 6 AT&T UNIX.
.Sh AVAILABILITY
-The col command is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+The col command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/text-utils/col.c b/text-utils/col.c
index 3b81a891..9349720c 100644
--- a/text-utils/col.c
+++ b/text-utils/col.c
@@ -50,8 +50,9 @@
#include <string.h>
#include <stdio.h>
#include <unistd.h>
-#include "nls.h"
+#include "nls.h"
+#include "xalloc.h"
#include "widechar.h"
#define BS '\b' /* backspace */
@@ -92,14 +93,10 @@ struct line_str {
int l_max_col; /* max column in the line */
};
-void usage(void);
-void wrerr(void);
-void warn(int);
void free_line(LINE *l);
void flush_line(LINE *l);
void flush_lines(int);
void flush_blanks(void);
-void *xmalloc(void *p, size_t size);
LINE *alloc_line(void);
CSET last_set; /* char_set of last char printed */
@@ -115,6 +112,17 @@ int pass_unknown_seqs; /* whether to pass unknown control sequences */
if (putwchar(ch) == WEOF) \
wrerr();
+static void __attribute__((__noreturn__)) usage()
+{
+ errx(EXIT_FAILURE, _("usage: %s [-bfpx] [-l nline]"),
+ program_invocation_short_name);
+}
+
+static void __attribute__((__noreturn__)) wrerr()
+{
+ errx(EXIT_FAILURE, _("write error."));
+}
+
int main(int argc, char **argv)
{
register wint_t ch;
@@ -128,12 +136,12 @@ int main(int argc, char **argv)
int this_line; /* line l points to */
int nflushd_lines; /* number of lines that were flushed */
int adjust, opt, warned;
- int ret = 0;
+ int ret = EXIT_SUCCESS;
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
-
+
max_bufd_lines = 128;
compress_spaces = 1; /* compress spaces into tabs */
pass_unknown_seqs = 0; /* remove unknown escape sequences */
@@ -149,11 +157,8 @@ int main(int argc, char **argv)
compress_spaces = 1;
break;
case 'l': /* buffered line count */
- if ((max_bufd_lines = atoi(optarg)) <= 0) {
- (void)fprintf(stderr,
- _("col: bad -l argument %s.\n"), optarg);
- exit(1);
- }
+ if ((max_bufd_lines = atoi(optarg)) <= 0)
+ errx(EXIT_FAILURE, _("bad -l argument %s."), optarg);
break;
case 'p':
pass_unknown_seqs = 1;
@@ -176,16 +181,16 @@ int main(int argc, char **argv)
cur_line = max_line = nflushd_lines = this_line = 0;
cur_set = last_set = CS_NORMAL;
lines = l = alloc_line();
-
+
while (feof(stdin)==0) {
errno = 0;
if ((ch = getwchar()) == WEOF) {
if (errno==EILSEQ) {
- perror("col");
- ret = 1;
+ warn(NULL);
+ ret = EXIT_FAILURE;
}
break;
- }
+ }
if (!iswgraph(ch)) {
switch (ch) {
case BS: /* can't go back further */
@@ -275,7 +280,9 @@ int main(int argc, char **argv)
}
} else {
if (!warned++)
- warn(cur_line);
+ warnx(
+ _("warning: can't back up %s."), cur_line < 0 ?
+ _("past first line") : _("-- line already flushed"));
cur_line -= nmove;
}
}
@@ -302,8 +309,8 @@ int main(int argc, char **argv)
int need;
need = l->l_lsize ? l->l_lsize * 2 : 90;
- l->l_line = (CHAR *)xmalloc((void *) l->l_line,
- (unsigned) need * sizeof(CHAR));
+ l->l_line = (CHAR *)xrealloc((void *) l->l_line,
+ (unsigned) need * sizeof(CHAR));
l->l_lsize = need;
}
c = &l->l_line[l->l_line_len++];
@@ -340,7 +347,7 @@ int main(int argc, char **argv)
nblank_lines = 2;
flush_blanks();
if (ferror(stdout) || fclose(stdout))
- return 1;
+ return EXIT_FAILURE;
return ret;
}
@@ -415,12 +422,12 @@ void flush_line(LINE *l)
*/
if (l->l_lsize > sorted_size) {
sorted_size = l->l_lsize;
- sorted = (CHAR *)xmalloc((void *)sorted,
- (unsigned)sizeof(CHAR) * sorted_size);
+ sorted = (CHAR *)xrealloc((void *)sorted,
+ (unsigned)sizeof(CHAR) * sorted_size);
}
if (l->l_max_col >= count_size) {
count_size = l->l_max_col + 1;
- count = (int *)xmalloc((void *)count,
+ count = (int *)xrealloc((void *)count,
(unsigned)sizeof(int) * count_size);
}
memset(count, 0, sizeof(int) * l->l_max_col + 1);
@@ -510,7 +517,7 @@ alloc_line()
int i;
if (!line_freelist) {
- l = (LINE *)xmalloc((void *)NULL, sizeof(LINE) * NALLOC);
+ l = xmalloc(sizeof(LINE) * NALLOC);
line_freelist = l;
for (i = 1; i < NALLOC; i++, l++)
l->l_next = l + 1;
@@ -529,31 +536,4 @@ void free_line(LINE *l)
line_freelist = l;
}
-void *
-xmalloc(void *p, size_t size)
-{
- if (!(p = (void *)realloc(p, size))) {
- (void)fprintf(stderr, "col: %s.\n", strerror(ENOMEM));
- exit(1);
- }
- return(p);
-}
-
-void usage()
-{
- (void)fprintf(stderr, _("usage: col [-bfpx] [-l nline]\n"));
- exit(1);
-}
-void wrerr()
-{
- (void)fprintf(stderr, _("col: write error.\n"));
- exit(1);
-}
-
-void warn(int line)
-{
- (void)fprintf(stderr,
- _("col: warning: can't back up %s.\n"), line < 0 ?
- _("past first line") : _("-- line already flushed"));
-}
diff --git a/text-utils/colcrt.1 b/text-utils/colcrt.1
index f0eceb55..ee603e1a 100644
--- a/text-utils/colcrt.1
+++ b/text-utils/colcrt.1
@@ -107,5 +107,5 @@ The
command appeared in
.Bx 3.0 .
.Sh AVAILABILITY
-The colcrt command is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+The colcrt command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/text-utils/colrm.1 b/text-utils/colrm.1
index d02167a1..1f3d4b04 100644
--- a/text-utils/colrm.1
+++ b/text-utils/colrm.1
@@ -62,5 +62,5 @@ The
command appeared in
.Bx 3.0 .
.Sh AVAILABILITY
-The colrm command is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+The colrm command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/text-utils/column.1 b/text-utils/column.1
index e3b2b941..54ab444b 100644
--- a/text-utils/column.1
+++ b/text-utils/column.1
@@ -71,5 +71,5 @@ sed 's/#.*//' /etc/fstab | column -t
.SH HISTORY
The column command appeared in 4.3BSD-Reno.
.SH AVAILABILITY
-The column command is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+The column command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/text-utils/column.c b/text-utils/column.c
index 87a6fc79..5b52339f 100644
--- a/text-utils/column.c
+++ b/text-utils/column.c
@@ -308,8 +308,10 @@ maketbl()
for (i = lens[coloff] - t->len[coloff] + 2; i > 0; i--)
putwchar(' ');
}
- fputws(t->list[coloff], stdout);
- putwchar('\n');
+ if (coloff < t->cols) {
+ fputws(t->list[coloff], stdout);
+ putwchar('\n');
+ }
}
}
diff --git a/text-utils/hexdump.1 b/text-utils/hexdump.1
index 24cb8c39..a5e2a8c1 100644
--- a/text-utils/hexdump.1
+++ b/text-utils/hexdump.1
@@ -338,5 +338,5 @@ utility is expected to be
.St -p1003.2
compatible.
.Sh AVAILABILITY
-The hexdump command is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+The hexdump command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/text-utils/line.1 b/text-utils/line.1
index 93081ea6..1cd0aa79 100644
--- a/text-utils/line.1
+++ b/text-utils/line.1
@@ -13,5 +13,5 @@ on EOF or read error.
.SH "SEE ALSO"
.BR read (1)
.SH AVAILABILITY
-The line command is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+The line command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/text-utils/more.1 b/text-utils/more.1
index a049d135..02353aa0 100644
--- a/text-utils/more.1
+++ b/text-utils/more.1
@@ -201,5 +201,5 @@ version 5.19 (Berkeley 6/29/88), which is currently in use in the Linux
community. Documentation was produced using several other versions of the
man page, and extensive inspection of the source code.
.Sh AVAILABILITY
-The more command is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+The more command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/text-utils/more.c b/text-utils/more.c
index 20efc28d..929e4a0b 100644
--- a/text-utils/more.c
+++ b/text-utils/more.c
@@ -36,6 +36,8 @@
libcurses (and hence can be in /bin with libcurses being in /usr/lib
which may not be mounted). However, when termcap is not present curses
can still be used.
+ 2010-10-21 Davidlohr Bueso <dave@gnu.org>
+ - modified mem allocation handling for util-linux
*/
#include <stdio.h>
@@ -54,8 +56,10 @@
#include <sys/stat.h>
#include <sys/file.h>
#include <sys/wait.h>
-#include "xstrncpy.h"
+#include "strutils.h"
+
#include "nls.h"
+#include "xalloc.h"
#include "widechar.h"
#define _REGEX_RE_COMP
@@ -2015,22 +2019,14 @@ int expand (char **outbuf, char *inbuf) {
xtra = strlen (fnames[fnum]) + strlen (shell_line) + 1;
tempsz = 200 + xtra;
- temp = malloc(tempsz);
- if (!temp) {
- error (_("Out of memory"));
- return -1;
- }
+ temp = xmalloc(tempsz);
inpstr = inbuf;
outstr = temp;
while ((c = *inpstr++) != '\0'){
offset = outstr-temp;
if (tempsz-offset-1 < xtra) {
tempsz += 200 + xtra;
- temp = realloc(temp, tempsz);
- if (!temp) {
- error (_("Out of memory"));
- return -1;
- }
+ temp = xrealloc(temp, tempsz);
outstr = temp + offset;
}
switch (c) {
diff --git a/text-utils/pg.1 b/text-utils/pg.1
index b1891ca1..853e5afc 100644
--- a/text-utils/pg.1
+++ b/text-utils/pg.1
@@ -233,5 +233,5 @@ Files that include
characters cannot be displayed by
.IR pg .
.SH AVAILABILITY
-The pg command is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+The pg command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/text-utils/pg.c b/text-utils/pg.c
index 24c12217..68275238 100644
--- a/text-utils/pg.c
+++ b/text-utils/pg.c
@@ -60,6 +60,7 @@
#include <term.h>
#include "nls.h"
+#include "xalloc.h"
#include "widechar.h"
#define READBUF LINE_MAX /* size of input buffer */
@@ -213,21 +214,6 @@ quit(int status)
}
/*
- * Memory allocator including check.
- */
-static char *
-smalloc(size_t s)
-{
- char *m = (char *)malloc(s);
- if (m == NULL) {
- const char *p = _("Out of memory\n");
- write(2, p, strlen(p));
- quit(++exitstatus);
- }
- return m;
-}
-
-/*
* Usage message and similar routines.
*/
static void
@@ -549,7 +535,7 @@ endline(unsigned col, char *s)
static void
cline(void)
{
- char *buf = (char *)smalloc(ttycols + 2);
+ char *buf = xmalloc(ttycols + 2);
memset(buf, ' ', ttycols + 2);
buf[0] = '\r';
buf[ttycols + 1] = '\r';
@@ -601,7 +587,7 @@ getcount(char *cmdstr)
if (*cmdstr == '\0')
return 1;
- buf = (char *)smalloc(strlen(cmdstr) + 1);
+ buf = xmalloc(strlen(cmdstr) + 1);
strcpy(buf, cmdstr);
if (cmd.key != '\0') {
if (cmd.key == '/' || cmd.key == '?' || cmd.key == '^') {
diff --git a/text-utils/rev.1 b/text-utils/rev.1
index 6288616a..5d205c78 100644
--- a/text-utils/rev.1
+++ b/text-utils/rev.1
@@ -49,5 +49,5 @@ utility copies the specified files to the standard output, reversing the
order of characters in every line.
If no files are specified, the standard input is read.
.Sh AVAILABILITY
-The rev command is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+The rev command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/text-utils/rev.c b/text-utils/rev.c
index 907b032b..b6924497 100644
--- a/text-utils/rev.c
+++ b/text-utils/rev.c
@@ -59,6 +59,7 @@
#include <signal.h>
#include "nls.h"
+#include "xalloc.h"
#include "widechar.h"
wchar_t *buf;
@@ -66,7 +67,7 @@ wchar_t *buf;
static void sig_handler(int signo)
{
free(buf);
- exit(EXIT_SUCCESS);
+ _exit(EXIT_SUCCESS);
}
static void __attribute__((__noreturn__)) usage(FILE *out)
@@ -117,9 +118,7 @@ int main(int argc, char *argv[])
filename = *argv++;
}
- buf = malloc(bufsiz * sizeof(wchar_t));
- if (!buf)
- err(EXIT_FAILURE, _("malloc failed"));
+ buf = xmalloc(bufsiz * sizeof(wchar_t));
while (fgetws(buf, bufsiz, fp)) {
len = wcslen(buf);
diff --git a/text-utils/tailf.1 b/text-utils/tailf.1
index 294d9d6a..92e63e56 100644
--- a/text-utils/tailf.1
+++ b/text-utils/tailf.1
@@ -57,5 +57,5 @@ The latest inotify based implementation was written by Karel Zak (kzak@redhat.co
.SH "SEE ALSO"
.BR tail "(1), " less "(1)"
.SH AVAILABILITY
-The tailf command is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+The tailf command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/text-utils/tailf.c b/text-utils/tailf.c
index dc18b2a6..2dcdba3f 100644
--- a/text-utils/tailf.c
+++ b/text-utils/tailf.c
@@ -29,7 +29,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-#include <malloc.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -40,7 +39,9 @@
#ifdef HAVE_INOTIFY_INIT
#include <sys/inotify.h>
#endif
+
#include "nls.h"
+#include "xalloc.h"
#include "usleep.h"
#define DEFAULT_LINES 10
@@ -57,7 +58,7 @@ tailf(const char *filename, int lines)
if (!(str = fopen(filename, "r")))
err(EXIT_FAILURE, _("cannot open \"%s\" for read"), filename);
- buf = malloc(lines * BUFSIZ);
+ buf = xmalloc(lines * BUFSIZ);
p = buf;
while (fgets(p, BUFSIZ, str)) {
if (++tail >= lines) {
diff --git a/text-utils/ul.1 b/text-utils/ul.1
index cec6940e..7d4e57ab 100644
--- a/text-utils/ul.1
+++ b/text-utils/ul.1
@@ -106,5 +106,5 @@ The
command appeared in
.Bx 3.0 .
.Sh AVAILABILITY
-The ul command is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+The ul command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/text-utils/ul.c b/text-utils/ul.c
index 4601e3c7..30f24e9d 100644
--- a/text-utils/ul.c
+++ b/text-utils/ul.c
@@ -49,8 +49,9 @@
#include <signal.h> /* for signal() */
#include <err.h>
#include <errno.h>
-#include "nls.h"
+#include "nls.h"
+#include "xalloc.h"
#include "widechar.h"
#ifdef HAVE_WIDECHAR
@@ -78,7 +79,6 @@ void outc(wint_t c, int width);
void setmode(int newmode);
static void setcol(int newcol);
static void needcol(int col);
-static void exitbuf(void);
static void sig_handler(int signo);
#define IESC '\033'
@@ -169,7 +169,6 @@ int main(int argc, char **argv)
if ( (tigetflag("os") && ENTER_BOLD==NULL ) ||
(tigetflag("ul") && ENTER_UNDERLINE==NULL && UNDER_CHAR==NULL))
must_overstrike = 1;
- atexit(exitbuf);
initbuf();
if (optind == argc)
filter(stdin);
@@ -428,9 +427,7 @@ void initbuf(void)
{
if (obuf == NULL) { /* First time. */
obuflen = INITBUF;
- obuf = malloc(sizeof(struct CHAR) * obuflen);
- if (obuf == NULL)
- err(EXIT_FAILURE, _("unable to allocate buffer"));
+ obuf = xmalloc(sizeof(struct CHAR) * obuflen);
}
/* assumes NORMAL == 0 */
@@ -596,19 +593,12 @@ needcol(int col) {
: obuflen * 2;
/* Now we can try to expand obuf. */
- obuf = realloc(obuf, sizeof(struct CHAR) * obuflen);
- if (obuf == NULL)
- err(EXIT_FAILURE, _("growing buffer failed"));
+ obuf = xrealloc(obuf, sizeof(struct CHAR) * obuflen);
}
}
static void sig_handler(int signo)
{
- exit(EXIT_SUCCESS);
+ _exit(EXIT_SUCCESS);
}
-static void exitbuf(void)
-{
- free(obuf);
- obuf = NULL;
-}