LCOV - differential code coverage report
Current view: top level - src/bin/pg_config - pg_config.c (source / functions) Coverage Total Hit UIC GIC
Current: c70b6db34ffeab48beef1fb4ce61bcad3772b8dd vs 06473f5a344df8c9594ead90a609b86f6724cff8 Lines: 97.0 % 67 65 2 65
Current Date: 2025-09-06 07:49:51 +0900 Functions: 100.0 % 4 4 4
Baseline: lcov-20250906-005545-baseline Branches: 91.7 % 24 22 2 22
Baseline Date: 2025-09-05 08:21:35 +0100 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(360..) days: 97.0 % 67 65 2 65
Function coverage date bins:
(360..) days: 100.0 % 4 4 4
Branch coverage date bins:
(360..) days: 91.7 % 24 22 2 22

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*-------------------------------------------------------------------------
                                  2                 :                :  *
                                  3                 :                :  * pg_config.c
                                  4                 :                :  *
                                  5                 :                :  * This program reports various pieces of information about the
                                  6                 :                :  * installed version of PostgreSQL.  Packages that interface to
                                  7                 :                :  * PostgreSQL can use it to configure their build.
                                  8                 :                :  *
                                  9                 :                :  * This is a C implementation of the previous shell script written by
                                 10                 :                :  * Peter Eisentraut <peter_e@gmx.net>, with adjustments made to
                                 11                 :                :  * accommodate the possibility that the installation has been relocated from
                                 12                 :                :  * the place originally configured.
                                 13                 :                :  *
                                 14                 :                :  * author of C translation: Andrew Dunstan     mailto:andrew@dunslane.net
                                 15                 :                :  *
                                 16                 :                :  * This code is released under the terms of the PostgreSQL License.
                                 17                 :                :  *
                                 18                 :                :  * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
                                 19                 :                :  *
                                 20                 :                :  * src/bin/pg_config/pg_config.c
                                 21                 :                :  *
                                 22                 :                :  *-------------------------------------------------------------------------
                                 23                 :                :  */
                                 24                 :                : 
                                 25                 :                : #include "postgres_fe.h"
                                 26                 :                : 
                                 27                 :                : #include "common/config_info.h"
                                 28                 :                : 
                                 29                 :                : static const char *progname;
                                 30                 :                : 
                                 31                 :                : /*
                                 32                 :                :  * Table of known information items
                                 33                 :                :  *
                                 34                 :                :  * Be careful to keep this in sync with the help() display.
                                 35                 :                :  */
                                 36                 :                : typedef struct
                                 37                 :                : {
                                 38                 :                :     const char *switchname;
                                 39                 :                :     const char *configname;
                                 40                 :                : } InfoItem;
                                 41                 :                : 
                                 42                 :                : static const InfoItem info_items[] = {
                                 43                 :                :     {"--bindir", "BINDIR"},
                                 44                 :                :     {"--docdir", "DOCDIR"},
                                 45                 :                :     {"--htmldir", "HTMLDIR"},
                                 46                 :                :     {"--includedir", "INCLUDEDIR"},
                                 47                 :                :     {"--pkgincludedir", "PKGINCLUDEDIR"},
                                 48                 :                :     {"--includedir-server", "INCLUDEDIR-SERVER"},
                                 49                 :                :     {"--libdir", "LIBDIR"},
                                 50                 :                :     {"--pkglibdir", "PKGLIBDIR"},
                                 51                 :                :     {"--localedir", "LOCALEDIR"},
                                 52                 :                :     {"--mandir", "MANDIR"},
                                 53                 :                :     {"--sharedir", "SHAREDIR"},
                                 54                 :                :     {"--sysconfdir", "SYSCONFDIR"},
                                 55                 :                :     {"--pgxs", "PGXS"},
                                 56                 :                :     {"--configure", "CONFIGURE"},
                                 57                 :                :     {"--cc", "CC"},
                                 58                 :                :     {"--cppflags", "CPPFLAGS"},
                                 59                 :                :     {"--cflags", "CFLAGS"},
                                 60                 :                :     {"--cflags_sl", "CFLAGS_SL"},
                                 61                 :                :     {"--ldflags", "LDFLAGS"},
                                 62                 :                :     {"--ldflags_ex", "LDFLAGS_EX"},
                                 63                 :                :     {"--ldflags_sl", "LDFLAGS_SL"},
                                 64                 :                :     {"--libs", "LIBS"},
                                 65                 :                :     {"--version", "VERSION"},
                                 66                 :                :     {NULL, NULL}
                                 67                 :                : };
                                 68                 :                : 
                                 69                 :                : 
                                 70                 :                : static void
 7636 neilc@samurai.com          71                 :GIC           1 : help(void)
                                 72                 :                : {
 7678 bruce@momjian.us           73                 :              1 :     printf(_("\n%s provides information about the installed version of PostgreSQL.\n\n"), progname);
 7706                            74                 :              1 :     printf(_("Usage:\n"));
 6037 peter_e@gmx.net            75                 :              1 :     printf(_("  %s [OPTION]...\n\n"), progname);
 7706 bruce@momjian.us           76                 :              1 :     printf(_("Options:\n"));
                                 77                 :              1 :     printf(_("  --bindir              show location of user executables\n"));
 7284 tgl@sss.pgh.pa.us          78                 :              1 :     printf(_("  --docdir              show location of documentation files\n"));
 6410 peter_e@gmx.net            79                 :              1 :     printf(_("  --htmldir             show location of HTML documentation files\n"));
 7640 bruce@momjian.us           80                 :              1 :     printf(_("  --includedir          show location of C header files of the client\n"
                                 81                 :                :              "                        interfaces\n"));
 7284 tgl@sss.pgh.pa.us          82                 :              1 :     printf(_("  --pkgincludedir       show location of other C header files\n"));
 7706 bruce@momjian.us           83                 :              1 :     printf(_("  --includedir-server   show location of C header files for the server\n"));
                                 84                 :              1 :     printf(_("  --libdir              show location of object code libraries\n"));
                                 85                 :              1 :     printf(_("  --pkglibdir           show location of dynamically loadable modules\n"));
 7284 tgl@sss.pgh.pa.us          86                 :              1 :     printf(_("  --localedir           show location of locale support files\n"));
                                 87                 :              1 :     printf(_("  --mandir              show location of manual pages\n"));
                                 88                 :              1 :     printf(_("  --sharedir            show location of architecture-independent support files\n"));
                                 89                 :              1 :     printf(_("  --sysconfdir          show location of system-wide configuration files\n"));
 7705 bruce@momjian.us           90                 :              1 :     printf(_("  --pgxs                show location of extension makefile\n"));
 7628 peter_e@gmx.net            91                 :              1 :     printf(_("  --configure           show options given to \"configure\" script when\n"
                                 92                 :                :              "                        PostgreSQL was built\n"));
 7333 tgl@sss.pgh.pa.us          93                 :              1 :     printf(_("  --cc                  show CC value used when PostgreSQL was built\n"));
                                 94                 :              1 :     printf(_("  --cppflags            show CPPFLAGS value used when PostgreSQL was built\n"));
                                 95                 :              1 :     printf(_("  --cflags              show CFLAGS value used when PostgreSQL was built\n"));
                                 96                 :              1 :     printf(_("  --cflags_sl           show CFLAGS_SL value used when PostgreSQL was built\n"));
                                 97                 :              1 :     printf(_("  --ldflags             show LDFLAGS value used when PostgreSQL was built\n"));
 5542                            98                 :              1 :     printf(_("  --ldflags_ex          show LDFLAGS_EX value used when PostgreSQL was built\n"));
 7333                            99                 :              1 :     printf(_("  --ldflags_sl          show LDFLAGS_SL value used when PostgreSQL was built\n"));
                                100                 :              1 :     printf(_("  --libs                show LIBS value used when PostgreSQL was built\n"));
                                101                 :              1 :     printf(_("  --version             show the PostgreSQL version\n"));
 4828 peter_e@gmx.net           102                 :              1 :     printf(_("  -?, --help            show this help, then exit\n"));
 7275                           103                 :              1 :     printf(_("\nWith no arguments, all known items are shown.\n\n"));
 2017 peter@eisentraut.org      104                 :              1 :     printf(_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
                                105                 :              1 :     printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
 7706 bruce@momjian.us          106                 :              1 : }
                                107                 :                : 
                                108                 :                : static void
 7636 neilc@samurai.com         109                 :              1 : advice(void)
                                110                 :                : {
 7275 peter_e@gmx.net           111                 :              1 :     fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
 7706 bruce@momjian.us          112                 :              1 : }
                                113                 :                : 
                                114                 :                : static void
 3489 mail@joeconway.com        115                 :            454 : show_item(const char *configname,
                                116                 :                :           ConfigData *configdata,
                                117                 :                :           size_t configdata_len)
                                118                 :                : {
                                119                 :                :     int         i;
                                120                 :                : 
                                121         [ +  + ]:          10896 :     for (i = 0; i < configdata_len; i++)
                                122                 :                :     {
                                123         [ +  + ]:          10442 :         if (strcmp(configname, configdata[i].name) == 0)
                                124                 :            454 :             printf("%s\n", configdata[i].setting);
                                125                 :                :     }
 7333 tgl@sss.pgh.pa.us         126                 :            454 : }
                                127                 :                : 
                                128                 :                : int
 7678 bruce@momjian.us          129                 :            455 : main(int argc, char **argv)
                                130                 :                : {
                                131                 :                :     ConfigData *configdata;
                                132                 :                :     size_t      configdata_len;
                                133                 :                :     char        my_exec_path[MAXPGPATH];
                                134                 :                :     int         i;
                                135                 :                :     int         j;
                                136                 :                : 
 6113 peter_e@gmx.net           137                 :            455 :     set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_config"));
                                138                 :                : 
 7628                           139                 :            455 :     progname = get_progname(argv[0]);
                                140                 :                : 
                                141                 :                :     /* check for --help */
 7678 bruce@momjian.us          142         [ +  + ]:            910 :     for (i = 1; i < argc; i++)
                                143                 :                :     {
                                144   [ +  +  -  + ]:            456 :         if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-?") == 0)
                                145                 :                :         {
 7706                           146                 :              1 :             help();
                                147                 :              1 :             exit(0);
                                148                 :                :         }
                                149                 :                :     }
                                150                 :                : 
 3489 mail@joeconway.com        151         [ -  + ]:            454 :     if (find_my_exec(argv[0], my_exec_path) < 0)
                                152                 :                :     {
 6673 peter_e@gmx.net           153                 :UIC           0 :         fprintf(stderr, _("%s: could not find own program executable\n"), progname);
 7706 bruce@momjian.us          154                 :              0 :         exit(1);
                                155                 :                :     }
                                156                 :                : 
 3489 mail@joeconway.com        157                 :GIC         454 :     configdata = get_configdata(my_exec_path, &configdata_len);
                                158                 :                :     /* no arguments -> print everything */
 7333 tgl@sss.pgh.pa.us         159         [ +  + ]:            454 :     if (argc < 2)
                                160                 :                :     {
 3489 mail@joeconway.com        161         [ +  + ]:             24 :         for (i = 0; i < configdata_len; i++)
                                162                 :             23 :             printf("%s = %s\n", configdata[i].name, configdata[i].setting);
 7333 tgl@sss.pgh.pa.us         163                 :              1 :         exit(0);
                                164                 :                :     }
                                165                 :                : 
                                166                 :                :     /* otherwise print requested items */
                                167         [ +  + ]:            907 :     for (i = 1; i < argc; i++)
                                168                 :                :     {
                                169         [ +  + ]:           9236 :         for (j = 0; info_items[j].switchname != NULL; j++)
                                170                 :                :         {
                                171         [ +  + ]:           9235 :             if (strcmp(argv[i], info_items[j].switchname) == 0)
                                172                 :                :             {
 3489 mail@joeconway.com        173                 :            454 :                 show_item(info_items[j].configname,
                                174                 :                :                           configdata, configdata_len);
 7333 tgl@sss.pgh.pa.us         175                 :            454 :                 break;
                                176                 :                :             }
                                177                 :                :         }
                                178         [ +  + ]:            455 :         if (info_items[j].switchname == NULL)
                                179                 :                :         {
                                180                 :              1 :             fprintf(stderr, _("%s: invalid argument: %s\n"),
                                181                 :              1 :                     progname, argv[i]);
                                182                 :              1 :             advice();
                                183                 :              1 :             exit(1);
                                184                 :                :         }
                                185                 :                :     }
                                186                 :                : 
 7706 bruce@momjian.us          187                 :            452 :     return 0;
                                188                 :                : }
        

Generated by: LCOV version 2.4-beta