Re: [PATCH] look: fix conflict between locally defined err() and glibc's version

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I didn't realize that the local version of err() was exiting as well.
Please consider this version of the patch.

>From 9ff41b4536ed67902ae76932a4ec8756dd06554b Mon Sep 17 00:00:00 2001
From: Davidlohr Bueso <dave@xxxxxxx>
Date: Fri, 15 Oct 2010 14:21:51 -0300
Subject: [PATCH 4/4] look: fix conflict between locally defined err() and glibc's version

Signed-off-by: Davidlohr Bueso <dave@xxxxxxx>
---
 misc-utils/look.c |   53 ++++++++++++++---------------------------------------
 1 files changed, 14 insertions(+), 39 deletions(-)

diff --git a/misc-utils/look.c b/misc-utils/look.c
index 54fbb91..1037239 100644
--- a/misc-utils/look.c
+++ b/misc-utils/look.c
@@ -59,8 +59,15 @@
 #include <strings.h>
 #include <ctype.h>
 #include <getopt.h>
-#include "pathnames.h"
+#if __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+
 #include "nls.h"
+#include "xalloc.h"
+#include "pathnames.h"
 
 #define	EQUAL		0
 #define	GREATER		1
@@ -75,7 +82,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 *);
@@ -136,7 +142,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 +150,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@xxxxxxxxxxxx) */
@@ -177,9 +183,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 +300,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 +358,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 */
-}
-- 
1.7.0.4



--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux