PostgreSQL Source Code  git master
pg_getopt.h File Reference
#include <unistd.h>
Include dependency graph for pg_getopt.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int getopt (int nargc, char *const *nargv, const char *ostr)
 

Variables

PGDLLIMPORT char * optarg
 
PGDLLIMPORT int optind
 
PGDLLIMPORT int opterr
 
PGDLLIMPORT int optopt
 

Function Documentation

◆ getopt()

int getopt ( int  nargc,
char *const *  nargv,
const char *  ostr 
)

Definition at line 71 of file getopt.c.

72 {
73  static char *place = EMSG; /* option letter processing */
74  char *oli; /* option letter list index */
75 
76  if (!*place)
77  { /* update scanning pointer */
78  if (optind >= nargc || *(place = nargv[optind]) != '-')
79  {
80  place = EMSG;
81  return -1;
82  }
83  if (place[1] && *++place == '-' && place[1] == '\0')
84  { /* found "--" */
85  ++optind;
86  place = EMSG;
87  return -1;
88  }
89  } /* option letter okay? */
90  if ((optopt = (int) *place++) == (int) ':' ||
91  !(oli = strchr(ostr, optopt)))
92  {
93  /*
94  * if the user didn't specify '-' as an option, assume it means -1.
95  */
96  if (optopt == (int) '-')
97  {
98  place = EMSG;
99  return -1;
100  }
101  if (!*place)
102  ++optind;
103  if (opterr && *ostr != ':')
104  (void) fprintf(stderr,
105  "illegal option -- %c\n", optopt);
106  return BADCH;
107  }
108  if (*++oli != ':')
109  { /* don't need argument */
110  optarg = NULL;
111  if (!*place)
112  ++optind;
113  }
114  else
115  { /* need an argument */
116  if (*place) /* no white space */
117  optarg = place;
118  else if (nargc <= ++optind)
119  { /* no arg */
120  place = EMSG;
121  if (*ostr == ':')
122  return BADARG;
123  if (opterr)
124  (void) fprintf(stderr,
125  "option requires an argument -- %c\n",
126  optopt);
127  return BADCH;
128  }
129  else
130  /* white space */
131  optarg = nargv[optind];
132  place = EMSG;
133  ++optind;
134  }
135  return optopt; /* dump back option letter */
136 }
#define BADCH
Definition: getopt.c:56
int optopt
Definition: getopt.c:51
#define BADARG
Definition: getopt.c:57
#define EMSG
Definition: getopt.c:58
int optind
Definition: getopt.c:50
char * optarg
Definition: getopt.c:52
int opterr
Definition: getopt.c:49
#define fprintf
Definition: port.h:242

References BADARG, BADCH, EMSG, fprintf, optarg, opterr, optind, and optopt.

Referenced by BootstrapModeMain(), main(), PostmasterMain(), and process_postgres_switches().

Variable Documentation

◆ optarg

◆ opterr

PGDLLIMPORT int opterr
extern

Definition at line 49 of file getopt.c.

Referenced by getopt(), getopt_long(), PostmasterMain(), and process_postgres_switches().

◆ optind

◆ optopt

PGDLLIMPORT int optopt
extern

Definition at line 51 of file getopt.c.

Referenced by getopt(), and getopt_long().