summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorotto <otto@openbsd.org>2006-02-01 09:27:28 +0000
committerotto <otto@openbsd.org>2006-02-01 09:27:28 +0000
commit6a87d5f5e14371bd8b2882c7c64dbc3f5bba4b8e (patch)
tree69124fdbd14a06a0f9eedf8a8721e9f44d561b47
parentsave errno, from Ray Lai in PR 4999. (diff)
downloadwireguard-openbsd-6a87d5f5e14371bd8b2882c7c64dbc3f5bba4b8e.tar.xz
wireguard-openbsd-6a87d5f5e14371bd8b2882c7c64dbc3f5bba4b8e.zip
Actually working example, from Ray Lai in PR 5000; with a twist (also
fix usage()) from me.
-rw-r--r--share/misc/getopt26
1 files changed, 18 insertions, 8 deletions
diff --git a/share/misc/getopt b/share/misc/getopt
index 1ae9cbf3249..45c61ad9f34 100644
--- a/share/misc/getopt
+++ b/share/misc/getopt
@@ -1,30 +1,40 @@
-/* $OpenBSD: getopt,v 1.7 2002/07/22 20:13:14 pvalchev Exp $ */
+/* $OpenBSD: getopt,v 1.8 2006/02/01 09:27:28 otto Exp $ */
/*
* Main/getopt(3) fragment.
*
* from: @(#)getopt 5.3 (Berkeley) 3/28/94
*/
-#include <sys/types.h>
+#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
-void usage(void);
+__dead void usage(void);
int
main(int argc, char *argv[])
{
- int ch;
+ int bflag, ch;
+ char *file;
- while ((ch = getopt(argc, argv, "abcf:")) != -1)
+ bflag = 0;
+ file = NULL;
+ while ((ch = getopt(argc, argv, "bf:")) != -1)
switch (ch) {
- case '':
+ case 'b':
+ bflag = 1;
+ break;
+ case 'f':
+ file = optarg;
break;
- case '?':
default:
usage();
+ /* NOTREACHED */
}
argc -= optind;
argv += optind;
+
+ return (0);
}
void
@@ -32,6 +42,6 @@ usage(void)
{
extern char *__progname;
- (void)fprintf(stderr, "usage: %s [-abc] [-f file]\n", __progname);
+ (void)fprintf(stderr, "usage: %s [-b] [-f file]\n", __progname);
exit(1);
}