]> The Tcpdump Group git mirrors - libpcap/commitdiff
Add a "getopt.h" header and include it instead of <unistd.h> on Windows.
authorGuy Harris <[email protected]>
Mon, 2 Nov 2015 00:24:47 +0000 (16:24 -0800)
committerGuy Harris <[email protected]>
Mon, 2 Nov 2015 00:25:30 +0000 (16:25 -0800)
We include <unistd.h> for getopt(), but, on Windows, we supply our own
getopt() (as it's a UN*X API), so supply our own header and include that
instead.

While we're at it, mark the copyright strings as unused (to squelch
compiler warnings), and don't include the headers for select() or poll()
in capturetest.c, as we don't use those APIs there (that's what
selpolltest(), which is UN*X-only, is for).  <unistd.h> or "getopt.h"
should declare the getopt() external variables, so don't declare them
ourselves.

Makefile.in
missing/getopt.h [new file with mode: 0644]
tests/can_set_rfmon_test.c
tests/capturetest.c
tests/filtertest.c
tests/opentest.c
tests/reactivatetest.c
tests/selpolltest.c
tests/valgrindtest.c

index 747a66af773ddccec5b0a9e477d4e36e8b33b8a7..1e7261f6dd23dad6ea519ec7a21917ce91136dc4 100644 (file)
@@ -278,6 +278,7 @@ EXTRA_DIST = \
        lbl/os-sunos4.h \
        lbl/os-ultrix4.h \
        missing/getopt.c \
+       missing/getopt.h \
        missing/snprintf.c \
        mkdep \
        msdos/bin2c.c \
diff --git a/missing/getopt.h b/missing/getopt.h
new file mode 100644 (file)
index 0000000..d176345
--- /dev/null
@@ -0,0 +1,7 @@
+/*
+ * Header for the getopt() we supply if the platform doesn't supply it.
+ */
+extern char *optarg;                   /* getopt(3) external variables */
+extern int optind, opterr, optopt;
+
+extern int getopt(int nargc, char * const *nargv, const char *ostr);
index aa4c1d40bb1d62ca7e009c44ba5d07cfb36adf79..f1644e66b7684991f5cee8bda674031b05e0ca0b 100644 (file)
@@ -20,7 +20,7 @@
  */
 
 #ifndef lint
-static const char copyright[] =
+static const char copyright[] _U_ =
     "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
 The Regents of the University of California.  All rights reserved.\n";
 #endif
index 1f217183ee044ce1b788f7f9449e9a6a408f0894..f786f09254293163e9d6876eed163a56f7c9cd5c 100644 (file)
@@ -20,7 +20,7 @@
  */
 
 #ifndef lint
-static const char copyright[] =
+static const char copyright[] _U_ =
     "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
 The Regents of the University of California.  All rights reserved.\n";
 #endif
@@ -30,15 +30,13 @@ The Regents of the University of California.  All rights reserved.\n";
 #include <string.h>
 #include <stdarg.h>
 #include <limits.h>
-#ifndef _WIN32
+#ifdef _WIN32
+#include "getopt.h"
+#else
 #include <unistd.h>
 #endif
 #include <errno.h>
 #include <sys/types.h>
-#ifndef _WIN32
-#include <sys/select.h>
-#include <poll.h>
-#endif
 
 #include <pcap.h>
 
@@ -61,10 +59,6 @@ static char *copy_argv(char **);
 
 static pcap_t *pd;
 
-extern int optind;
-extern int opterr;
-extern char *optarg;
-
 int
 main(int argc, char **argv)
 {
index 60709c781c6f8ab7a71d70cef2d8ae607daebb68..5f1b9be3baef2e0adecb4358b1e46ee7ec366097 100644 (file)
@@ -34,7 +34,9 @@ The Regents of the University of California.  All rights reserved.\n";
 #include <stdlib.h>
 #include <string.h>
 #include <stdarg.h>
-#ifndef _WIN32
+#ifdef _WIN32
+#include "getopt.h"
+#else
 #include <unistd.h>
 #endif
 #include <fcntl.h>
@@ -61,9 +63,6 @@ static void error(const char *, ...)
 static void warn(const char *, ...)
     __attribute__((format (printf, 1, 2)));
 
-extern int optind;
-extern int opterr;
-extern char *optarg;
 #ifdef BDEBUG
 int dflag;
 #endif
index 0c91531018dbacfdfd141465f21adfd2ca93637c..60dcf0d19df070f7a2043a6a749d6141d73eb6ed 100644 (file)
@@ -20,7 +20,7 @@
  */
 
 #ifndef lint
-static const char copyright[] =
+static const char copyright[] _U_ =
     "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
 The Regents of the University of California.  All rights reserved.\n";
 #endif
@@ -30,7 +30,11 @@ The Regents of the University of California.  All rights reserved.\n";
 #include <stdlib.h>
 #include <string.h>
 #include <stdarg.h>
+#ifdef _WIN32
+#include "getopt.h"
+#else
 #include <unistd.h>
+#endif
 #include <errno.h>
 
 #define MAXIMUM_SNAPLEN                65535
@@ -42,10 +46,6 @@ static void usage(void) __attribute__((noreturn));
 static void error(const char *, ...);
 static void warning(const char *, ...);
 
-extern int optind;
-extern int opterr;
-extern char *optarg;
-
 int
 main(int argc, char **argv)
 {
index 9031a64a619e7bc12957b51e6187a8a34bd98683..2e1b7b67adb75e779a03fcef6aa3d3123c0d1fca 100644 (file)
@@ -20,7 +20,7 @@
  */
 
 #ifndef lint
-static const char copyright[] =
+static const char copyright[] _U_ =
     "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
 The Regents of the University of California.  All rights reserved.\n";
 #endif
index 7e35845ee8ce72b7aa8998773628fcf814892371..bba1ff5cf1b6af58d5523e32cb3dcf4a3270ac86 100644 (file)
@@ -20,7 +20,7 @@
  */
 
 #ifndef lint
-static const char copyright[] =
+static const char copyright[] _U_ =
     "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
 The Regents of the University of California.  All rights reserved.\n";
 #endif
@@ -55,10 +55,6 @@ static char *copy_argv(char **);
 
 static pcap_t *pd;
 
-extern int optind;
-extern int opterr;
-extern char *optarg;
-
 int
 main(int argc, char **argv)
 {
index 72786e41ae6897f952ff43d3b05086a20df4ffc1..c825952e0b0006a0e266480fe60d0ff77a52c9d2 100644 (file)
@@ -85,10 +85,6 @@ static void error(const char *, ...)
 static void warning(const char *, ...)
     __attribute__((format (printf, 1, 2)));
 
-extern int optind;
-extern int opterr;
-extern char *optarg;
-
 /*
  * On Windows, we need to open the file in binary mode, so that
  * we get all the bytes specified by the size we get from "fstat()".