3 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
9 modified public-domain AT&T getopt(3)
10 modified by Kurt Zeilenga for inclusion into OpenLDAP
19 #include <ac/string.h>
20 #include <ac/unistd.h>
27 #define STDERR_FILENO 2
35 static void ERR (char * const argv[], const char * s, char c)
40 printf("DF_TRACE_DEBUG: static void ERR () in getopt.c\n");
46 (void) write(STDERR_FILENO,argv[0],strlen(argv[0]));
47 (void) write(STDERR_FILENO,s,strlen(s));
48 (void) write(STDERR_FILENO,errbuf,sizeof errbuf);
52 int getopt (int argc, char * const argv [], const char * opts)
54 static int sp = 1, error = (int) '?';
55 static char sw = '-', eos = '\0', arg = ':';
56 register char c, * cp;
59 printf("DF_TRACE_DEBUG: int getopt () in getopt.c\n");
63 if (optind >= argc || argv[optind][0] != sw
64 || argv[optind][1] == eos)
66 else if (strcmp(argv[optind],"--") == 0)
74 if (c == arg || (cp = strchr(opts,c)) == NULL)
76 ERR(argv,": illegal option--",c);
77 if (argv[optind][++sp] == eos)
84 else if (*++cp == arg)
86 if (argv[optind][sp + 1] != eos)
87 optarg = &argv[optind++][sp + 1];
88 else if (++optind >= argc)
90 ERR(argv,": option requires an argument--",c);
95 optarg = argv[optind++];
100 if (argv[optind][++sp] == eos)
109 #endif /* HAVE_GETOPT */