|
20 | 20 | #include "postgres_fe.h"
|
21 | 21 | #endif
|
22 | 22 |
|
23 |
| -#include "miscadmin.h" |
24 | 23 | #include "common/config_info.h"
|
| 24 | +#include "miscadmin.h" |
25 | 25 |
|
26 |
| -static size_t configdata_names_len(void); |
27 |
| - |
28 |
| -static const char *const configdata_names[] = |
29 |
| -{ |
30 |
| - "BINDIR", |
31 |
| - "DOCDIR", |
32 |
| - "HTMLDIR", |
33 |
| - "INCLUDEDIR", |
34 |
| - "PKGINCLUDEDIR", |
35 |
| - "INCLUDEDIR-SERVER", |
36 |
| - "LIBDIR", |
37 |
| - "PKGLIBDIR", |
38 |
| - "LOCALEDIR", |
39 |
| - "MANDIR", |
40 |
| - "SHAREDIR", |
41 |
| - "SYSCONFDIR", |
42 |
| - "PGXS", |
43 |
| - "CONFIGURE", |
44 |
| - "CC", |
45 |
| - "CPPFLAGS", |
46 |
| - "CFLAGS", |
47 |
| - "CFLAGS_SL", |
48 |
| - "LDFLAGS", |
49 |
| - "LDFLAGS_EX", |
50 |
| - "LDFLAGS_SL", |
51 |
| - "LIBS", |
52 |
| - "VERSION", |
53 |
| - NULL |
54 |
| -}; |
55 |
| - |
56 |
| -static size_t |
57 |
| -configdata_names_len(void) |
58 |
| -{ |
59 |
| - size_t i = 0; |
60 |
| - |
61 |
| - while (configdata_names[i]) |
62 |
| - i++; |
63 |
| - |
64 |
| - return i; |
65 |
| -} |
66 | 26 |
|
67 | 27 | /*
|
68 |
| - * get_configdata(char *my_exec_path, size_t *configdata_len) |
| 28 | + * get_configdata(const char *my_exec_path, size_t *configdata_len) |
69 | 29 | *
|
70 | 30 | * Get configure-time constants. The caller is responsible
|
71 | 31 | * for pfreeing the result.
|
72 | 32 | */
|
73 | 33 | ConfigData *
|
74 |
| -get_configdata(char *my_exec_path, size_t *configdata_len) |
| 34 | +get_configdata(const char *my_exec_path, size_t *configdata_len) |
75 | 35 | {
|
76 | 36 | ConfigData *configdata;
|
77 | 37 | char path[MAXPGPATH];
|
78 | 38 | char *lastsep;
|
79 |
| - int i; |
| 39 | + int i = 0; |
80 | 40 |
|
81 |
| - *configdata_len = configdata_names_len(); |
82 |
| - configdata = palloc(*configdata_len * sizeof(ConfigData)); |
| 41 | + /* Adjust this to match the number of items filled below */ |
| 42 | + *configdata_len = 23; |
| 43 | + configdata = (ConfigData *) palloc(*configdata_len * sizeof(ConfigData)); |
83 | 44 |
|
84 |
| - /* |
85 |
| - * initialize configdata names |
86 |
| - * |
87 |
| - * These better be in sync with the settings manually |
88 |
| - * defined below. |
89 |
| - */ |
90 |
| - for (i = 0; i < *configdata_len; i++) |
91 |
| - configdata[i].name = pstrdup(configdata_names[i]); |
92 |
| - |
93 |
| - strcpy(path, my_exec_path); |
| 45 | + configdata[i].name = pstrdup("BINDIR"); |
| 46 | + strlcpy(path, my_exec_path, sizeof(path)); |
94 | 47 | lastsep = strrchr(path, '/');
|
95 | 48 | if (lastsep)
|
96 | 49 | *lastsep = '\0';
|
97 | 50 | cleanup_path(path);
|
98 |
| - configdata[0].setting = pstrdup(path); |
| 51 | + configdata[i].setting = pstrdup(path); |
| 52 | + i++; |
99 | 53 |
|
| 54 | + configdata[i].name = pstrdup("DOCDIR"); |
100 | 55 | get_doc_path(my_exec_path, path);
|
101 | 56 | cleanup_path(path);
|
102 |
| - configdata[1].setting = pstrdup(path); |
| 57 | + configdata[i].setting = pstrdup(path); |
| 58 | + i++; |
103 | 59 |
|
| 60 | + configdata[i].name = pstrdup("HTMLDIR"); |
104 | 61 | get_html_path(my_exec_path, path);
|
105 | 62 | cleanup_path(path);
|
106 |
| - configdata[2].setting = pstrdup(path); |
| 63 | + configdata[i].setting = pstrdup(path); |
| 64 | + i++; |
107 | 65 |
|
| 66 | + configdata[i].name = pstrdup("INCLUDEDIR"); |
108 | 67 | get_include_path(my_exec_path, path);
|
109 | 68 | cleanup_path(path);
|
110 |
| - configdata[3].setting = pstrdup(path); |
| 69 | + configdata[i].setting = pstrdup(path); |
| 70 | + i++; |
111 | 71 |
|
| 72 | + configdata[i].name = pstrdup("PKGINCLUDEDIR"); |
112 | 73 | get_pkginclude_path(my_exec_path, path);
|
113 | 74 | cleanup_path(path);
|
114 |
| - configdata[4].setting = pstrdup(path); |
| 75 | + configdata[i].setting = pstrdup(path); |
| 76 | + i++; |
115 | 77 |
|
| 78 | + configdata[i].name = pstrdup("INCLUDEDIR-SERVER"); |
116 | 79 | get_includeserver_path(my_exec_path, path);
|
117 | 80 | cleanup_path(path);
|
118 |
| - configdata[5].setting = pstrdup(path); |
| 81 | + configdata[i].setting = pstrdup(path); |
| 82 | + i++; |
119 | 83 |
|
| 84 | + configdata[i].name = pstrdup("LIBDIR"); |
120 | 85 | get_lib_path(my_exec_path, path);
|
121 | 86 | cleanup_path(path);
|
122 |
| - configdata[6].setting = pstrdup(path); |
| 87 | + configdata[i].setting = pstrdup(path); |
| 88 | + i++; |
123 | 89 |
|
| 90 | + configdata[i].name = pstrdup("PKGLIBDIR"); |
124 | 91 | get_pkglib_path(my_exec_path, path);
|
125 | 92 | cleanup_path(path);
|
126 |
| - configdata[7].setting = pstrdup(path); |
| 93 | + configdata[i].setting = pstrdup(path); |
| 94 | + i++; |
127 | 95 |
|
| 96 | + configdata[i].name = pstrdup("LOCALEDIR"); |
128 | 97 | get_locale_path(my_exec_path, path);
|
129 | 98 | cleanup_path(path);
|
130 |
| - configdata[8].setting = pstrdup(path); |
| 99 | + configdata[i].setting = pstrdup(path); |
| 100 | + i++; |
131 | 101 |
|
| 102 | + configdata[i].name = pstrdup("MANDIR"); |
132 | 103 | get_man_path(my_exec_path, path);
|
133 | 104 | cleanup_path(path);
|
134 |
| - configdata[9].setting = pstrdup(path); |
| 105 | + configdata[i].setting = pstrdup(path); |
| 106 | + i++; |
135 | 107 |
|
| 108 | + configdata[i].name = pstrdup("SHAREDIR"); |
136 | 109 | get_share_path(my_exec_path, path);
|
137 | 110 | cleanup_path(path);
|
138 |
| - configdata[10].setting = pstrdup(path); |
| 111 | + configdata[i].setting = pstrdup(path); |
| 112 | + i++; |
139 | 113 |
|
| 114 | + configdata[i].name = pstrdup("SYSCONFDIR"); |
140 | 115 | get_etc_path(my_exec_path, path);
|
141 | 116 | cleanup_path(path);
|
142 |
| - configdata[11].setting = pstrdup(path); |
| 117 | + configdata[i].setting = pstrdup(path); |
| 118 | + i++; |
143 | 119 |
|
| 120 | + configdata[i].name = pstrdup("PGXS"); |
144 | 121 | get_pkglib_path(my_exec_path, path);
|
145 | 122 | strlcat(path, "/pgxs/src/makefiles/pgxs.mk", sizeof(path));
|
146 | 123 | cleanup_path(path);
|
147 |
| - configdata[12].setting = pstrdup(path); |
| 124 | + configdata[i].setting = pstrdup(path); |
| 125 | + i++; |
148 | 126 |
|
| 127 | + configdata[i].name = pstrdup("CONFIGURE"); |
149 | 128 | #ifdef VAL_CONFIGURE
|
150 |
| - configdata[13].setting = pstrdup(VAL_CONFIGURE); |
| 129 | + configdata[i].setting = pstrdup(VAL_CONFIGURE); |
151 | 130 | #else
|
152 |
| - configdata[13].setting = pstrdup(_("not recorded")); |
| 131 | + configdata[i].setting = pstrdup(_("not recorded")); |
153 | 132 | #endif
|
| 133 | + i++; |
154 | 134 |
|
| 135 | + configdata[i].name = pstrdup("CC"); |
155 | 136 | #ifdef VAL_CC
|
156 |
| - configdata[14].setting = pstrdup(VAL_CC); |
| 137 | + configdata[i].setting = pstrdup(VAL_CC); |
157 | 138 | #else
|
158 |
| - configdata[14].setting = pstrdup(_("not recorded")); |
| 139 | + configdata[i].setting = pstrdup(_("not recorded")); |
159 | 140 | #endif
|
| 141 | + i++; |
160 | 142 |
|
| 143 | + configdata[i].name = pstrdup("CPPFLAGS"); |
161 | 144 | #ifdef VAL_CPPFLAGS
|
162 |
| - configdata[15].setting = pstrdup(VAL_CPPFLAGS); |
| 145 | + configdata[i].setting = pstrdup(VAL_CPPFLAGS); |
163 | 146 | #else
|
164 |
| - configdata[15].setting = pstrdup(_("not recorded")); |
| 147 | + configdata[i].setting = pstrdup(_("not recorded")); |
165 | 148 | #endif
|
| 149 | + i++; |
166 | 150 |
|
| 151 | + configdata[i].name = pstrdup("CFLAGS"); |
167 | 152 | #ifdef VAL_CFLAGS
|
168 |
| - configdata[16].setting = pstrdup(VAL_CFLAGS); |
| 153 | + configdata[i].setting = pstrdup(VAL_CFLAGS); |
169 | 154 | #else
|
170 |
| - configdata[16].setting = pstrdup(_("not recorded")); |
| 155 | + configdata[i].setting = pstrdup(_("not recorded")); |
171 | 156 | #endif
|
| 157 | + i++; |
172 | 158 |
|
| 159 | + configdata[i].name = pstrdup("CFLAGS_SL"); |
173 | 160 | #ifdef VAL_CFLAGS_SL
|
174 |
| - configdata[17].setting = pstrdup(VAL_CFLAGS_SL); |
| 161 | + configdata[i].setting = pstrdup(VAL_CFLAGS_SL); |
175 | 162 | #else
|
176 |
| - configdata[17].setting = pstrdup(_("not recorded")); |
| 163 | + configdata[i].setting = pstrdup(_("not recorded")); |
177 | 164 | #endif
|
| 165 | + i++; |
178 | 166 |
|
| 167 | + configdata[i].name = pstrdup("LDFLAGS"); |
179 | 168 | #ifdef VAL_LDFLAGS
|
180 |
| - configdata[18].setting = pstrdup(VAL_LDFLAGS); |
| 169 | + configdata[i].setting = pstrdup(VAL_LDFLAGS); |
181 | 170 | #else
|
182 |
| - configdata[18].setting = pstrdup(_("not recorded")); |
| 171 | + configdata[i].setting = pstrdup(_("not recorded")); |
183 | 172 | #endif
|
| 173 | + i++; |
184 | 174 |
|
| 175 | + configdata[i].name = pstrdup("LDFLAGS_EX"); |
185 | 176 | #ifdef VAL_LDFLAGS_EX
|
186 |
| - configdata[19].setting = pstrdup(VAL_LDFLAGS_EX); |
| 177 | + configdata[i].setting = pstrdup(VAL_LDFLAGS_EX); |
187 | 178 | #else
|
188 |
| - configdata[19].setting = pstrdup(_("not recorded")); |
| 179 | + configdata[i].setting = pstrdup(_("not recorded")); |
189 | 180 | #endif
|
| 181 | + i++; |
190 | 182 |
|
| 183 | + configdata[i].name = pstrdup("LDFLAGS_SL"); |
191 | 184 | #ifdef VAL_LDFLAGS_SL
|
192 |
| - configdata[20].setting = pstrdup(VAL_LDFLAGS_SL); |
| 185 | + configdata[i].setting = pstrdup(VAL_LDFLAGS_SL); |
193 | 186 | #else
|
194 |
| - configdata[20].setting = pstrdup(_("not recorded")); |
| 187 | + configdata[i].setting = pstrdup(_("not recorded")); |
195 | 188 | #endif
|
| 189 | + i++; |
196 | 190 |
|
| 191 | + configdata[i].name = pstrdup("LIBS"); |
197 | 192 | #ifdef VAL_LIBS
|
198 |
| - configdata[21].setting = pstrdup(VAL_LIBS); |
| 193 | + configdata[i].setting = pstrdup(VAL_LIBS); |
199 | 194 | #else
|
200 |
| - configdata[21].setting = pstrdup(_("not recorded")); |
| 195 | + configdata[i].setting = pstrdup(_("not recorded")); |
201 | 196 | #endif
|
| 197 | + i++; |
| 198 | + |
| 199 | + configdata[i].name = pstrdup("VERSION"); |
| 200 | + configdata[i].setting = pstrdup("PostgreSQL " PG_VERSION); |
| 201 | + i++; |
202 | 202 |
|
203 |
| - configdata[22].setting = pstrdup("PostgreSQL " PG_VERSION); |
| 203 | + Assert(i == *configdata_len); |
204 | 204 |
|
205 | 205 | return configdata;
|
206 | 206 | }
|
0 commit comments