Back to index

openldap  2.4.31
Defines | Functions | Variables
getopt.c File Reference
#include "portable.h"
#include <stdio.h>
#include <ac/string.h>
#include <ac/unistd.h>
#include "lutil.h"

Go to the source code of this file.

Defines

#define STDERR_FILENO   2

Functions

static void ERR (char *const argv[], const char *s, char c)
int getopt (int argc, char *const argv[], const char *opts)

Variables

int opterr = 1
int optind = 1
int optopt
char * optarg

Define Documentation

#define STDERR_FILENO   2

Definition at line 39 of file getopt.c.


Function Documentation

static void ERR ( char *const  argv[],
const char *  s,
char  c 
) [static]

Definition at line 51 of file getopt.c.

{
#ifdef DF_TRACE_DEBUG
printf("DF_TRACE_DEBUG:     static void ERR () in getopt.c\n");
#endif
       if (opterr)
       {
              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);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int getopt ( int  argc,
char *const  argv[],
const char *  opts 
)

Definition at line 71 of file getopt.c.

{
       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

#ifdef HAVE_EBCDIC
       if (_trans_argv) {
              int i;
              for (i=0; i<argc; i++) __etoa(argv[i]);
              _trans_argv = 0;
       }
#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;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

char* optarg

Definition at line 45 of file getopt.c.

int opterr = 1

Definition at line 42 of file getopt.c.

int optind = 1

Definition at line 43 of file getopt.c.

Definition at line 44 of file getopt.c.