Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6cc4175

Browse files
committed
Attached is a patch that takes care of the PATHSEP issue. I made a more
extensive change then what was suggested. I found the file path.c that contained a lot of "Unix/Windows" agnostic functions so I added a function there instead and removed the PATHSEP declaration in exec.c altogether. All to keep things from scattering all over the code. I also took the liberty of changing the name of the functions "first_path_sep" and "last_path_sep". Where I come from (and I'm apparently not alone given the former macro name PATHSEP), they should be called "first_dir_sep" and "last_dir_sep". The new function I introduced, that actually finds path separators, is now the "first_path_sep". The patch contains changes on all affected places of course. I also changed the documentation on dynamic_library_path to reflect the chagnes. Thomas Hallgren
1 parent d4117de commit 6cc4175

File tree

10 files changed

+85
-50
lines changed

10 files changed

+85
-50
lines changed

doc/src/sgml/runtime.sgml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.265 2004/05/26 18:51:43 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.266 2004/06/10 22:26:17 momjian Exp $
33
-->
44

55
<Chapter Id="runtime">
@@ -2617,8 +2617,9 @@ SET ENABLE_SEQSCAN TO OFF;
26172617
</para>
26182618

26192619
<para>
2620-
The value for <varname>dynamic_library_path</varname> has to be a colon-separated
2621-
list of absolute directory names. If a directory name starts
2620+
The value for <varname>dynamic_library_path</varname> has to be a
2621+
list of absolute directory names separated by colon or, in windows
2622+
environments with semi-colon. If a directory name starts
26222623
with the special value <literal>$libdir</literal>, the
26232624
compiled-in <productname>PostgreSQL</productname> package
26242625
library directory is substituted. This where the modules
@@ -2628,6 +2629,10 @@ SET ENABLE_SEQSCAN TO OFF;
26282629
example:
26292630
<programlisting>
26302631
dynamic_library_path = '/usr/local/lib/postgresql:/home/my_project/lib:$libdir'
2632+
</programlisting>
2633+
or, in a windows environment:
2634+
<programlisting>
2635+
dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir'
26312636
</programlisting>
26322637
</para>
26332638

src/backend/commands/dbcommands.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.134 2004/05/26 13:56:45 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.135 2004/06/10 22:26:18 momjian Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -941,7 +941,7 @@ resolve_alt_dbpath(const char *dbpath, Oid dboid)
941941
if (dbpath == NULL || dbpath[0] == '\0')
942942
return NULL;
943943

944-
if (first_path_separator(dbpath))
944+
if (first_dir_separator(dbpath))
945945
{
946946
if (!is_absolute_path(dbpath))
947947
ereport(ERROR,

src/backend/utils/fmgr/dfmgr.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.73 2004/05/26 18:35:39 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.74 2004/06/10 22:26:19 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -288,7 +288,7 @@ expand_dynamic_library_name(const char *name)
288288

289289
AssertArg(name);
290290

291-
have_slash = (first_path_separator(name) != NULL);
291+
have_slash = (first_dir_separator(name) != NULL);
292292

293293
if (!have_slash)
294294
{
@@ -343,7 +343,7 @@ substitute_libpath_macro(const char *name)
343343
if (name[0] != '$')
344344
return pstrdup(name);
345345

346-
if ((sep_ptr = first_path_separator(name)) == NULL)
346+
if ((sep_ptr = first_dir_separator(name)) == NULL)
347347
sep_ptr = name + strlen(name);
348348

349349
if (strlen("$libdir") != sep_ptr - name ||
@@ -374,7 +374,7 @@ find_in_dynamic_libpath(const char *basename)
374374
size_t baselen;
375375

376376
AssertArg(basename != NULL);
377-
AssertArg(first_path_separator(basename) == NULL);
377+
AssertArg(first_dir_separator(basename) == NULL);
378378
AssertState(Dynamic_library_path != NULL);
379379

380380
p = Dynamic_library_path;
@@ -390,13 +390,17 @@ find_in_dynamic_libpath(const char *basename)
390390
char *mangled;
391391
char *full;
392392

393-
len = strcspn(p, ":");
394-
395-
if (len == 0)
393+
piece = first_path_separator(p);
394+
if(piece == p)
396395
ereport(ERROR,
397396
(errcode(ERRCODE_INVALID_NAME),
398397
errmsg("zero-length component in parameter \"dynamic_library_path\"")));
399398

399+
if(piece == 0)
400+
len = strlen(p);
401+
else
402+
len = piece - p;
403+
400404
piece = palloc(len + 1);
401405
strncpy(piece, p, len);
402406
piece[len] = '\0';

src/bin/initdb/initdb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* Portions Copyright (c) 1994, Regents of the University of California
4040
* Portions taken from FreeBSD.
4141
*
42-
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.36 2004/06/10 16:35:16 momjian Exp $
42+
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.37 2004/06/10 22:26:20 momjian Exp $
4343
*
4444
*-------------------------------------------------------------------------
4545
*/
@@ -1934,7 +1934,7 @@ main(int argc, char *argv[])
19341934

19351935
/* store binary directory */
19361936
strcpy(bin_path, backend_exec);
1937-
*last_path_separator(bin_path) = '\0';
1937+
*last_dir_separator(bin_path) = '\0';
19381938

19391939
if (!share_path)
19401940
{

src/include/port.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/include/port.h,v 1.41 2004/06/10 16:35:18 momjian Exp $
9+
* $PostgreSQL: pgsql/src/include/port.h,v 1.42 2004/06/10 22:26:20 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -22,8 +22,22 @@
2222
bool set_noblock(int sock);
2323

2424
/* Portable path handling for Unix/Win32 */
25+
26+
/* Find the location of the first directory separator, return
27+
* NULL if not found.
28+
*/
29+
extern char *first_dir_separator(const char *filename);
30+
31+
/* Find the location of the last directory separator, return
32+
* NULL if not found.
33+
*/
34+
extern char *last_dir_separator(const char *filename);
35+
36+
/* Find the location of the first path separator (i.e. ':' on
37+
* Unix, ';' on Windows), return NULL if not found.
38+
*/
2539
extern char *first_path_separator(const char *filename);
26-
extern char *last_path_separator(const char *filename);
40+
2741
extern void canonicalize_path(char *path);
2842
extern const char *get_progname(const char *argv0);
2943
extern void get_share_path(const char *my_exec_path, char *ret_path);

src/interfaces/ecpg/ecpglib/connect.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.21 2004/03/15 16:27:43 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.22 2004/06/10 22:26:21 momjian Exp $ */
22

33
#define POSTGRES_ECPG_INTERNAL
44
#include "postgres_fe.h"
@@ -323,7 +323,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
323323
*tmp = '\0';
324324
}
325325

326-
tmp = last_path_separator(dbname + offset);
326+
tmp = last_dir_separator(dbname + offset);
327327
if (tmp != NULL) /* database name given */
328328
{
329329
realname = strdup(tmp + 1);

src/interfaces/ecpg/preproc/ecpg.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.87 2004/05/17 14:35:34 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.88 2004/06/10 22:26:23 momjian Exp $ */
22

33
/* New main for ecpg, the PostgreSQL embedded SQL precompiler. */
44
/* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */
@@ -268,7 +268,7 @@ main(int argc, char *const argv[])
268268
strcpy(input_filename, argv[fnr]);
269269

270270
/* take care of relative paths */
271-
ptr2ext = last_path_separator(input_filename);
271+
ptr2ext = last_dir_separator(input_filename);
272272
ptr2ext = (ptr2ext ? strrchr(ptr2ext, '.') : strrchr(input_filename, '.'));
273273

274274
/* no extension? */

src/interfaces/libpq/fe-connect.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.273 2004/06/08 13:49:23 momjian Exp $
11+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.274 2004/06/10 22:26:24 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -679,7 +679,7 @@ update_db_info(PGconn *conn)
679679
*tmp = '\0';
680680
}
681681

682-
tmp = last_path_separator(conn->dbName + offset);
682+
tmp = last_dir_separator(conn->dbName + offset);
683683
if (tmp != NULL) /* database name given */
684684
{
685685
if (conn->dbName)

src/port/exec.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/port/exec.c,v 1.15 2004/05/24 22:35:37 momjian Exp $
10+
* $PostgreSQL: pgsql/src/port/exec.c,v 1.16 2004/06/10 22:26:24 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -28,13 +28,6 @@
2828

2929
#define _(x) gettext(x)
3030

31-
/* $PATH (or %PATH%) path separator */
32-
#ifdef WIN32
33-
#define PATHSEP ';'
34-
#else
35-
#define PATHSEP ':'
36-
#endif
37-
3831
#ifndef S_IRUSR /* XXX [TRH] should be in a header */
3932
#define S_IRUSR S_IREAD
4033
#define S_IWUSR S_IWRITE
@@ -196,7 +189,7 @@ find_my_exec(const char *argv0, char *retpath)
196189
* it).
197190
*/
198191
/* Does argv0 have a separator? */
199-
if ((path = last_path_separator(argv0)))
192+
if ((path = last_dir_separator(argv0)))
200193
{
201194
if (*++path == '\0')
202195
{
@@ -247,7 +240,7 @@ find_my_exec(const char *argv0, char *retpath)
247240
else
248241
startp = endp + 1;
249242

250-
endp = strchr(startp, PATHSEP);
243+
endp = first_path_separator(startp);
251244
if (!endp)
252245
endp = startp + strlen(startp); /* point to end */
253246

@@ -303,7 +296,7 @@ find_other_exec(const char *argv0, const char *target,
303296
return -1;
304297

305298
/* Trim off program name and keep just directory */
306-
*last_path_separator(retpath) = '\0';
299+
*last_dir_separator(retpath) = '\0';
307300

308301
snprintf(retpath + strlen(retpath), MAXPGPATH - strlen(retpath),
309302
"/%s%s", target, EXE);

src/port/path.c

Lines changed: 36 additions & 17 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.18 2004/06/08 13:49:23 momjian Exp $
11+
* $PostgreSQL: pgsql/src/port/path.c,v 1.19 2004/06/10 22:26:24 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -21,9 +21,15 @@
2121

2222

2323
#ifndef WIN32
24-
#define ISSEP(ch) ((ch) == '/')
24+
#define IS_DIR_SEP(ch) ((ch) == '/')
2525
#else
26-
#define ISSEP(ch) ((ch) == '/' || (ch) == '\\')
26+
#define IS_DIR_SEP(ch) ((ch) == '/' || (ch) == '\\')
27+
#endif
28+
29+
#ifndef WIN32
30+
#define IS_PATH_SEP(ch) ((ch) == ':')
31+
#else
32+
#define IS_PATH_SEP(ch) ((ch) == ';')
2733
#endif
2834

2935
const static char *relative_path(const char *bin_path, const char *other_path);
@@ -33,7 +39,7 @@ static void trim_trailing_separator(char *path);
3339
/* Move to last of consecutive separators or to null byte */
3440
#define MOVE_TO_SEP_END(p) \
3541
{ \
36-
while (ISSEP((p)[0]) && (ISSEP((p)[1]) || !(p)[1])) \
42+
while (IS_DIR_SEP((p)[0]) && (IS_DIR_SEP((p)[1]) || !(p)[1])) \
3743
(p)++; \
3844
}
3945

@@ -46,6 +52,20 @@ do { \
4652
snprintf(ret_path, MAXPGPATH, "%s/%s", path, p); \
4753
} while (0)
4854

55+
/*
56+
* first_dir_separator
57+
*/
58+
char *
59+
first_dir_separator(const char *filename)
60+
{
61+
char *p;
62+
63+
for (p = (char *)filename; *p; p++)
64+
if (IS_DIR_SEP(*p))
65+
return p;
66+
return NULL;
67+
}
68+
4969
/*
5070
* first_path_separator
5171
*/
@@ -55,22 +75,21 @@ first_path_separator(const char *filename)
5575
char *p;
5676

5777
for (p = (char *)filename; *p; p++)
58-
if (ISSEP(*p))
78+
if (IS_PATH_SEP(*p))
5979
return p;
6080
return NULL;
6181
}
6282

63-
6483
/*
65-
* last_path_separator
84+
* last_dir_separator
6685
*/
6786
char *
68-
last_path_separator(const char *filename)
87+
last_dir_separator(const char *filename)
6988
{
7089
char *p, *ret = NULL;
7190

7291
for (p = (char *)filename; *p; p++)
73-
if (ISSEP(*p))
92+
if (IS_DIR_SEP(*p))
7493
ret = p;
7594
return ret;
7695
}
@@ -108,10 +127,10 @@ canonicalize_path(char *path)
108127
const char *
109128
get_progname(const char *argv0)
110129
{
111-
if (!last_path_separator(argv0))
130+
if (!last_dir_separator(argv0))
112131
return argv0;
113132
else
114-
return last_path_separator(argv0) + 1;
133+
return last_dir_separator(argv0) + 1;
115134
}
116135

117136

@@ -307,15 +326,15 @@ relative_path(const char *bin_path, const char *other_path)
307326
break;
308327

309328
/* Win32 filesystem is case insensitive */
310-
if ((!ISSEP(*bin_path) || !ISSEP(*other_path)) &&
329+
if ((!IS_DIR_SEP(*bin_path) || !IS_DIR_SEP(*other_path)) &&
311330
#ifndef WIN32
312331
*bin_path != *other_path)
313332
#else
314333
toupper((unsigned char) *bin_path) != toupper((unsigned char)*other_path))
315334
#endif
316335
break;
317336

318-
if (ISSEP(*other_path))
337+
if (IS_DIR_SEP(*other_path))
319338
other_sep = other_path + 1; /* past separator */
320339

321340
bin_path++;
@@ -327,7 +346,7 @@ relative_path(const char *bin_path, const char *other_path)
327346
return NULL;
328347

329348
/* advance past directory name */
330-
while (!ISSEP(*bin_path) && *bin_path)
349+
while (!IS_DIR_SEP(*bin_path) && *bin_path)
331350
bin_path++;
332351

333352
MOVE_TO_SEP_END(bin_path);
@@ -353,9 +372,9 @@ trim_directory(char *path)
353372
if (path[0] == '\0')
354373
return;
355374

356-
for (p = path + strlen(path) - 1; ISSEP(*p) && p > path; p--)
375+
for (p = path + strlen(path) - 1; IS_DIR_SEP(*p) && p > path; p--)
357376
;
358-
for (; !ISSEP(*p) && p > path; p--)
377+
for (; !IS_DIR_SEP(*p) && p > path; p--)
359378
;
360379
*p = '\0';
361380
return;
@@ -373,6 +392,6 @@ trim_trailing_separator(char *path)
373392

374393
/* trim off trailing slashes */
375394
if (p > path)
376-
for (p--; p >= path && ISSEP(*p); p--)
395+
for (p--; p >= path && IS_DIR_SEP(*p); p--)
377396
*p = '\0';
378397
}

0 commit comments

Comments
 (0)