Skip to content

Commit f39cfbe

Browse files
committed
Fix pgxs for spaces in file names on Win32
Dave Page
1 parent 0f397b9 commit f39cfbe

File tree

1 file changed

+86
-14
lines changed

1 file changed

+86
-14
lines changed

src/bin/pg_config/pg_config.c

Lines changed: 86 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
1919
*
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 $
2121
*
2222
*-------------------------------------------------------------------------
2323
*/
@@ -30,6 +30,64 @@ static const char *progname;
3030
static char mypath[MAXPGPATH];
3131

3232

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+
3391
/*
3492
* For each piece of information known to pg_config, we define a subroutine
3593
* to print it. This is probably overkill, but it avoids code duplication
@@ -39,138 +97,152 @@ static char mypath[MAXPGPATH];
3997
static void
4098
show_bindir(bool all)
4199
{
42-
char path[MAXPGPATH];
43-
char *lastsep;
100+
char path[MAXPGPATH];
101+
char *lastsep;
44102

45103
if (all)
46104
printf("BINDIR = ");
47105
/* assume we are located in the bindir */
48106
strcpy(path, mypath);
49107
lastsep = strrchr(path, '/');
108+
50109
if (lastsep)
51110
*lastsep = '\0';
111+
112+
cleanup_path(path);
52113
printf("%s\n", path);
53114
}
54115

55116
static void
56117
show_docdir(bool all)
57118
{
58-
char path[MAXPGPATH];
119+
char path[MAXPGPATH];
59120

60121
if (all)
61122
printf("DOCDIR = ");
62123
get_doc_path(mypath, path);
124+
cleanup_path(path);
63125
printf("%s\n", path);
64126
}
65127

66128
static void
67129
show_includedir(bool all)
68130
{
69-
char path[MAXPGPATH];
131+
char path[MAXPGPATH];
70132

71133
if (all)
72134
printf("INCLUDEDIR = ");
73135
get_include_path(mypath, path);
136+
cleanup_path(path);
74137
printf("%s\n", path);
75138
}
76139

77140
static void
78141
show_pkgincludedir(bool all)
79142
{
80-
char path[MAXPGPATH];
143+
char path[MAXPGPATH];
81144

82145
if (all)
83146
printf("PKGINCLUDEDIR = ");
84147
get_pkginclude_path(mypath, path);
148+
cleanup_path(path);
85149
printf("%s\n", path);
86150
}
87151

88152
static void
89153
show_includedir_server(bool all)
90154
{
91-
char path[MAXPGPATH];
155+
char path[MAXPGPATH];
92156

93157
if (all)
94158
printf("INCLUDEDIR-SERVER = ");
95159
get_includeserver_path(mypath, path);
160+
cleanup_path(path);
96161
printf("%s\n", path);
97162
}
98163

99164
static void
100165
show_libdir(bool all)
101166
{
102-
char path[MAXPGPATH];
167+
char path[MAXPGPATH];
103168

104169
if (all)
105170
printf("LIBDIR = ");
106171
get_lib_path(mypath, path);
172+
cleanup_path(path);
107173
printf("%s\n", path);
108174
}
109175

110176
static void
111177
show_pkglibdir(bool all)
112178
{
113-
char path[MAXPGPATH];
179+
char path[MAXPGPATH];
114180

115181
if (all)
116182
printf("PKGLIBDIR = ");
117183
get_pkglib_path(mypath, path);
184+
cleanup_path(path);
118185
printf("%s\n", path);
119186
}
120187

121188
static void
122189
show_localedir(bool all)
123190
{
124-
char path[MAXPGPATH];
191+
char path[MAXPGPATH];
125192

126193
if (all)
127194
printf("LOCALEDIR = ");
128195
get_locale_path(mypath, path);
196+
cleanup_path(path);
129197
printf("%s\n", path);
130198
}
131199

132200
static void
133201
show_mandir(bool all)
134202
{
135-
char path[MAXPGPATH];
203+
char path[MAXPGPATH];
136204

137205
if (all)
138206
printf("MANDIR = ");
139207
get_man_path(mypath, path);
208+
cleanup_path(path);
140209
printf("%s\n", path);
141210
}
142211

143212
static void
144213
show_sharedir(bool all)
145214
{
146-
char path[MAXPGPATH];
215+
char path[MAXPGPATH];
147216

148217
if (all)
149218
printf("SHAREDIR = ");
150219
get_share_path(mypath, path);
220+
cleanup_path(path);
151221
printf("%s\n", path);
152222
}
153223

154224
static void
155225
show_sysconfdir(bool all)
156226
{
157-
char path[MAXPGPATH];
227+
char path[MAXPGPATH];
158228

159229
if (all)
160230
printf("SYSCONFDIR = ");
161231
get_etc_path(mypath, path);
232+
cleanup_path(path);
162233
printf("%s\n", path);
163234
}
164235

165236
static void
166237
show_pgxs(bool all)
167238
{
168-
char path[MAXPGPATH];
239+
char path[MAXPGPATH];
169240

170241
if (all)
171242
printf("PGXS = ");
172243
get_pkglib_path(mypath, path);
173244
strncat(path, "/pgxs/src/makefiles/pgxs.mk", MAXPGPATH - 1);
245+
cleanup_path(path);
174246
printf("%s\n", path);
175247
}
176248

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy