]> The Tcpdump Group git mirrors - libpcap/commitdiff
Extract progname from argv[0].
authorGuy Harris <[email protected]>
Mon, 2 Nov 2015 01:33:02 +0000 (17:33 -0800)
committerGuy Harris <[email protected]>
Mon, 2 Nov 2015 01:33:02 +0000 (17:33 -0800)
On UN*X, __progname is a BSD-specific variable, so don't rely on it
being defined by the system.

On Windows, don't hardwire "windump" as the program name.

missing/getopt.c

index f5e62daa4cccf380ae1b1e06f3d96cb5b0b653c1..14cd6a328652d99797714936e313a5a47ebab1d4 100644 (file)
@@ -59,14 +59,17 @@ getopt(nargc, nargv, ostr)
        char * const *nargv;
        const char *ostr;
 {
-#ifdef _WIN32
-       char *__progname="windump";
-#else
-       extern char *__progname;
-#endif
+       char *cp;
+       static char *__progname;
        static char *place = EMSG;              /* option letter processing */
        char *oli;                              /* option letter list index */
 
+       if (__progname == NULL) {
+               if ((cp = strrchr(nargv[0], '/')) != NULL)
+                       __progname = cp + 1;
+               else
+                       __progname = nargv[0];
+       }
        if (optreset || !*place) {              /* update scanning pointer */
                optreset = 0;
                if (optind >= nargc || *(place = nargv[optind]) != '-') {