]> git.sur5r.net Git - openldap/blobdiff - libraries/liblutil/getopt.c
Fix ldaps / TLS processing...
[openldap] / libraries / liblutil / getopt.c
index a19d9ba2c92aeabb7b92b120f52efe2856984b63..ac63dbdae4d9240ae647c24dada2f542cc7342a1 100644 (file)
@@ -1,21 +1,30 @@
+/* $OpenLDAP$ */
+/*
+ * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
 /*
        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 <string.h>
 
-#ifdef _POSIX_SOURCE
-#      include <unistd.h>
-#else
-#      define STDERR_FILENO 2
-#      ifdef __STDC__
-               extern int write (int fildes, char * buf, unsigned nbyte);
-#      else
-               extern int write ();
-#      endif
+#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;
@@ -23,12 +32,7 @@ int optind = 1;
 int optopt;
 char * optarg;
 
-#ifdef __STDC__
-       static void ERR (char ** argv, char * s, char c)
-#else
-       static void ERR (argv, s, c)
-       char ** argv, * s, c;
-#endif
+static void ERR (char * const argv[], const char * s, char c)
 {
        char errbuf[2];
 
@@ -45,13 +49,7 @@ printf("DF_TRACE_DEBUG:      static void ERR () in getopt.c\n");
        }
 }
 
-#ifdef __STDC__
-       int getopt (int argc, char ** argv, char * opts)
-#else
-       int getopt (argc, argv, opts)
-       int argc;
-       char ** argv, * opts;
-#endif
+int getopt (int argc, char * const argv [], const char * opts)
 {
        static int sp = 1, error = (int) '?';
        static char sw = '-', eos = '\0', arg = ':';
@@ -61,6 +59,7 @@ printf("DF_TRACE_DEBUG:       static void ERR () in getopt.c\n");
 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;
@@ -69,6 +68,7 @@ printf("DF_TRACE_DEBUG:       int getopt () in getopt.c\n");
                        optind++;
                        return EOF;
                }
+       }
        c = argv[optind][sp];
        optopt = (int) c;
        if (c == arg || (cp = strchr(opts,c)) == NULL)
@@ -106,3 +106,4 @@ printf("DF_TRACE_DEBUG:     int getopt () in getopt.c\n");
        }
        return (int) c;
 }
+#endif /* HAVE_GETOPT */