Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf39cfbe

Browse files
committed
Fix pgxs for spaces in file names on Win32
Dave Page
1 parent0f397b9 commitf39cfbe

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
staticcharmypath[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+
staticvoid
45+
cleanup_path(char*path)
46+
{
47+
#ifdefWIN32
48+
intx=0,y=0;
49+
chartemp[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 charmypath[MAXPGPATH];
3997
staticvoid
4098
show_bindir(boolall)
4199
{
42-
charpath[MAXPGPATH];
43-
char*lastsep;
100+
charpath[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
staticvoid
56117
show_docdir(boolall)
57118
{
58-
charpath[MAXPGPATH];
119+
charpath[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
staticvoid
67129
show_includedir(boolall)
68130
{
69-
charpath[MAXPGPATH];
131+
charpath[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
staticvoid
78141
show_pkgincludedir(boolall)
79142
{
80-
charpath[MAXPGPATH];
143+
charpath[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
staticvoid
89153
show_includedir_server(boolall)
90154
{
91-
charpath[MAXPGPATH];
155+
charpath[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
staticvoid
100165
show_libdir(boolall)
101166
{
102-
charpath[MAXPGPATH];
167+
charpath[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
staticvoid
111177
show_pkglibdir(boolall)
112178
{
113-
charpath[MAXPGPATH];
179+
charpath[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
staticvoid
122189
show_localedir(boolall)
123190
{
124-
charpath[MAXPGPATH];
191+
charpath[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
staticvoid
133201
show_mandir(boolall)
134202
{
135-
charpath[MAXPGPATH];
203+
charpath[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
staticvoid
144213
show_sharedir(boolall)
145214
{
146-
charpath[MAXPGPATH];
215+
charpath[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
staticvoid
155225
show_sysconfdir(boolall)
156226
{
157-
charpath[MAXPGPATH];
227+
charpath[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
staticvoid
166237
show_pgxs(boolall)
167238
{
168-
charpath[MAXPGPATH];
239+
charpath[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)

[8]ページ先頭

©2009-2025 Movatter.jp