summaryrefslogtreecommitdiffstats
path: root/misc-utils/getopt.c
diff options
context:
space:
mode:
authorRuediger Meier2016-03-07 11:44:55 +0100
committerRuediger Meier2016-03-07 23:36:46 +0100
commit5c78d493c05d03b119f1d1c76874ac31f909655a (patch)
tree0173bf1ba3205b7aa076cac106477dcc7902a026 /misc-utils/getopt.c
parenttests: improve getopt loop error case (diff)
downloadkernel-qcow2-util-linux-5c78d493c05d03b119f1d1c76874ac31f909655a.tar.gz
kernel-qcow2-util-linux-5c78d493c05d03b119f1d1c76874ac31f909655a.tar.xz
kernel-qcow2-util-linux-5c78d493c05d03b119f1d1c76874ac31f909655a.zip
getopt: fix -n name for BSD
BSD gets the program name for warnings from getprogname() and not from argv. Thus we use setprogname() there. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Diffstat (limited to 'misc-utils/getopt.c')
-rw-r--r--misc-utils/getopt.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/misc-utils/getopt.c b/misc-utils/getopt.c
index c166fd756..c4144f63e 100644
--- a/misc-utils/getopt.c
+++ b/misc-utils/getopt.c
@@ -62,6 +62,9 @@
#include <unistd.h>
#include <ctype.h>
#include <getopt.h>
+#ifdef HAVE_SYS_PARAM_H
+# include <sys/param.h> /* BSD */
+#endif
#include "closestream.h"
#include "nls.h"
@@ -447,9 +450,13 @@ int main(int argc, char *argv[])
optind++;
}
}
- if (name)
+
+ if (name) {
argv[optind - 1] = name;
- else
+#if defined (BSD) || defined (__APPLE__)
+ setprogname(name);
+#endif
+ } else
argv[optind - 1] = argv[0];
return generate_output(&ctl, argv + optind - 1, argc - optind + 1);