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

Commit2a70ec1

Browse files
committed
Allow relative paths as long as the hardcoded path matches the bin path
up to the last bin directory name.
1 parentbfb77c1 commit2a70ec1

File tree

1 file changed

+67
-81
lines changed

1 file changed

+67
-81
lines changed

‎src/port/path.c

Lines changed: 67 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/port/path.c,v 1.14 2004/05/2518:18:29 momjian Exp $
11+
* $PostgreSQL: pgsql/src/port/path.c,v 1.15 2004/05/2520:47:41 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -26,7 +26,7 @@
2626
#defineISSEP(ch)((ch) == '/' || (ch) == '\\')
2727
#endif
2828

29-
staticboolrelative_path(constchar*path1,constchar*path2);
29+
conststaticchar*relative_path(constchar*bin_path,constchar*other_path);
3030
staticvoidtrim_directory(char*path);
3131
staticvoidtrim_trailing_separator(char*path);
3232

@@ -37,6 +37,14 @@ static void trim_trailing_separator(char *path);
3737
(p)++; \
3838
}
3939

40+
/* Macro creates a relative path */
41+
#defineMAKE_RELATIVE \
42+
do { \
43+
StrNCpy(path, my_exec_path, MAXPGPATH); \
44+
trim_directory(path); \
45+
trim_directory(path); \
46+
snprintf(ret_path, MAXPGPATH, "%s/%s", path, p); \
47+
} while (0)
4048

