Define USED_FOR_TARGET in tconfig.h, matching what gcc does.
[dragonfly.git] / bin / pax / getoldopt.c
blob1cc4df59b9354809b28cc520e61ea7a6b344912f
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 $ */
4 /*
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 $
16 #include <stdio.h>
17 #include <string.h>
18 #include <unistd.h>
20 int
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 '-' */
25 char c;
26 char *place;
28 optarg = NULL;
30 if (key == NULL) { /* First time */
31 if (argc < 2) return EOF;
32 key = argv[1];
33 if (*key == '-')
34 use_getopt++;
35 else
36 optind = 2;
39 if (use_getopt)
40 return getopt(argc, argv, optstring);
42 c = *key++;
43 if (c == '\0') {
44 key--;
45 return EOF;
47 place = strchr(optstring, c);
49 if (place == NULL || c == ':') {
50 fprintf(stderr, "%s: unknown option %c\n", argv[0], c);
51 return('?');
54 place++;
55 if (*place == ':') {
56 if (optind < argc) {
57 optarg = argv[optind];
58 optind++;
59 } else {
60 fprintf(stderr, "%s: %c argument missing\n",
61 argv[0], c);
62 return('?');
66 return(c);