summaryrefslogtreecommitdiffstats
path: root/text-utils/col.c
diff options
context:
space:
mode:
authorDavidlohr Bueso2010-10-22 17:24:37 +0200
committerKarel Zak2010-11-01 14:32:48 +0100
commit04faca4a1325fe21b90b761e5d3ef37c4a267ecc (patch)
tree67f1edf1ab7c20c0d18da136ba0a9722c36b54ce /text-utils/col.c
parenttailf: use xalloc for memory allocation (diff)
downloadkernel-qcow2-util-linux-04faca4a1325fe21b90b761e5d3ef37c4a267ecc.tar.gz
kernel-qcow2-util-linux-04faca4a1325fe21b90b761e5d3ef37c4a267ecc.tar.xz
kernel-qcow2-util-linux-04faca4a1325fe21b90b761e5d3ef37c4a267ecc.zip
col: use xalloc for memory allocation
Differentiate between malloc and realloc (not done so far) and get rid of local warn() Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Diffstat (limited to 'text-utils/col.c')
-rw-r--r--text-utils/col.c38
1 files changed, 11 insertions, 27 deletions
diff --git a/text-utils/col.c b/text-utils/col.c
index 3b81a891a..580a84c75 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 */
@@ -94,12 +95,10 @@ struct line_str {
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 */
@@ -275,7 +274,9 @@ int main(int argc, char **argv)
}
} else {
if (!warned++)
- warn(cur_line);
+ fprintf(stderr,
+ _("col: warning: can't back up %s.\n"), cur_line < 0 ?
+ _("past first line") : _("-- line already flushed"));
cur_line -= nmove;
}
}
@@ -302,8 +303,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++];
@@ -415,12 +416,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 +511,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,16 +530,6 @@ 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"));
@@ -550,10 +541,3 @@ 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"));
-}