From: Kurt Zeilenga Date: Sun, 25 Oct 1998 03:15:45 +0000 (+0000) Subject: New files from Autoconf branch. X-Git-Tag: PHP3_TOOL_0_0~19 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=926ba6cb4afd403aef6a216a7b68e83a9f50c8fc;p=openldap New files from Autoconf branch. --- diff --git a/libraries/liblutil/getopt.c b/libraries/liblutil/getopt.c new file mode 100644 index 0000000000..d1d1345a64 --- /dev/null +++ b/libraries/liblutil/getopt.c @@ -0,0 +1,102 @@ +/* + getopt.c + + modified public-domain AT&T getopt(3) + modified by Kurt Zeilenga for inclusion into OpenLDAP +*/ + +#include "portable.h" + +#ifndef HAVE_GETOPT + +#include + +#include +#include + +#ifdef HAVE_IO_H +#include +#endif + +#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 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 ** argv, 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 */ diff --git a/libraries/liblutil/strdup.c b/libraries/liblutil/strdup.c new file mode 100644 index 0000000000..a7140dbd86 --- /dev/null +++ b/libraries/liblutil/strdup.c @@ -0,0 +1,19 @@ +#include "portable.h" + +#ifndef HAVE_STRDUP + +#include + +char *strdup( const char *s ) +{ + char *p; + + if ( (p = (char *) malloc( strlen( s ) + 1 )) == NULL ) + return( NULL ); + + strcpy( p, s ); + + return( p ); +} + +#endif /* !strdup */ diff --git a/libraries/liblutil/tempnam.c b/libraries/liblutil/tempnam.c new file mode 100644 index 0000000000..9aa21870b8 --- /dev/null +++ b/libraries/liblutil/tempnam.c @@ -0,0 +1,38 @@ +#include "portable.h" + +#ifndef HAVE_TEMPNAME + +#include + +char *tempnam( char *dir, char *pfx ) +{ + char *s; + + if ( dir == NULL ) { + dir = "/tmp"; + } + +/* + * allocate space for dir + '/' + pfx (up to 5 chars) + 6 trailing 'X's + 0 byte + */ + if (( s = (char *)malloc( strlen( dir ) + 14 )) == NULL ) { + return( NULL ); + } + + strcpy( s, dir ); + strcat( s, "/" ); + if ( pfx != NULL ) { + strcat( s, pfx ); + } + strcat( s, "XXXXXX" ); + mktemp( s ); + + if ( *s == '\0' ) { + free( s ); + s = NULL; + } + + return( s ); +} + +#endif /* nextstep */