]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
pg: use xalloc for memory allocation
authorDavidlohr Bueso <dave@gnu.org>
Fri, 22 Oct 2010 15:22:09 +0000 (12:22 -0300)
committerKarel Zak <kzak@redhat.com>
Mon, 1 Nov 2010 13:03:08 +0000 (14:03 +0100)
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
text-utils/pg.c

index 24c1221773ef10eea054d5b8cf6e0672ced623e2..68275238f69e2785cc31a0c95f7dfb1cba66ee11 100644 (file)
@@ -60,6 +60,7 @@
 #include <term.h>
 
 #include "nls.h"
+#include "xalloc.h"
 #include "widechar.h"
 
 #define        READBUF         LINE_MAX        /* size of input buffer */
@@ -212,21 +213,6 @@ quit(int status)
        exit(status < 0100 ? status : 077);
 }
 
-/*
- * 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.
  */
@@ -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 == '^') {