summaryrefslogtreecommitdiffstats
path: root/misc-utils/look.c
diff options
context:
space:
mode:
authorDavidlohr Bueso2010-10-15 19:23:16 +0200
committerKarel Zak2010-10-21 10:37:57 +0200
commit026ed2cedd6e5d0dbbc32d097d6104107970419f (patch)
treed11fdc558cf148f90743da782d21a73055fd4622 /misc-utils/look.c
parentmisc-utils: use new xmalloc() wrapper (diff)
downloadkernel-qcow2-util-linux-026ed2cedd6e5d0dbbc32d097d6104107970419f.tar.gz
kernel-qcow2-util-linux-026ed2cedd6e5d0dbbc32d097d6104107970419f.tar.xz
kernel-qcow2-util-linux-026ed2cedd6e5d0dbbc32d097d6104107970419f.zip
look: fix conflict between locally defined err() and glibc's version
Signed-off-by: Davidlohr Bueso <dave@gnu.org> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils/look.c')
-rw-r--r--misc-utils/look.c50
1 files changed, 10 insertions, 40 deletions
diff --git a/misc-utils/look.c b/misc-utils/look.c
index 54fbb9183..85a8cc1b2 100644
--- a/misc-utils/look.c
+++ b/misc-utils/look.c
@@ -59,8 +59,10 @@
#include <strings.h>
#include <ctype.h>
#include <getopt.h>
-#include "pathnames.h"
+
#include "nls.h"
+#include "xalloc.h"
+#include "pathnames.h"
#define EQUAL 0
#define GREATER 1
@@ -75,7 +77,6 @@ char *comparbuf;
static char *binary_search (char *, char *);
static int compare (char *, char *);
-static void err (const char *fmt, ...);
static char *linear_search (char *, char *);
static int look (char *, char *);
static void print_from (char *, char *);
@@ -101,7 +102,7 @@ main(int argc, char *argv[])
while ((ch = getopt(argc, argv, "adft:")) != -1)
switch(ch) {
case 'a':
- file = _PATH_WORDS_ALT;
+ file = _PATH_WORDS_ALT;
break;
case 'd':
dflag = 1;
@@ -136,7 +137,7 @@ main(int argc, char *argv[])
*++p = '\0';
if ((fd = open(file, O_RDONLY, 0)) < 0 || fstat(fd, &sb))
- err("%s: %s", file, strerror(errno));
+ err(EXIT_FAILURE, "%s", file);
front = mmap(NULL, (size_t) sb.st_size, PROT_READ,
#ifdef MAP_FILE
MAP_FILE |
@@ -144,11 +145,11 @@ main(int argc, char *argv[])
MAP_SHARED, fd, (off_t) 0);
if
#ifdef MAP_FAILED
- (front == MAP_FAILED)
+ (front == MAP_FAILED)
#else
- ((void *)(front) <= (void *)0)
+ ((void *)(front) <= (void *)0)
#endif
- err("%s: %s", file, strerror(errno));
+ err(EXIT_FAILURE, "%s", file);
#if 0
/* workaround for mmap problem (rmiller@duskglow.com) */
@@ -177,9 +178,7 @@ look(char *front, char *back)
} else
stringlen = strlen(string);
- comparbuf = malloc(stringlen+1);
- if (comparbuf == NULL)
- err(_("Out of memory"));
+ comparbuf = xmalloc(stringlen+1);
front = binary_search(front, back);
front = linear_search(front, back);
@@ -296,7 +295,7 @@ print_from(char *front, char *back)
eol = 0;
while (front < back && !eol) {
if (putchar(*front) == EOF)
- err("stdout: %s", strerror(errno));
+ err(EXIT_FAILURE, "stdout");
if (*front++ == '\n')
eol = 1;
}
@@ -354,32 +353,3 @@ usage()
(void)fprintf(stderr, _("usage: look [-dfa] [-t char] string [file]\n"));
exit(2);
}
-
-#if __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
-void
-#if __STDC__
-err(const char *fmt, ...)
-#else
-err(fmt, va_alist)
- char *fmt;
- va_dcl
-#endif
-{
- va_list ap;
-#if __STDC__
- va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
- (void)fprintf(stderr, "look: ");
- (void)vfprintf(stderr, fmt, ap);
- va_end(ap);
- (void)fprintf(stderr, "\n");
- exit(2);
- /* NOTREACHED */
-}