PostgreSQL Source Code  git master
pg_getopt.h
Go to the documentation of this file.
1 /*
2  * Postgres files that use getopt(3) always include this file.
3  * We must cope with three different scenarios:
4  * 1. We're using the platform's getopt(), and we should just import the
5  * appropriate declarations.
6  * 2. The platform lacks getopt(), and we must declare everything.
7  * 3. The platform has getopt(), but we're not using it because we don't
8  * like its behavior. The declarations we make here must be compatible
9  * with both the platform's getopt() and our src/port/getopt.c.
10  *
11  * Portions Copyright (c) 1987, 1993, 1994
12  * The Regents of the University of California. All rights reserved.
13  *
14  * Portions Copyright (c) 2003-2024, PostgreSQL Global Development Group
15  *
16  * src/include/pg_getopt.h
17  */
18 #ifndef PG_GETOPT_H
19 #define PG_GETOPT_H
20 
21 /* POSIX says getopt() is provided by unistd.h */
22 #include <unistd.h>
23 
24 /* rely on the system's getopt.h if present */
25 #ifdef HAVE_GETOPT_H
26 #include <getopt.h>
27 #endif
28 
29 /*
30  * If we have <getopt.h>, assume it declares these variables, else do that
31  * ourselves. (We used to just declare them unconditionally, but Cygwin
32  * doesn't like that.)
33  */
34 #ifndef HAVE_GETOPT_H
35 
36 extern PGDLLIMPORT char *optarg;
37 extern PGDLLIMPORT int optind;
38 extern PGDLLIMPORT int opterr;
39 extern PGDLLIMPORT int optopt;
40 
41 #endif /* HAVE_GETOPT_H */
42 
43 /*
44  * Some platforms have optreset but fail to declare it in <getopt.h>, so cope.
45  * Cygwin, however, doesn't like this either.
46  */
47 #if defined(HAVE_INT_OPTRESET) && !defined(__CYGWIN__)
48 extern PGDLLIMPORT int optreset;
49 #endif
50 
51 /* Provide getopt() declaration if the platform doesn't have it */
52 #ifndef HAVE_GETOPT
53 extern int getopt(int nargc, char *const *nargv, const char *ostr);
54 #endif
55 
56 #endif /* PG_GETOPT_H */
#define PGDLLIMPORT
Definition: c.h:1303
PGDLLIMPORT int optind
Definition: getopt.c:50
PGDLLIMPORT int optopt
Definition: getopt.c:51
PGDLLIMPORT int opterr
Definition: getopt.c:49
int getopt(int nargc, char *const *nargv, const char *ostr)
Definition: getopt.c:71
PGDLLIMPORT char * optarg
Definition: getopt.c:52