17
17
*
18
18
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
19
19
*
20
- * $PostgreSQL: pgsql/src/bin/pg_config/pg_config.c,v 1.13 2005/09/27 17:39:33 tgl Exp $
20
+ * $PostgreSQL: pgsql/src/bin/pg_config/pg_config.c,v 1.14 2005/10/05 12:16:28 momjian Exp $
21
21
*
22
22
*-------------------------------------------------------------------------
23
23
*/
@@ -30,6 +30,64 @@ static const char *progname;
30
30
static char mypath [MAXPGPATH ];
31
31
32
32
33
+ /*
34
+ * This function cleans up the paths for use with either cmd.exe or Msys
35
+ * on Windows. We need them to use double backslashes and filenames without
36
+ * spaces (for which a short filename is the safest equivalent) eg:
37
+ * C:\\Progra~1\\
38
+ *
39
+ * This can fail in 2 ways - if the path doesn't exist, or short names are
40
+ * disabled. In the first case, don't return any path. In the second case,
41
+ * we leave the path in the long form. In this case, it does still seem to
42
+ * fix elements containing spaces which is all we actually need.
43
+ */
44
+ static void
45
+ cleanup_path (char * path )
46
+ {
47
+ #ifdef WIN32
48
+ int x = 0 , y = 0 ;
49
+ char temp [MAXPGPATH ];
50
+
51
+ if (GetShortPathName (path , path , MAXPGPATH - 1 ) == 0 )
52
+ {
53
+ /* Ignore ERROR_INVALID_PARAMETER as it almost certainly
54
+ * means that short names are disabled
55
+ */
56
+ if (GetLastError () != ERROR_INVALID_PARAMETER )
57
+ {
58
+ path [0 ] = '\0' ;
59
+ return ;
60
+ }
61
+ }
62
+
63
+
64
+ /* Replace '\' with '\\'. */
65
+ for (x = 0 ; x < strlen (path ); x ++ )
66
+ {
67
+ if (path [x ] == '/' || path [x ] == '\\' )
68
+ {
69
+ temp [y ] = '\\' ;
70
+ y ++ ;
71
+ temp [y ] = '\\' ;
72
+ }
73
+ else
74
+ {
75
+ temp [y ] = path [x ];
76
+ }
77
+
78
+ y ++ ;
79
+
80
+ /* Bail out if we're too close to MAXPGPATH */
81
+ if (y >= MAXPGPATH - 2 )
82
+ break ;
83
+ }
84
+ temp [y ] = '\0' ;
85
+
86
+ strncpy (path , temp , MAXPGPATH - 1 );
87
+ #endif
88
+ }
89
+
90
+
33
91
/*
34
92
* For each piece of information known to pg_config, we define a subroutine
35
93
* to print it. This is probably overkill, but it avoids code duplication
@@ -39,138 +97,152 @@ static char mypath[MAXPGPATH];
39
97
static void
40
98
show_bindir (bool all )
41
99
{
42
- char path [MAXPGPATH ];
43
- char * lastsep ;
100
+ char path [MAXPGPATH ];
101
+ char * lastsep ;
44
102
45
103
if (all )
46
104
printf ("BINDIR = " );
47
105
/* assume we are located in the bindir */
48
106
strcpy (path , mypath );
49
107
lastsep = strrchr (path , '/' );
108
+
50
109
if (lastsep )
51
110
* lastsep = '\0' ;
111
+
112
+ cleanup_path (path );
52
113
printf ("%s\n" , path );
53
114
}
54
115
55
116
static void
56
117
show_docdir (bool all )
57
118
{
58
- char path [MAXPGPATH ];
119
+ char path [MAXPGPATH ];
59
120
60
121
if (all )
61
122
printf ("DOCDIR = " );
62
123
get_doc_path (mypath , path );
124
+ cleanup_path (path );
63
125
printf ("%s\n" , path );
64
126
}
65
127
66
128
static void
67
129
show_includedir (bool all )
68
130
{
69
- char path [MAXPGPATH ];
131
+ char path [MAXPGPATH ];
70
132
71
133
if (all )
72
134
printf ("INCLUDEDIR = " );
73
135
get_include_path (mypath , path );
136
+ cleanup_path (path );
74
137
printf ("%s\n" , path );
75
138
}
76
139
77
140
static void
78
141
show_pkgincludedir (bool all )
79
142
{
80
- char path [MAXPGPATH ];
143
+ char path [MAXPGPATH ];
81
144
82
145
if (all )
83
146
printf ("PKGINCLUDEDIR = " );
84
147
get_pkginclude_path (mypath , path );
148
+ cleanup_path (path );
85
149
printf ("%s\n" , path );
86
150
}
87
151
88
152
static void
89
153
show_includedir_server (bool all )
90
154
{
91
- char path [MAXPGPATH ];
155
+ char path [MAXPGPATH ];
92
156
93
157
if (all )
94
158
printf ("INCLUDEDIR-SERVER = " );
95
159
get_includeserver_path (mypath , path );
160
+ cleanup_path (path );
96
161
printf ("%s\n" , path );
97
162
}
98
163
99
164
static void
100
165
show_libdir (bool all )
101
166
{
102
- char path [MAXPGPATH ];
167
+ char path [MAXPGPATH ];
103
168
104
169
if (all )
105
170
printf ("LIBDIR = " );
106
171
get_lib_path (mypath , path );
172
+ cleanup_path (path );
107
173
printf ("%s\n" , path );
108
174
}
109
175
110
176
static void
111
177
show_pkglibdir (bool all )
112
178
{
113
- char path [MAXPGPATH ];
179
+ char path [MAXPGPATH ];
114
180
115
181
if (all )
116
182
printf ("PKGLIBDIR = " );
117
183
get_pkglib_path (mypath , path );
184
+ cleanup_path (path );
118
185
printf ("%s\n" , path );
119
186
}
120
187
121
188
static void
122
189
show_localedir (bool all )
123
190
{
124
- char path [MAXPGPATH ];
191
+ char path [MAXPGPATH ];
125
192
126
193
if (all )
127
194
printf ("LOCALEDIR = " );
128
195
get_locale_path (mypath , path );
196
+ cleanup_path (path );
129
197
printf ("%s\n" , path );
130
198
}
131
199
132
200
static void
133
201
show_mandir (bool all )
134
202
{
135
- char path [MAXPGPATH ];
203
+ char path [MAXPGPATH ];
136
204
137
205
if (all )
138
206
printf ("MANDIR = " );
139
207
get_man_path (mypath , path );
208
+ cleanup_path (path );
140
209
printf ("%s\n" , path );
141
210
}
142
211
143
212
static void
144
213
show_sharedir (bool all )
145
214
{
146
- char path [MAXPGPATH ];
215
+ char path [MAXPGPATH ];
147
216
148
217
if (all )
149
218
printf ("SHAREDIR = " );
150
219
get_share_path (mypath , path );
220
+ cleanup_path (path );
151
221
printf ("%s\n" , path );
152
222
}
153
223
154
224
static void
155
225
show_sysconfdir (bool all )
156
226
{
157
- char path [MAXPGPATH ];
227
+ char path [MAXPGPATH ];
158
228
159
229
if (all )
160
230
printf ("SYSCONFDIR = " );
161
231
get_etc_path (mypath , path );
232
+ cleanup_path (path );
162
233
printf ("%s\n" , path );
163
234
}
164
235
165
236
static void
166
237
show_pgxs (bool all )
167
238
{
168
- char path [MAXPGPATH ];
239
+ char path [MAXPGPATH ];
169
240
170
241
if (all )
171
242
printf ("PGXS = " );
172
243
get_pkglib_path (mypath , path );
173
244
strncat (path , "/pgxs/src/makefiles/pgxs.mk" , MAXPGPATH - 1 );
245
+ cleanup_path (path );
174
246
printf ("%s\n" , path );
175
247
}
176
248
0 commit comments