Annotation of src/usr.bin/getopt/getopt.c, Revision 1.9
1.9 ! deraadt 1: /* $OpenBSD: getopt.c,v 1.8 2009/10/27 23:59:38 deraadt Exp $ */
1.7 jmc 2:
3: /*
4: * This material, written by Henry Spencer, was released by him
5: * into the public domain and is thus not subject to any copyright.
6: */
1.1 deraadt 7:
8: #include <stdio.h>
1.6 david 9: #include <stdlib.h>
1.4 deraadt 10: #include <unistd.h>
1.9 ! deraadt 11: #include <err.h>
1.1 deraadt 12:
1.4 deraadt 13: int
1.5 deraadt 14: main(int argc, char *argv[])
1.1 deraadt 15: {
16: extern int optind;
17: extern char *optarg;
18: int c;
19: int status = 0;
1.9 ! deraadt 20:
! 21: if (tame("stdio", NULL) == -1)
! 22: err(1, "tame");
1.1 deraadt 23:
24: optind = 2; /* Past the program name and the option letters. */
1.3 millert 25: while ((c = getopt(argc, argv, argv[1])) != -1)
1.1 deraadt 26: switch (c) {
27: case '?':
28: status = 1; /* getopt routine gave message */
29: break;
30: default:
31: if (optarg != NULL)
32: printf(" -%c %s", c, optarg);
33: else
34: printf(" -%c", c);
35: break;
36: }
37: printf(" --");
38: for (; optind < argc; optind++)
39: printf(" %s", argv[optind]);
40: printf("\n");
41: exit(status);
42: }