3 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
8 * modified public-domain AT&T getopt(3)
9 * modified by Kurt Zeilenga for inclusion into OpenLDAP
18 #include <ac/string.h>
19 #include <ac/unistd.h>
28 #define STDERR_FILENO 2
37 extern int _trans_argv;
40 static void ERR (char * const argv[], const char * s, char c)
43 printf("DF_TRACE_DEBUG: static void ERR () in getopt.c\n");
47 char *ptr, outbuf[4096];
49 ptr = lutil_strncopy(outbuf, argv[0], sizeof(outbuf) - 2);
50 ptr = lutil_strncopy(ptr, s, sizeof(outbuf)-2 -(ptr-outbuf));
54 __atoe_l(outbuf, ptr - outbuf);
56 (void) write(STDERR_FILENO,outbuf,ptr - outbuf);
60 int getopt (int argc, char * const argv [], const char * opts)
62 static int sp = 1, error = (int) '?';
63 static char sw = '-', eos = '\0', arg = ':';
64 register char c, * cp;
67 printf("DF_TRACE_DEBUG: int getopt () in getopt.c\n");
73 for (i=0; i<argc; i++) __etoa(argv[i]);
79 if (optind >= argc || argv[optind][0] != sw
80 || argv[optind][1] == eos)
82 else if (strcmp(argv[optind],"--") == 0)
90 if (c == arg || (cp = strchr(opts,c)) == NULL)
92 ERR(argv,_(": illegal option--"),c);
93 if (argv[optind][++sp] == eos)
100 else if (*++cp == arg)
102 if (argv[optind][sp + 1] != eos)
103 optarg = &argv[optind++][sp + 1];
104 else if (++optind >= argc)
106 ERR(argv,_(": option requires an argument--"),c);
111 optarg = argv[optind++];
116 if (argv[optind][++sp] == eos)
125 #endif /* HAVE_GETOPT */