openldap/libraries/liblutil/getopt.c
Kurt Zeilenga 3ab8c58335 Mongo patch: changes from -devel from 981105 snap to present
Changed LDBM default to sync on writes
    Added mail500 BOUNCEFROM patch
    Added dbcachenowsync option
    Fixed slapd/ldbm id2children bug
    Fixed slapd/shell newline bug
    Fixed whois++ get_dn leak
    Fixed DEC OSF1 (alpha) support
    Fixed r/w lock initialization on non-final Pthreads
    Fixed slapd/slurpd file unlock bugs
    Fixed slurpd string translation bug
    Fixed slurpd/st mutex unlock bug
    Moved detach() to -llutil
    Added lutil_passwd() to -llutil
    Autoconf:
        Fixed thread detection
        Removed gcc -traditional tests
        Changed --enable-dns to require --enable-referrals
        Added -lresolv tests for ldapd and LDAP_DNS
        Added basic ISODE checks
        Added pwd.h &  getpwuid() tests
        Added sys/resource.h test
    Updated NT support (now builds ud)
    Removed lint
1998-11-15 20:08:54 +00:00

102 lines
1.8 KiB
C

/*
getopt.c
modified public-domain AT&T getopt(3)
modified by Kurt Zeilenga for inclusion into OpenLDAP
*/
#include "portable.h"
#ifndef HAVE_GETOPT
#include <stdio.h>
#include <ac/string.h>
#include <ac/unistd.h>
#ifdef HAVE_IO_H
#include <io.h>
#endif
#ifndef STDERR_FILENO
#define STDERR_FILENO 2
#endif
int opterr = 1;
int optind = 1;
int optopt;
char * optarg;
static void ERR (char * const argv[], const char * s, char c)
{
char errbuf[2];
#ifdef DF_TRACE_DEBUG
printf("DF_TRACE_DEBUG: static void ERR () in getopt.c\n");
#endif
if (opterr)
{
errbuf[0] = c;
errbuf[1] = '\n';
(void) write(STDERR_FILENO,argv[0],strlen(argv[0]));
(void) write(STDERR_FILENO,s,strlen(s));
(void) write(STDERR_FILENO,errbuf,sizeof errbuf);
}
}
int getopt (int argc, char * const argv [], const char * opts)
{
static int sp = 1, error = (int) '?';
static char sw = '-', eos = '\0', arg = ':';
register char c, * cp;
#ifdef DF_TRACE_DEBUG
printf("DF_TRACE_DEBUG: int getopt () in getopt.c\n");
#endif
if (sp == 1)
if (optind >= argc || argv[optind][0] != sw
|| argv[optind][1] == eos)
return EOF;
else if (strcmp(argv[optind],"--") == 0)
{
optind++;
return EOF;
}
c = argv[optind][sp];
optopt = (int) c;
if (c == arg || (cp = strchr(opts,c)) == NULL)
{
ERR(argv,": illegal option--",c);
if (argv[optind][++sp] == eos)
{
optind++;
sp = 1;
}
return error;
}
else if (*++cp == arg)
{
if (argv[optind][sp + 1] != eos)
optarg = &argv[optind++][sp + 1];
else if (++optind >= argc)
{
ERR(argv,": option requires an argument--",c);
sp = 1;
return error;
}
else
optarg = argv[optind++];
sp = 1;
}
else
{
if (argv[optind][++sp] == eos)
{
sp = 1;
optind++;
}
optarg = NULL;
}
return (int) c;
}
#endif /* HAVE_GETOPT */