PostgreSQL Source Code git master
Loading...
Searching...
No Matches
option_utils.h File Reference
Include dependency graph for option_utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define check_mut_excl_opts(set, opt, ...)
 

Typedefs

typedef void(* help_handler) (const char *progname)
 

Functions

void handle_help_version_opts (int argc, char *argv[], const char *fixed_progname, help_handler hlp)
 
bool option_parse_int (const char *optarg, const char *optname, int min_range, int max_range, int *result)
 
bool parse_sync_method (const char *optarg, DataDirSyncMethod *sync_method)
 
void check_mut_excl_opts_internal (int n,...)
 

Macro Definition Documentation

◆ check_mut_excl_opts

#define check_mut_excl_opts (   set,
  opt,
  ... 
)
Value:
set, opt, __VA_ARGS__)
#define VA_ARGS_NARGS(...)
Definition c.h:517
void check_mut_excl_opts_internal(int n,...)
static int fb(int x)

Definition at line 30 of file option_utils.h.

Typedef Documentation

◆ help_handler

typedef void(* help_handler) (const char *progname)

Definition at line 17 of file option_utils.h.

Function Documentation

◆ check_mut_excl_opts_internal()

void check_mut_excl_opts_internal ( int  n,
  ... 
)
extern

Definition at line 125 of file option_utils.c.

126{
127 char *first = NULL;
129
130 Assert(n % 2 == 0);
131
132 va_start(args, n);
133 for (int i = 0; i < n; i += 2)
134 {
135 bool set = va_arg(args, int);
136 char *opt = va_arg(args, char *);
137
138 if (set && first)
139 pg_fatal("options %s and %s cannot be used together",
140 first, opt);
141
142 if (set)
143 first = opt;
144 }
145 va_end(args);
146}
#define Assert(condition)
Definition c.h:945
int i
Definition isn.c:77
#define pg_fatal(...)

References Assert, fb(), i, and pg_fatal.

◆ handle_help_version_opts()

void handle_help_version_opts ( int  argc,
char argv[],
const char fixed_progname,
help_handler  hlp 
)
extern

Definition at line 24 of file option_utils.c.

26{
27 if (argc > 1)
28 {
29 if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
30 {
31 hlp(get_progname(argv[0]));
32 exit(0);
33 }
34 if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
35 {
36 printf("%s (PostgreSQL) " PG_VERSION "\n", fixed_progname);
37 exit(0);
38 }
39 }
40}
const char * get_progname(const char *argv0)
Definition path.c:652
#define printf(...)
Definition port.h:266

References fb(), get_progname(), and printf.

Referenced by main(), and main().

◆ option_parse_int()

bool option_parse_int ( const char optarg,
const char optname,
int  min_range,
int  max_range,
int result 
)
extern

Definition at line 50 of file option_utils.c.

53{
54 char *endptr;
55 int val;
56
57 errno = 0;
58 val = strtoint(optarg, &endptr, 10);
59
60 /*
61 * Skip any trailing whitespace; if anything but whitespace remains before
62 * the terminating character, fail.
63 */
64 while (*endptr != '\0' && isspace((unsigned char) *endptr))
65 endptr++;
66
67 if (*endptr != '\0')
68 {
69 pg_log_error("invalid value \"%s\" for option %s",
70 optarg, optname);
71 return false;
72 }
73
75 {
76 pg_log_error("%s must be in range %d..%d",
77 optname, min_range, max_range);
78 return false;
79 }
80
81 if (result)
82 *result = val;
83 return true;
84}
long val
Definition informix.c:689
#define pg_log_error(...)
Definition logging.h:106
PGDLLIMPORT char * optarg
Definition getopt.c:53
int strtoint(const char *pg_restrict str, char **pg_restrict endptr, int base)
Definition string.c:50

References fb(), optarg, pg_log_error, strtoint(), and val.

Referenced by main(), and main().

◆ parse_sync_method()

bool parse_sync_method ( const char optarg,
DataDirSyncMethod sync_method 
)
extern

Definition at line 90 of file option_utils.c.

91{
92 if (strcmp(optarg, "fsync") == 0)
94 else if (strcmp(optarg, "syncfs") == 0)
95 {
96#ifdef HAVE_SYNCFS
98#else
99 pg_log_error("this build does not support sync method \"%s\"",
100 "syncfs");
101 return false;
102#endif
103 }
104 else
105 {
106 pg_log_error("unrecognized sync method: %s", optarg);
107 return false;
108 }
109
110 return true;
111}
@ DATA_DIR_SYNC_METHOD_SYNCFS
Definition file_utils.h:30
@ DATA_DIR_SYNC_METHOD_FSYNC
Definition file_utils.h:29
static DataDirSyncMethod sync_method
Definition initdb.c:170

References DATA_DIR_SYNC_METHOD_FSYNC, DATA_DIR_SYNC_METHOD_SYNCFS, fb(), optarg, pg_log_error, and sync_method.

Referenced by main(), main(), and parseCommandLine().