aboutsummaryrefslogtreecommitdiff
path: root/missing/getopt.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2015-11-01 17:33:02 -0800
committerGuy Harris <guy@alum.mit.edu>2015-11-01 17:33:02 -0800
commit9345447aca0518ef74936db729dc94c58f1ce46f (patch)
treebf212b087073309ec9d43fe0eff3d7ca81a92f95 /missing/getopt.c
parenta77491e209e49a16cda89508e86cf71c04d6a2c4 (diff)
Extract progname from argv[0].
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.
Diffstat (limited to 'missing/getopt.c')
-rw-r--r--missing/getopt.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/missing/getopt.c b/missing/getopt.c
index f5e62daa..14cd6a32 100644
--- a/missing/getopt.c
+++ b/missing/getopt.c
@@ -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]) != '-') {