3 * Copyright 1998-2002 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>
29 #define STDERR_FILENO 2
38 extern int _trans_argv;
41 static void ERR (char * const argv[], const char * s, char c)
44 printf("DF_TRACE_DEBUG: static void ERR () in getopt.c\n");
48 char *ptr, outbuf[4096];
50 ptr = lutil_strncopy(outbuf, argv[0], sizeof(outbuf) - 2);
51 ptr = lutil_strncopy(ptr, s, sizeof(outbuf)-2 -(ptr-outbuf));
55 __atoe_l(outbuf, ptr - outbuf);
57 (void) write(STDERR_FILENO,outbuf,ptr - outbuf);
61 int getopt (int argc, char * const argv [], const char * opts)
63 static int sp = 1, error = (int) '?';
64 static char sw = '-', eos = '\0', arg = ':';
65 register char c, * cp;
68 printf("DF_TRACE_DEBUG: int getopt () in getopt.c\n");
74 for (i=0; i<argc; i++) __etoa(argv[i]);
80 if (optind >= argc || argv[optind][0] != sw
81 || argv[optind][1] == eos)
83 else if (strcmp(argv[optind],"--") == 0)
91 if (c == arg || (cp = strchr(opts,c)) == NULL)
93 ERR(argv,": illegal option--",c);
94 if (argv[optind][++sp] == eos)
101 else if (*++cp == arg)
103 if (argv[optind][sp + 1] != eos)
104 optarg = &argv[optind++][sp + 1];
105 else if (++optind >= argc)
107 ERR(argv,": option requires an argument--",c);
112 optarg = argv[optind++];
117 if (argv[optind][++sp] == eos)
126 #endif /* HAVE_GETOPT */