1 /* $OpenBSD: getoldopt.c,v 1.9 2009/10/27 23:59:22 deraadt Exp $ */
2 /* $NetBSD: getoldopt.c,v 1.3 1995/03/21 09:07:28 cgd Exp $ */
5 * Plug-compatible replacement for getopt() for parsing tar-like
6 * arguments. If the first argument begins with "-", it uses getopt;
7 * otherwise, it uses the old rules used by tar, dump, and ps.
9 * Written 25 August 1985 by John Gilmore (ihnp4!hoptoad!gnu) and placed
10 * in the Public Domain for your edification and enjoyment.
13 #include <sys/cdefs.h>
14 __FBSDID("$FreeBSD$");
16 #include <sys/types.h>
22 int getoldopt(int, char **, const char *);
25 getoldopt(int argc, char **argv, const char *optstring)
27 static char *key; /* Points to next keyletter */
28 static char use_getopt; /* !=0 if argv[1][0] was '-' */
34 if (key == NULL) { /* First time */
45 return (getopt(argc, argv, optstring));
52 place = strchr(optstring, c);
54 if (place == NULL || c == ':') {
55 fprintf(stderr, "%s: unknown option %c\n", argv[0], c);
62 optarg = argv[optind];
65 fprintf(stderr, "%s: %c argument missing\n",