LCOV - differential code coverage report
Current view: top level - src/bin/pg_config - pg_config.c (source / functions) Coverage Total Hit UBC CBC
Current: Differential Code Coverage 16@8cea358b128 vs 17@8cea358b128 Lines: 97.0 % 67 65 2 65
Current Date: 2024-04-14 14:21:10 Functions: 100.0 % 4 4 4
Baseline: 16@8cea358b128 Branches: 91.7 % 24 22 2 22
Baseline Date: 2024-04-14 14:21:09 Line coverage date bins:
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed (240..) days: 97.0 % 67 65 2 65
Function coverage date bins:
(240..) days: 100.0 % 4 4 4
Branch coverage date bins:
(240..) 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-2024, 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                 :                : #include "port.h"
                                 29                 :                : 
                                 30                 :                : static const char *progname;
                                 31                 :                : 
                                 32                 :                : /*
                                 33                 :                :  * Table of known information items
                                 34                 :                :  *
                                 35                 :                :  * Be careful to keep this in sync with the help() display.
                                 36                 :                :  */
                                 37                 :                : typedef struct
                                 38                 :                : {
                                 39                 :                :     const char *switchname;
                                 40                 :                :     const char *configname;
                                 41                 :                : } InfoItem;
                                 42                 :                : 
                                 43                 :                : static const InfoItem info_items[] = {
                                 44                 :                :     {"--bindir", "BINDIR"},
                                 45                 :                :     {"--docdir", "DOCDIR"},
                                 46                 :                :     {"--htmldir", "HTMLDIR"},
                                 47                 :                :     {"--includedir", "INCLUDEDIR"},
                                 48                 :                :     {"--pkgincludedir", "PKGINCLUDEDIR"},
                                 49                 :                :     {"--includedir-server", "INCLUDEDIR-SERVER"},
                                 50                 :                :     {"--libdir", "LIBDIR"},
                                 51                 :                :     {"--pkglibdir", "PKGLIBDIR"},
                                 52                 :                :     {"--localedir", "LOCALEDIR"},
                                 53                 :                :     {"--mandir", "MANDIR"},
                                 54                 :                :     {"--sharedir", "SHAREDIR"},
                                 55                 :                :     {"--sysconfdir", "SYSCONFDIR"},
                                 56                 :                :     {"--pgxs", "PGXS"},
                                 57                 :                :     {"--configure", "CONFIGURE"},
                                 58                 :                :     {"--cc", "CC"},
                                 59                 :                :     {"--cppflags", "CPPFLAGS"},
                                 60                 :                :     {"--cflags", "CFLAGS"},
                                 61                 :                :     {"--cflags_sl", "CFLAGS_SL"},
                                 62                 :                :     {"--ldflags", "LDFLAGS"},
                                 63                 :                :     {"--ldflags_ex", "LDFLAGS_EX"},
                                 64                 :                :     {"--ldflags_sl", "LDFLAGS_SL"},
                                 65                 :                :     {"--libs", "LIBS"},
                                 66                 :                :     {"--version", "VERSION"},
                                 67                 :                :     {NULL, NULL}
                                 68                 :                : };
                                 69                 :                : 
                                 70                 :                : 
                                 71                 :                : static void
 7126 neilc@samurai.com          72                 :CBC           1 : help(void)
                                 73                 :                : {
 7168 bruce@momjian.us           74                 :              1 :     printf(_("\n%s provides information about the installed version of PostgreSQL.\n\n"), progname);
 7196                            75                 :              1 :     printf(_("Usage:\n"));
 5527 peter_e@gmx.net            76                 :              1 :     printf(_("  %s [OPTION]...\n\n"), progname);
 7196 bruce@momjian.us           77                 :              1 :     printf(_("Options:\n"));
                                 78                 :              1 :     printf(_("  --bindir              show location of user executables\n"));
 6774 tgl@sss.pgh.pa.us          79                 :              1 :     printf(_("  --docdir              show location of documentation files\n"));
 5900 peter_e@gmx.net            80                 :              1 :     printf(_("  --htmldir             show location of HTML documentation files\n"));
 7130 bruce@momjian.us           81                 :              1 :     printf(_("  --includedir          show location of C header files of the client\n"
                                 82                 :                :              "                        interfaces\n"));
 6774 tgl@sss.pgh.pa.us          83                 :              1 :     printf(_("  --pkgincludedir       show location of other C header files\n"));
 7196 bruce@momjian.us           84                 :              1 :     printf(_("  --includedir-server   show location of C header files for the server\n"));
                                 85                 :              1 :     printf(_("  --libdir              show location of object code libraries\n"));
                                 86                 :              1 :     printf(_("  --pkglibdir           show location of dynamically loadable modules\n"));
 6774 tgl@sss.pgh.pa.us          87                 :              1 :     printf(_("  --localedir           show location of locale support files\n"));
                                 88                 :              1 :     printf(_("  --mandir              show location of manual pages\n"));
                                 89                 :              1 :     printf(_("  --sharedir            show location of architecture-independent support files\n"));
                                 90                 :              1 :     printf(_("  --sysconfdir          show location of system-wide configuration files\n"));
 7195 bruce@momjian.us           91                 :              1 :     printf(_("  --pgxs                show location of extension makefile\n"));
 7118 peter_e@gmx.net            92                 :              1 :     printf(_("  --configure           show options given to \"configure\" script when\n"
                                 93                 :                :              "                        PostgreSQL was built\n"));
 6823 tgl@sss.pgh.pa.us          94                 :              1 :     printf(_("  --cc                  show CC value used when PostgreSQL was built\n"));
                                 95                 :              1 :     printf(_("  --cppflags            show CPPFLAGS value used when PostgreSQL was built\n"));
                                 96                 :              1 :     printf(_("  --cflags              show CFLAGS value used when PostgreSQL was built\n"));
                                 97                 :              1 :     printf(_("  --cflags_sl           show CFLAGS_SL value used when PostgreSQL was built\n"));
                                 98                 :              1 :     printf(_("  --ldflags             show LDFLAGS value used when PostgreSQL was built\n"));
 5032                            99                 :              1 :     printf(_("  --ldflags_ex          show LDFLAGS_EX value used when PostgreSQL was built\n"));
 6823                           100                 :              1 :     printf(_("  --ldflags_sl          show LDFLAGS_SL value used when PostgreSQL was built\n"));
                                101                 :              1 :     printf(_("  --libs                show LIBS value used when PostgreSQL was built\n"));
                                102                 :              1 :     printf(_("  --version             show the PostgreSQL version\n"));
 4318 peter_e@gmx.net           103                 :              1 :     printf(_("  -?, --help            show this help, then exit\n"));
 6765                           104                 :              1 :     printf(_("\nWith no arguments, all known items are shown.\n\n"));
 1507 peter@eisentraut.org      105                 :              1 :     printf(_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
                                106                 :              1 :     printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
 7196 bruce@momjian.us          107                 :              1 : }
                                108                 :                : 
                                109                 :                : static void
 7126 neilc@samurai.com         110                 :              1 : advice(void)
                                111                 :                : {
 6765 peter_e@gmx.net           112                 :              1 :     fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
 7196 bruce@momjian.us          113                 :              1 : }
                                114                 :                : 
                                115                 :                : static void
 2979 mail@joeconway.com        116                 :            397 : show_item(const char *configname,
                                117                 :                :           ConfigData *configdata,
                                118                 :                :           size_t configdata_len)
                                119                 :                : {
                                120                 :                :     int         i;
                                121                 :                : 
                                122         [ +  + ]:           9528 :     for (i = 0; i < configdata_len; i++)
                                123                 :                :     {
                                124         [ +  + ]:           9131 :         if (strcmp(configname, configdata[i].name) == 0)
                                125                 :            397 :             printf("%s\n", configdata[i].setting);
                                126                 :                :     }
 6823 tgl@sss.pgh.pa.us         127                 :            397 : }
                                128                 :                : 
                                129                 :                : int
 7168 bruce@momjian.us          130                 :            398 : main(int argc, char **argv)
                                131                 :                : {
                                132                 :                :     ConfigData *configdata;
                                133                 :                :     size_t      configdata_len;
                                134                 :                :     char        my_exec_path[MAXPGPATH];
                                135                 :                :     int         i;
                                136                 :                :     int         j;
                                137                 :                : 
 5603 peter_e@gmx.net           138                 :            398 :     set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_config"));
                                139                 :                : 
 7118                           140                 :            398 :     progname = get_progname(argv[0]);
                                141                 :                : 
                                142                 :                :     /* check for --help */
 7168 bruce@momjian.us          143         [ +  + ]:            796 :     for (i = 1; i < argc; i++)
                                144                 :                :     {
                                145   [ +  +  -  + ]:            399 :         if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-?") == 0)
                                146                 :                :         {
 7196                           147                 :              1 :             help();
                                148                 :              1 :             exit(0);
                                149                 :                :         }
                                150                 :                :     }
                                151                 :                : 
 2979 mail@joeconway.com        152         [ -  + ]:            397 :     if (find_my_exec(argv[0], my_exec_path) < 0)
                                153                 :                :     {
 6163 peter_e@gmx.net           154                 :UBC           0 :         fprintf(stderr, _("%s: could not find own program executable\n"), progname);
 7196 bruce@momjian.us          155                 :              0 :         exit(1);
                                156                 :                :     }
                                157                 :                : 
 2979 mail@joeconway.com        158                 :CBC         397 :     configdata = get_configdata(my_exec_path, &configdata_len);
                                159                 :                :     /* no arguments -> print everything */
 6823 tgl@sss.pgh.pa.us         160         [ +  + ]:            397 :     if (argc < 2)
                                161                 :                :     {
 2979 mail@joeconway.com        162         [ +  + ]:             24 :         for (i = 0; i < configdata_len; i++)
                                163                 :             23 :             printf("%s = %s\n", configdata[i].name, configdata[i].setting);
 6823 tgl@sss.pgh.pa.us         164                 :              1 :         exit(0);
                                165                 :                :     }
                                166                 :                : 
                                167                 :                :     /* otherwise print requested items */
                                168         [ +  + ]:            793 :     for (i = 1; i < argc; i++)
                                169                 :                :     {
                                170         [ +  + ]:           8328 :         for (j = 0; info_items[j].switchname != NULL; j++)
                                171                 :                :         {
                                172         [ +  + ]:           8327 :             if (strcmp(argv[i], info_items[j].switchname) == 0)
                                173                 :                :             {
 2979 mail@joeconway.com        174                 :            397 :                 show_item(info_items[j].configname,
                                175                 :                :                           configdata, configdata_len);
 6823 tgl@sss.pgh.pa.us         176                 :            397 :                 break;
                                177                 :                :             }
                                178                 :                :         }
                                179         [ +  + ]:            398 :         if (info_items[j].switchname == NULL)
                                180                 :                :         {
                                181                 :              1 :             fprintf(stderr, _("%s: invalid argument: %s\n"),
                                182                 :              1 :                     progname, argv[i]);
                                183                 :              1 :             advice();
                                184                 :              1 :             exit(1);
                                185                 :                :         }
                                186                 :                :     }
                                187                 :                : 
 7196 bruce@momjian.us          188                 :            395 :     return 0;
                                189                 :                : }
        

Generated by: LCOV version 2.1-beta2-3-g6141622