1/*-------------------------------------------------------------------------
3 * Command line option processing facilities for frontend code
5 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
6 * Portions Copyright (c) 1994, Regents of the University of California
8 * src/fe_utils/option_utils.c
10 *-------------------------------------------------------------------------
20 * Provide strictly harmonized handling of --help and --version
29 if (strcmp(argv[1],
"--help") == 0 || strcmp(argv[1],
"-?") == 0)
34 if (strcmp(argv[1],
"--version") == 0 || strcmp(argv[1],
"-V") == 0)
36 printf(
"%s (PostgreSQL) " PG_VERSION
"\n", fixed_progname);
45 * Parse integer value for an option. If the parsing is successful, returns
46 * true and stores the result in *result if that's given; if parsing fails,
51 int min_range,
int max_range,
61 * Skip any trailing whitespace; if anything but whitespace remains before
62 * the terminating character, fail.
64 while (*endptr !=
'0円' && isspace((
unsigned char) *endptr))
74 if (errno == ERANGE || val < min_range || val > max_range)
77 optname, min_range, max_range);
87 * Provide strictly harmonized handling of the --sync-method option.
92 if (strcmp(
optarg,
"fsync") == 0)
94 else if (strcmp(
optarg,
"syncfs") == 0)
99 pg_log_error(
"this build does not support sync method \"%s\"",
@ DATA_DIR_SYNC_METHOD_SYNCFS
@ DATA_DIR_SYNC_METHOD_FSYNC
static DataDirSyncMethod sync_method
#define pg_log_error(...)
bool option_parse_int(const char *optarg, const char *optname, int min_range, int max_range, int *result)
void handle_help_version_opts(int argc, char *argv[], const char *fixed_progname, help_handler hlp)
bool parse_sync_method(const char *optarg, DataDirSyncMethod *sync_method)
void(* help_handler)(const char *progname)
PGDLLIMPORT char * optarg
const char * get_progname(const char *argv0)
int strtoint(const char *pg_restrict str, char **pg_restrict endptr, int base)