4149
/*
4250
*first_path_separator
@@ -114,14 +122,10 @@ void
114122
get_share_path(constchar*my_exec_path,char*ret_path)
115123
{
116124
charpath[MAXPGPATH];
125+
constchar*p;
117126

118-
if (relative_path(PGBINDIR,PGSHAREDIR))
119-
{
120-
StrNCpy(path,my_exec_path,MAXPGPATH);
121-
trim_directory(path);/* trim off binary */
122-
trim_directory(path);/* trim off /bin */
123-
snprintf(ret_path,MAXPGPATH,"%s/share",path);
124-
}
127+
if ((p=relative_path(PGBINDIR,PGSHAREDIR)))
128+
MAKE_RELATIVE;
125129
else
126130
StrNCpy(ret_path,PGSHAREDIR,MAXPGPATH);
127131
}
@@ -135,14 +139,10 @@ void
135139
get_etc_path(constchar*my_exec_path,char*ret_path)
136140
{
137141
charpath[MAXPGPATH];
142+
constchar*p;
138143

139-
if (relative_path(PGBINDIR,SYSCONFDIR))
140-
{
141-
StrNCpy(path,my_exec_path,MAXPGPATH);
142-
trim_directory(path);
143-
trim_directory(path);
144-
snprintf(ret_path,MAXPGPATH,"%s/etc",path);
145-
}
144+
if ((p=relative_path(PGBINDIR,SYSCONFDIR)))
145+
MAKE_RELATIVE;
146146
else
147147
StrNCpy(ret_path,SYSCONFDIR,MAXPGPATH);
148148
}
@@ -156,14 +156,10 @@ void
156156
get_include_path(constchar*my_exec_path,char*ret_path)
157157
{
158158
charpath[MAXPGPATH];
159+
constchar*p;
159160

160-
if (relative_path(PGBINDIR,INCLUDEDIR))
161-
{
162-
StrNCpy(path,my_exec_path,MAXPGPATH);
163-
trim_directory(path);
164-
trim_directory(path);
165-
snprintf(ret_path,MAXPGPATH,"%s/include",path);
166-
}
161+
if ((p=relative_path(PGBINDIR,INCLUDEDIR)))
162+
MAKE_RELATIVE;
167163
else
168164
StrNCpy(ret_path,INCLUDEDIR,MAXPGPATH);
169165
}
@@ -177,14 +173,10 @@ void
177173
get_pkginclude_path(constchar*my_exec_path,char*ret_path)
178174
{
179175
charpath[MAXPGPATH];
176+
constchar*p;
180177

181-
if (relative_path(PGBINDIR,PKGINCLUDEDIR))
182-
{
183-
StrNCpy(path,my_exec_path,MAXPGPATH);
184-
trim_directory(path);
185-
trim_directory(path);
186-
snprintf(ret_path,MAXPGPATH,"%s/include",path);
187-
}
178+
if ((p=relative_path(PGBINDIR,PKGINCLUDEDIR)))
179+
MAKE_RELATIVE;
188180
else
189181
StrNCpy(ret_path,PKGINCLUDEDIR,MAXPGPATH);
190182
}
@@ -200,14 +192,10 @@ void
200192
get_pkglib_path(constchar*my_exec_path,char*ret_path)
201193
{
202194
charpath[MAXPGPATH];
195+
constchar*p;
203196

204-
if (relative_path(PGBINDIR,PKGLIBDIR))
205-
{
206-
StrNCpy(path,my_exec_path,MAXPGPATH);
207-
trim_directory(path);
208-
trim_directory(path);
209-
snprintf(ret_path,MAXPGPATH,"%s/lib",path);
210-
}
197+
if ((p=relative_path(PGBINDIR,PKGLIBDIR)))
198+
MAKE_RELATIVE;
211199
else
212200
StrNCpy(ret_path,PKGLIBDIR,MAXPGPATH);
213201
}
@@ -223,14 +211,10 @@ void
223211
get_locale_path(constchar*my_exec_path,char*ret_path)
224212
{
225213
charpath[MAXPGPATH];
214+
constchar*p;
226215

227-
if (relative_path(PGBINDIR,LOCALEDIR))
228-
{
229-
StrNCpy(path,my_exec_path,MAXPGPATH);
230-
trim_directory(path);
231-
trim_directory(path);
232-
snprintf(ret_path,MAXPGPATH,"%s/share/locale",path);
233-
}
216+
if ((p=relative_path(PGBINDIR,LOCALEDIR)))
217+
MAKE_RELATIVE;
234218
else
235219
StrNCpy(ret_path,LOCALEDIR,MAXPGPATH);
236220
}
@@ -271,68 +255,71 @@ set_pglocale(const char *argv0, const char *app)
271255
*
272256
*Do the supplied paths differ only in their last component?
273257
*/
274-
staticbool
275-
relative_path(constchar*path1,constchar*path2)
258+
staticconstchar*
259+
relative_path(constchar*bin_path,constchar*other_path)
276260
{
277-
261+
constchar*other_sep=other_path;
262+
278263
#ifdefWIN32
279264
/* Driver letters match? */
280-
if (isalpha(*path1)&&path1[1]==':'&&
281-
(!isalpha(*path2)|| !path2[1]==':'))
282-
returnfalse;
283-
if ((!isalpha(*path1)|| !path1[1]==':')&&
284-
(isalpha(*path2)&&path2[1]==':'))
285-
returnfalse;
286-
if (isalpha(*path1)&&path1[1]==':'&&
287-
isalpha(*path2)&&path2[1]==':')
265+
if (isalpha(*bin_path)&&bin_path[1]==':'&&
266+
(!isalpha(*other_path)|| !other_path[1]==':'))
267+
returnNULL;
268+
if ((!isalpha(*bin_path)|| !bin_path[1]==':')&&
269+
(isalpha(*other_path)&&other_path[1]==':'))
270+
returnNULL;
271+
if (isalpha(*bin_path)&&bin_path[1]==':'&&
272+
isalpha(*other_path)&&other_path[1]==':')
288273
{
289-
if (toupper(*path1)!=toupper(*path2))
290-
return false;
291-
path1+=2;
292-
path2+=2;
274+
if (toupper(*bin_path)!=toupper(*other_path))
275+
returnNULL;
276+
bin_path+=2;
277+
other_path+=2;
278+
other_sep=other_path+1;/* past separator */
293279
}
294280
#endif
295281

296282
while (1)
297283
{
298284
/* Move past adjacent slashes like //, and trailing ones */
299-
MOVE_TO_SEP_END(path1);
300-
MOVE_TO_SEP_END(path2);
285+
MOVE_TO_SEP_END(bin_path);
286+
MOVE_TO_SEP_END(other_path);
301287

302288
/* One of the paths is done? */
303-
if (!*path1|| !*path2)
289+
if (!*bin_path|| !*other_path)
304290
break;
305291

306292
/* Win32 filesystem is case insensitive */
293+
if ((!ISSEP(*bin_path)|| !ISSEP(*other_path))&&
307294
#ifndefWIN32
308-
if (*path1!=*path2)
295+
*bin_path!=*other_path)
309296
#else
310-
if (toupper((unsignedchar)*path1)!=toupper((unsignedchar)*path2))
297+
toupper((unsignedchar)*bin_path)!=toupper((unsignedchar)*other_path))
311298
#endif
312-
break;
299+
break;
313300

314-
path1++;
315-
path2++;
301+
if (ISSEP(*other_path))
302+
other_sep=other_path+1;/* past separator */
303+
304+
bin_path++;
305+
other_path++;
316306
}
317307

318-
/*both done,identical? */
319-
if (!*path1&& !*path2)
320-
returnfalse;
308+
/* identical? */
309+
if (!*bin_path&& !*other_path)
310+
returnNULL;
321311

322312
/* advance past directory name */
323-
while (!ISSEP(*path1)&&*path1)
324-
path1++;
325-
while (!ISSEP(*path2)&&*path2)
326-
path2++;
313+
while (!ISSEP(*bin_path)&&*bin_path)
314+
bin_path++;
327315

328-
MOVE_TO_SEP_END(path1);
329-
MOVE_TO_SEP_END(path2);
316+
MOVE_TO_SEP_END(bin_path);
330317

331-
/*Are both strings done? */
332-
if (!*path1&& !*path2)
333-
returntrue;
318+
/*Is bin done? */
319+
if (!*bin_path)
320+
returnother_path;
334321
else
335-
returnfalse;
322+
returnNULL;
336323
}
337324

338325

@@ -372,4 +359,3 @@ trim_trailing_separator(char *path)
372359
for (p--;p >=path&&ISSEP(*p);p--)
373360
*p='\0';
374361
}
375-

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp