LCOV - differential code coverage report
Current view: top level - src/fe_utils - option_utils.c (source / functions) Coverage Total Hit CBC
Current: Differential Code Coverage HEAD vs 15 Lines: 100.0 % 23 23 23
Current Date: 2023-04-08 17:13:01 Functions: 100.0 % 2 2 2
Baseline: 15 Line coverage date bins:
Baseline Date: 2023-04-08 15:09:40 (240..) days: 100.0 % 23 23 23
Legend: Lines: hit not hit Function coverage date bins:
(240..) days: 100.0 % 2 2 2

 Age         Owner                  TLA  Line data    Source code
                                  1                 : /*-------------------------------------------------------------------------
                                  2                 :  *
                                  3                 :  * Command line option processing facilities for frontend code
                                  4                 :  *
                                  5                 :  * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
                                  6                 :  * Portions Copyright (c) 1994, Regents of the University of California
                                  7                 :  *
                                  8                 :  * src/fe_utils/option_utils.c
                                  9                 :  *
                                 10                 :  *-------------------------------------------------------------------------
                                 11                 :  */
                                 12                 : 
                                 13                 : #include "postgres_fe.h"
                                 14                 : 
                                 15                 : #include "common/logging.h"
                                 16                 : #include "common/string.h"
                                 17                 : #include "fe_utils/option_utils.h"
                                 18                 : 
                                 19                 : /*
                                 20                 :  * Provide strictly harmonized handling of --help and --version
                                 21                 :  * options.
                                 22                 :  */
                                 23                 : void
  793 rhaas                      24 CBC         225 : handle_help_version_opts(int argc, char *argv[],
                                 25                 :                          const char *fixed_progname, help_handler hlp)
                                 26                 : {
                                 27             225 :     if (argc > 1)
                                 28                 :     {
                                 29             223 :         if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
                                 30                 :         {
                                 31               9 :             hlp(get_progname(argv[0]));
                                 32               9 :             exit(0);
                                 33                 :         }
                                 34             214 :         if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
                                 35                 :         {
                                 36              11 :             printf("%s (PostgreSQL) " PG_VERSION "\n", fixed_progname);
                                 37              11 :             exit(0);
                                 38                 :         }
                                 39                 :     }
                                 40             205 : }
                                 41                 : 
                                 42                 : /*
                                 43                 :  * option_parse_int
                                 44                 :  *
                                 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,
                                 47                 :  * returns false.
                                 48                 :  */
                                 49                 : bool
  624 michael                    50             182 : option_parse_int(const char *optarg, const char *optname,
                                 51                 :                  int min_range, int max_range,
                                 52                 :                  int *result)
                                 53                 : {
                                 54                 :     char       *endptr;
                                 55                 :     int         val;
                                 56                 : 
                                 57             182 :     errno = 0;
                                 58             182 :     val = strtoint(optarg, &endptr, 10);
                                 59                 : 
                                 60                 :     /*
                                 61                 :      * Skip any trailing whitespace; if anything but whitespace remains before
                                 62                 :      * the terminating character, fail.
                                 63                 :      */
  621                            64             183 :     while (*endptr != '\0' && isspace((unsigned char) *endptr))
                                 65               1 :         endptr++;
                                 66                 : 
                                 67             182 :     if (*endptr != '\0')
                                 68                 :     {
  624                            69               5 :         pg_log_error("invalid value \"%s\" for option %s",
                                 70                 :                      optarg, optname);
                                 71               5 :         return false;
                                 72                 :     }
                                 73                 : 
                                 74             177 :     if (errno == ERANGE || val < min_range || val > max_range)
                                 75                 :     {
                                 76              11 :         pg_log_error("%s must be in range %d..%d",
                                 77                 :                      optname, min_range, max_range);
                                 78              11 :         return false;
                                 79                 :     }
                                 80                 : 
                                 81             166 :     if (result)
                                 82             160 :         *result = val;
                                 83             166 :     return true;
                                 84                 : }
        

Generated by: LCOV version v1.16-55-g56c0a2a