X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Fliblutil%2Fgetopt.c;h=137944ab6f7d2552305e311af20fadaa53e6bd8a;hb=c0f8e30d2290b22718f3cfd6800679dfb4c253a9;hp=112616fdceb4b717850c422831cf7eb5eb7190fc;hpb=6880f37fdc5a133b07c2efb15b6128aceaa5c55a;p=openldap diff --git a/libraries/liblutil/getopt.c b/libraries/liblutil/getopt.c index 112616fdce..137944ab6f 100644 --- a/libraries/liblutil/getopt.c +++ b/libraries/liblutil/getopt.c @@ -1,3 +1,8 @@ +/* $OpenLDAP$ */ +/* + * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ /* getopt.c @@ -14,29 +19,46 @@ #include #include +#ifdef HAVE_IO_H +#include +#endif + +#include "lutil.h" + +#ifndef STDERR_FILENO +#define STDERR_FILENO 2 +#endif + int opterr = 1; int optind = 1; int optopt; char * optarg; -static void ERR (char ** argv, char * s, char c) -{ - char errbuf[2]; +#ifdef HAVE_EBCDIC +extern int _trans_argv; +#endif +static void ERR (char * const argv[], const char * s, char c) +{ #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); + char *ptr, outbuf[4096]; + + ptr = lutil_strncopy(outbuf, argv[0], sizeof(outbuf) - 2); + ptr = lutil_strncopy(ptr, s, sizeof(outbuf)-2 -(ptr-outbuf)); + *ptr++ = c; + *ptr++ = '\n'; +#ifdef HAVE_EBCDIC + __atoe_l(outbuf, ptr - outbuf); +#endif + (void) write(STDERR_FILENO,outbuf,ptr - outbuf); } } -int getopt (int argc, char ** argv, char * opts) +int getopt (int argc, char * const argv [], const char * opts) { static int sp = 1, error = (int) '?'; static char sw = '-', eos = '\0', arg = ':'; @@ -44,8 +66,17 @@ int getopt (int argc, char ** argv, char * opts) #ifdef DF_TRACE_DEBUG printf("DF_TRACE_DEBUG: int getopt () in getopt.c\n"); +#endif + +#ifdef HAVE_EBCDIC + if (_trans_argv) { + int i; + for (i=0; i= argc || argv[optind][0] != sw || argv[optind][1] == eos) return EOF; @@ -54,6 +85,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)