PostgreSQL Source Code  git master
option_utils.c File Reference
#include "postgres_fe.h"
#include "common/logging.h"
#include "common/string.h"
#include "fe_utils/option_utils.h"
Include dependency graph for option_utils.c:

Go to the source code of this file.

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)
 

Function Documentation

◆ handle_help_version_opts()

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

Definition at line 24 of file option_utils.c.

References get_progname(), and printf.

Referenced by main().

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:453
#define printf(...)
Definition: port.h:222

◆ option_parse_int()

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

Definition at line 50 of file option_utils.c.

References pg_log_error, strtoint(), and val.

Referenced by main().

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 
74  if (errno == ERANGE || val < min_range || val > max_range)
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 }
#define pg_log_error(...)
Definition: logging.h:80
int strtoint(const char *pg_restrict str, char **pg_restrict endptr, int base)
Definition: string.c:50
char * optarg
Definition: getopt.c:52
long val
Definition: informix.c:664