X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Fliblutil%2Fgetopt.c;h=5e4e02273c3c9ac327666da239a6289246bfeac9;hb=f2a02b90edde2dbecb342f040603ffac72d99c36;hp=c6e8e914f702dab8b7d535fa45036e840a0baa3b;hpb=0e2af54a3ffdeebe3901370683be56fcc53023b0;p=openldap diff --git a/libraries/liblutil/getopt.c b/libraries/liblutil/getopt.c index c6e8e914f7..5e4e02273c 100644 --- a/libraries/liblutil/getopt.c +++ b/libraries/liblutil/getopt.c @@ -1,14 +1,24 @@ +/* getopt.c -- replacement getopt(3) routines */ /* $OpenLDAP$ */ -/* - * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved. - * COPYING RESTRICTIONS APPLY, see COPYRIGHT file +/* This work is part of OpenLDAP Software . + * + * Copyright 1998-2007 The OpenLDAP Foundation. + * Portions Copyright 1998-2003 Kurt D. Zeilenga. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted only as authorized by the OpenLDAP + * Public License. + * + * A copy of this license is available in the file LICENSE in the + * top-level directory of the distribution or, alternatively, at + * . + */ +/* This work is based upon the public-domain getopt(3) routines + * developed by AT&T. Modified by Kurt D. Zeilenga for inclusion + * into OpenLDAP Software. Significant contributors include: + * Howard Chu */ -/* - getopt.c - - modified public-domain AT&T getopt(3) - modified by Kurt Zeilenga for inclusion into OpenLDAP -*/ #include "portable.h" @@ -23,6 +33,8 @@ #include #endif +#include "lutil.h" + #ifndef STDERR_FILENO #define STDERR_FILENO 2 #endif @@ -32,20 +44,27 @@ int optind = 1; int optopt; char * optarg; +#ifdef HAVE_EBCDIC +extern int _trans_argv; +#endif + 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); + 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); } } @@ -57,6 +76,14 @@ int getopt (int argc, char * const argv [], const 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) { - ERR(argv,": option requires an argument--",c); + ERR(argv,_(": option requires an argument--"),c); sp = 1; return error; }