[patch] tcpdump: simplify warning(), error()

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[patch] tcpdump: simplify warning(), error()

Alexey Dobriyan-2
Both functions will not attach \n to the error message if caller did
it itself in format string. Since only one error() call is using this
feature, shrink tcpdump by 8 lines.

Index: usr.sbin/tcpdump/tcpdump.c
===================================================================
RCS file: /cvs/src/usr.sbin/tcpdump/tcpdump.c,v
retrieving revision 1.49
diff -u -p -r1.49 tcpdump.c
--- usr.sbin/tcpdump/tcpdump.c 2006/02/15 20:34:23 1.49
+++ usr.sbin/tcpdump/tcpdump.c 2006/03/12 13:11:33
@@ -195,7 +195,7 @@ pcap_list_linktypes(pcap_t *p)
  err(1, "BIOCGDLTLIST");
 
  if (dl.bfl_len > MAXDLT)
- error("Invalid number of linktypes: %u\n", dl.bfl_len);
+ error("Invalid number of linktypes: %u", dl.bfl_len);
 
  fprintf(stderr, "%d link type%s supported:\n", dl.bfl_len,
     dl.bfl_len == 1 ? "" : "s");
Index: usr.sbin/tcpdump/util.c
===================================================================
RCS file: /cvs/src/usr.sbin/tcpdump/util.c,v
retrieving revision 1.19
diff -u -p -r1.19 util.c
--- usr.sbin/tcpdump/util.c 2005/03/07 16:13:38 1.19
+++ usr.sbin/tcpdump/util.c 2006/03/12 13:11:33
@@ -217,11 +217,7 @@ error(const char *fmt, ...)
  va_start(ap, fmt);
  (void)vfprintf(stderr, fmt, ap);
  va_end(ap);
- if (*fmt) {
- fmt += strlen(fmt);
- if (fmt[-1] != '\n')
- (void)fputc('\n', stderr);
- }
+ (void)fputc('\n', stderr);
  exit(1);
  /* NOTREACHED */
 }
@@ -236,11 +232,7 @@ warning(const char *fmt, ...)
  va_start(ap, fmt);
  (void)vfprintf(stderr, fmt, ap);
  va_end(ap);
- if (*fmt) {
- fmt += strlen(fmt);
- if (fmt[-1] != '\n')
- (void)fputc('\n', stderr);
- }
+ (void)fputc('\n', stderr);
 }