PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
libpq_uri_regress.c File Reference
#include "postgres_fe.h"
#include "libpq-fe.h"
Include dependency graph for libpq_uri_regress.c:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 21 of file libpq_uri_regress.c.

22{
24 PQconninfoOption *defs;
27 char *errmsg = NULL;
28 bool local = true;
29
30 if (argc != 2)
31 return 1;
32
33 opts = PQconninfoParse(argv[1], &errmsg);
34 if (opts == NULL)
35 {
36 fprintf(stderr, "libpq_uri_regress: %s", errmsg);
37 return 1;
38 }
39
40 defs = PQconndefaults();
41 if (defs == NULL)
42 {
43 fprintf(stderr, "libpq_uri_regress: cannot fetch default options\n");
44 return 1;
45 }
46
47 /*
48 * Loop on the options, and print the value of each if not the default.
49 *
50 * XXX this coding assumes that PQconninfoOption structs always have the
51 * keywords in the same order.
52 */
53 for (opt = opts, def = defs; opt->keyword; ++opt, ++def)
54 {
55 if (opt->val != NULL)
56 {
57 if (def->val == NULL || strcmp(opt->val, def->val) != 0)
58 printf("%s='%s' ", opt->keyword, opt->val);
59
60 /*
61 * Try to detect if this is a Unix-domain socket or inet. This is
62 * a bit grotty but it's the same thing that libpq itself does.
63 *
64 * Note that we directly test for '/' instead of using
65 * is_absolute_path, as that would be considerably more messy.
66 * This would fail on Windows, but that platform doesn't have
67 * Unix-domain sockets anyway.
68 */
69 if (*opt->val &&
70 (strcmp(opt->keyword, "hostaddr") == 0 ||
71 (strcmp(opt->keyword, "host") == 0 && *opt->val != '/')))
72 {
73 local = false;
74 }
75 }
76 }
77
78 if (local)
79 printf("(local)\n");
80 else
81 printf("(inet)\n");
82
83 return 0;
84}
#define fprintf(file, fmt, msg)
Definition: cubescan.l:21
int errmsg(const char *fmt,...)
Definition: elog.c:1070
PQconninfoOption * PQconninfoParse(const char *conninfo, char **errmsg)
Definition: fe-connect.c:5799
PQconninfoOption * PQconndefaults(void)
Definition: fe-connect.c:1940
static AmcheckOptions opts
Definition: pg_amcheck.c:112
#define printf(...)
Definition: port.h:244

References errmsg(), fprintf, _PQconninfoOption::keyword, opts, PQconndefaults(), PQconninfoParse(), printf, and _PQconninfoOption::val.