1 /* $OpenBSD: getoldopt.c,v 1.4 2000/01/22 20:24:51 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 Pubic Domain for your edification and enjoyment.
12 * $FreeBSD: src/bin/pax/getoldopt.c,v 1.1.2.1 2001/08/01 05:03:11 obrien Exp $
13 * $DragonFly: src/bin/pax/getoldopt.c,v 1.3 2003/09/28 14:39:14 hmp Exp $
21 getoldopt(int argc, char **argv, char *optstring)
23 static char *key; /* Points to next keyletter */
24 static char use_getopt; /* !=0 if argv[1][0] was '-' */
30 if (key == NULL) { /* First time */
31 if (argc < 2) return EOF;
40 return getopt(argc, argv, optstring);
47 place = strchr(optstring, c);
49 if (place == NULL || c == ':') {
50 fprintf(stderr, "%s: unknown option %c\n", argv[0], c);
57 optarg = argv[optind];
60 fprintf(stderr, "%s: %c argument missing\n",