PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
config_info.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * config_info.c
4  * Common code for pg_config output
5  *
6  *
7  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  *
11  * IDENTIFICATION
12  * src/common/config_info.c
13  *
14  *-------------------------------------------------------------------------
15  */
16 
17 #ifndef FRONTEND
18 #include "postgres.h"
19 #else
20 #include "postgres_fe.h"
21 #endif
22 
23 #include "common/config_info.h"
24 #include "miscadmin.h"
25 
26 
27 /*
28  * get_configdata(const char *my_exec_path, size_t *configdata_len)
29  *
30  * Get configure-time constants. The caller is responsible
31  * for pfreeing the result.
32  */
33 ConfigData *
34 get_configdata(const char *my_exec_path, size_t *configdata_len)
35 {
36  ConfigData *configdata;
37  char path[MAXPGPATH];
38  char *lastsep;
39  int i = 0;
40 
41  /* Adjust this to match the number of items filled below */
42  *configdata_len = 23;
43  configdata = (ConfigData *) palloc(*configdata_len * sizeof(ConfigData));
44 
45  configdata[i].name = pstrdup("BINDIR");
46  strlcpy(path, my_exec_path, sizeof(path));
47  lastsep = strrchr(path, '/');
48  if (lastsep)
49  *lastsep = '\0';
50  cleanup_path(path);
51  configdata[i].setting = pstrdup(path);
52  i++;
53 
54  configdata[i].name = pstrdup("DOCDIR");
55  get_doc_path(my_exec_path, path);
56  cleanup_path(path);
57  configdata[i].setting = pstrdup(path);
58  i++;
59 
60  configdata[i].name = pstrdup("HTMLDIR");
61  get_html_path(my_exec_path, path);
62  cleanup_path(path);
63  configdata[i].setting = pstrdup(path);
64  i++;
65 
66  configdata[i].name = pstrdup("INCLUDEDIR");
67  get_include_path(my_exec_path, path);
68  cleanup_path(path);
69  configdata[i].setting = pstrdup(path);
70  i++;
71 
72  configdata[i].name = pstrdup("PKGINCLUDEDIR");
73  get_pkginclude_path(my_exec_path, path);
74  cleanup_path(path);
75  configdata[i].setting = pstrdup(path);
76  i++;
77 
78  configdata[i].name = pstrdup("INCLUDEDIR-SERVER");
79  get_includeserver_path(my_exec_path, path);
80  cleanup_path(path);
81  configdata[i].setting = pstrdup(path);
82  i++;
83 
84  configdata[i].name = pstrdup("LIBDIR");
85  get_lib_path(my_exec_path, path);
86  cleanup_path(path);
87  configdata[i].setting = pstrdup(path);
88  i++;
89 
90  configdata[i].name = pstrdup("PKGLIBDIR");
91  get_pkglib_path(my_exec_path, path);
92  cleanup_path(path);
93  configdata[i].setting = pstrdup(path);
94  i++;
95 
96  configdata[i].name = pstrdup("LOCALEDIR");
97  get_locale_path(my_exec_path, path);
98  cleanup_path(path);
99  configdata[i].setting = pstrdup(path);
100  i++;
101 
102  configdata[i].name = pstrdup("MANDIR");
103  get_man_path(my_exec_path, path);
104  cleanup_path(path);
105  configdata[i].setting = pstrdup(path);
106  i++;
107 
108  configdata[i].name = pstrdup("SHAREDIR");
109  get_share_path(my_exec_path, path);
110  cleanup_path(path);
111  configdata[i].setting = pstrdup(path);
112  i++;
113 
114  configdata[i].name = pstrdup("SYSCONFDIR");
115  get_etc_path(my_exec_path, path);
116  cleanup_path(path);
117  configdata[i].setting = pstrdup(path);
118  i++;
119 
120  configdata[i].name = pstrdup("PGXS");
121  get_pkglib_path(my_exec_path, path);
122  strlcat(path, "/pgxs/src/makefiles/pgxs.mk", sizeof(path));
123  cleanup_path(path);
124  configdata[i].setting = pstrdup(path);
125  i++;
126 
127  configdata[i].name = pstrdup("CONFIGURE");
128 #ifdef VAL_CONFIGURE
129  configdata[i].setting = pstrdup(VAL_CONFIGURE);
130 #else
131  configdata[i].setting = pstrdup(_("not recorded"));
132 #endif
133  i++;
134 
135  configdata[i].name = pstrdup("CC");
136 #ifdef VAL_CC
137  configdata[i].setting = pstrdup(VAL_CC);
138 #else
139  configdata[i].setting = pstrdup(_("not recorded"));
140 #endif
141  i++;
142 
143  configdata[i].name = pstrdup("CPPFLAGS");
144 #ifdef VAL_CPPFLAGS
145  configdata[i].setting = pstrdup(VAL_CPPFLAGS);
146 #else
147  configdata[i].setting = pstrdup(_("not recorded"));
148 #endif
149  i++;
150 
151  configdata[i].name = pstrdup("CFLAGS");
152 #ifdef VAL_CFLAGS
153  configdata[i].setting = pstrdup(VAL_CFLAGS);
154 #else
155  configdata[i].setting = pstrdup(_("not recorded"));
156 #endif
157  i++;
158 
159  configdata[i].name = pstrdup("CFLAGS_SL");
160 #ifdef VAL_CFLAGS_SL
161  configdata[i].setting = pstrdup(VAL_CFLAGS_SL);
162 #else
163  configdata[i].setting = pstrdup(_("not recorded"));
164 #endif
165  i++;
166 
167  configdata[i].name = pstrdup("LDFLAGS");
168 #ifdef VAL_LDFLAGS
169  configdata[i].setting = pstrdup(VAL_LDFLAGS);
170 #else
171  configdata[i].setting = pstrdup(_("not recorded"));
172 #endif
173  i++;
174 
175  configdata[i].name = pstrdup("LDFLAGS_EX");
176 #ifdef VAL_LDFLAGS_EX
177  configdata[i].setting = pstrdup(VAL_LDFLAGS_EX);
178 #else
179  configdata[i].setting = pstrdup(_("not recorded"));
180 #endif
181  i++;
182 
183  configdata[i].name = pstrdup("LDFLAGS_SL");
184 #ifdef VAL_LDFLAGS_SL
185  configdata[i].setting = pstrdup(VAL_LDFLAGS_SL);
186 #else
187  configdata[i].setting = pstrdup(_("not recorded"));
188 #endif
189  i++;
190 
191  configdata[i].name = pstrdup("LIBS");
192 #ifdef VAL_LIBS
193  configdata[i].setting = pstrdup(VAL_LIBS);
194 #else
195  configdata[i].setting = pstrdup(_("not recorded"));
196 #endif
197  i++;
198 
199  configdata[i].name = pstrdup("VERSION");
200  configdata[i].setting = pstrdup("PostgreSQL " PG_VERSION);
201  i++;
202 
203  Assert(i == *configdata_len);
204 
205  return configdata;
206 }
void get_includeserver_path(const char *my_exec_path, char *ret_path)
Definition: path.c:740
char * pstrdup(const char *in)
Definition: mcxt.c:1077
void get_pkglib_path(const char *my_exec_path, char *ret_path)
Definition: path.c:758
char * name
Definition: config_info.h:14
char * setting
Definition: config_info.h:15
void get_lib_path(const char *my_exec_path, char *ret_path)
Definition: path.c:749
void get_pkginclude_path(const char *my_exec_path, char *ret_path)
Definition: path.c:731
#define MAXPGPATH
void get_doc_path(const char *my_exec_path, char *ret_path)
Definition: path.c:776
void cleanup_path(char *path)
Definition: path.c:185
char my_exec_path[MAXPGPATH]
Definition: globals.c:64
void get_etc_path(const char *my_exec_path, char *ret_path)
Definition: path.c:713
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
#define Assert(condition)
Definition: c.h:675
ConfigData * get_configdata(const char *my_exec_path, size_t *configdata_len)
Definition: config_info.c:34
void get_html_path(const char *my_exec_path, char *ret_path)
Definition: path.c:785
void get_man_path(const char *my_exec_path, char *ret_path)
Definition: path.c:794
void get_include_path(const char *my_exec_path, char *ret_path)
Definition: path.c:722
void * palloc(Size size)
Definition: mcxt.c:849
int i
void get_locale_path(const char *my_exec_path, char *ret_path)
Definition: path.c:767
void get_share_path(const char *my_exec_path, char *ret_path)
Definition: path.c:704
#define _(x)
Definition: elog.c:84
size_t strlcat(char *dst, const char *src, size_t siz)
Definition: strlcat.c:33