From: Davidlohr Bueso Date: Fri, 15 Oct 2010 17:23:16 +0000 (-0300) Subject: look: fix conflict between locally defined err() and glibc's version X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=026ed2cedd6e5d0dbbc32d097d6104107970419f;p=util-linux look: fix conflict between locally defined err() and glibc's version Signed-off-by: Davidlohr Bueso Signed-off-by: Karel Zak --- diff --git a/misc-utils/look.c b/misc-utils/look.c index 54fbb918..85a8cc1b 100644 --- a/misc-utils/look.c +++ b/misc-utils/look.c @@ -59,8 +59,10 @@ #include #include #include -#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 -#else -#include -#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 */ -}