Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d46e643

Browse files
committed
Add Win32 path handling for / vs. \ and drive letters.
1 parent 9bad936 commit d46e643

File tree

22 files changed

+147
-88
lines changed

22 files changed

+147
-88
lines changed

src/Makefile.global.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*-makefile-*-
2-
# $Header: /cvsroot/pgsql/src/Makefile.global.in,v 1.160 2003/03/29 11:31:51 petere Exp $
2+
# $Header: /cvsroot/pgsql/src/Makefile.global.in,v 1.161 2003/04/04 20:42:11 momjian Exp $
33

44
#------------------------------------------------------------------------------
55
# All PostgreSQL makefiles include this file and use the variables it sets,
@@ -338,7 +338,7 @@ endif
338338
#
339339
# substitute implementations of the C library
340340

341-
LIBOBJS = @LIBOBJS@
341+
LIBOBJS = @LIBOBJS@ path.o
342342

343343
ifneq (,$(LIBOBJS))
344344
LIBS += -lpgport

src/backend/commands/copy.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.190 2003/03/27 16:51:27 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.191 2003/04/04 20:42:11 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -476,7 +476,7 @@ DoCopy(const CopyStmt *stmt)
476476
* Prevent write to relative path ... too easy to shoot
477477
* oneself in the foot by overwriting a database file ...
478478
*/
479-
if (filename[0] != '/')
479+
if (!is_absolute_path(filename))
480480
elog(ERROR, "Relative path not allowed for server side"
481481
" COPY command");
482482

src/backend/commands/dbcommands.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.111 2003/04/04 20:40:44 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.112 2003/04/04 20:42:12 momjian Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -698,9 +698,9 @@ resolve_alt_dbpath(const char *dbpath, Oid dboid)
698698
if (dbpath == NULL || dbpath[0] == '\0')
699699
return NULL;
700700

701-
if (strchr(dbpath, '/'))
701+
if (first_path_separator(dbpath))
702702
{
703-
if (dbpath[0] != '/')
703+
if (!is_absolute_path(dbpath))
704704
elog(ERROR, "Relative paths are not allowed as database locations");
705705
#ifndef ALLOW_ABSOLUTE_DBPATHS
706706
elog(ERROR, "Absolute paths are not allowed as database locations");
@@ -714,7 +714,7 @@ resolve_alt_dbpath(const char *dbpath, Oid dboid)
714714

715715
if (!var)
716716
elog(ERROR, "Postmaster environment variable '%s' not set", dbpath);
717-
if (var[0] != '/')
717+
if (!is_absolute_path(var))
718718
elog(ERROR, "Postmaster environment variable '%s' must be absolute path", dbpath);
719719
prefix = var;
720720
}

src/backend/storage/file/fd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/storage/file/fd.c,v 1.96 2003/03/27 16:51:29 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/file/fd.c,v 1.97 2003/04/04 20:42:12 momjian Exp $
1111
*
1212
* NOTES:
1313
*
@@ -607,7 +607,7 @@ filepath(const char *filename)
607607
char *buf;
608608

609609
/* Not an absolute path name? Then fill in with database path... */
610-
if (*filename != '/')
610+
if (!is_absolute_path(filename))
611611
{
612612
buf = (char *) palloc(strlen(DatabasePath) + strlen(filename) + 2);
613613
sprintf(buf, "%s/%s", DatabasePath, filename);

src/backend/utils/fmgr/dfmgr.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.57 2002/09/02 02:47:05 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.58 2003/04/04 20:42:12 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -271,7 +271,7 @@ expand_dynamic_library_name(const char *name)
271271

272272
AssertArg(name);
273273

274-
have_slash = (strchr(name, '/') != NULL);
274+
have_slash = (first_path_separator(name) != NULL);
275275

276276
if (!have_slash)
277277
{
@@ -326,7 +326,13 @@ substitute_libpath_macro(const char *name)
326326
if (name[0] != '$')
327327
return pstrdup(name);
328328

329-
macroname_len = strcspn(name + 1, "/") + 1;
329+
macroname_len = strcspn(name + 1,
330+
#ifndef WIN32
331+
"/"
332+
#else
333+
"/\\"
334+
#endif
335+
) + 1;
330336

331337
if (strncmp(name, "$libdir", macroname_len) == 0)
332338
replacement = PKGLIBDIR;
@@ -362,7 +368,7 @@ find_in_dynamic_libpath(const char *basename)
362368
size_t baselen;
363369

364370
AssertArg(basename != NULL);
365-
AssertArg(strchr(basename, '/') == NULL);
371+
AssertArg(first_path_separator(basename) == NULL);
366372
AssertState(Dynamic_library_path != NULL);
367373

368374
p = Dynamic_library_path;
@@ -391,7 +397,7 @@ find_in_dynamic_libpath(const char *basename)
391397
pfree(piece);
392398

393399
/* only absolute paths */
394-
if (mangled[0] != '/')
400+
if (!is_absolute_path(mangled))
395401
elog(ERROR, "dynamic_library_path component is not absolute");
396402

397403
full = palloc(strlen(mangled) + 1 + baselen + 1);

src/backend/utils/init/findbe.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/init/Attic/findbe.c,v 1.31 2002/11/02 15:54:13 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/init/Attic/findbe.c,v 1.32 2003/04/04 20:42:12 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -159,14 +159,14 @@ FindExec(char *full_path, const char *argv0, const char *binary_name)
159159
* (making sure that a relative path is made absolute before returning
160160
* it).
161161
*/
162-
if (argv0 && (p = strrchr(argv0, '/')) && *++p)
162+
if (argv0 && (p = last_path_separator(argv0)) && *++p)
163163
{
164-
if (*argv0 == '/' || !getcwd(buf, MAXPGPATH))
164+
if (is_absolute_path(argv0) || !getcwd(buf, MAXPGPATH))
165165
buf[0] = '\0';
166166
else
167167
strcat(buf, "/");
168168
strcat(buf, argv0);
169-
p = strrchr(buf, '/');
169+
p = last_path_separator(buf);
170170
strcpy(++p, binary_name);
171171
if (ValidateBinary(buf) == 0)
172172
{
@@ -194,7 +194,7 @@ FindExec(char *full_path, const char *argv0, const char *binary_name)
194194
continue;
195195
if (endp)
196196
*endp = '\0';
197-
if (*startp == '/' || !getcwd(buf, MAXPGPATH))
197+
if (is_absolute_path(startp) || !getcwd(buf, MAXPGPATH))
198198
buf[0] = '\0';
199199
else
200200
strcat(buf, "/");

src/backend/utils/init/miscinit.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.101 2003/03/20 04:51:44 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.102 2003/04/04 20:42:12 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -134,7 +134,7 @@ SetDataDir(const char *dir)
134134
AssertArg(dir);
135135

136136
/* If presented path is relative, convert to absolute */
137-
if (dir[0] != '/')
137+
if (!is_absolute_path(dir))
138138
{
139139
char *buf;
140140
size_t buflen;
@@ -179,7 +179,11 @@ SetDataDir(const char *dir)
179179
* generating funny-looking paths to individual files.
180180
*/
181181
newlen = strlen(new);
182-
if (newlen > 1 && new[newlen - 1] == '/')
182+
if (newlen > 1 && new[newlen - 1] == '/'
183+
#ifdef WIN32
184+
|| new[newlen - 1] == '\\'
185+
#endif
186+
)
183187
new[newlen - 1] = '\0';
184188

185189
if (DataDir)

src/backend/utils/misc/database.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/misc/Attic/database.c,v 1.55 2003/03/10 22:28:19 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/misc/Attic/database.c,v 1.56 2003/04/04 20:42:12 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -50,10 +50,10 @@ ExpandDatabasePath(const char *dbpath)
5050
return NULL; /* ain't gonna fit nohow */
5151

5252
/* leading path delimiter? then already absolute path */
53-
if (*dbpath == '/')
53+
if (is_absolute_path(dbpath))
5454
{
5555
#ifdef ALLOW_ABSOLUTE_DBPATHS
56-
cp = strrchr(dbpath, '/');
56+
cp = last_path_separator(dbpath);
5757
len = cp - dbpath;
5858
strncpy(buf, dbpath, len);
5959
snprintf(&buf[len], MAXPGPATH - len, "/base/%s", (cp + 1));
@@ -62,7 +62,7 @@ ExpandDatabasePath(const char *dbpath)
6262
#endif
6363
}
6464
/* path delimiter somewhere? then has leading environment variable */
65-
else if ((cp = strchr(dbpath, '/')) != NULL)
65+
else if ((cp = first_path_separator(dbpath)) != NULL)
6666
{
6767
const char *envvar;
6868

src/bin/pg_controldata/pg_controldata.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* copyright (c) Oliver Elphick <[email protected]>, 2001;
77
* licence: BSD
88
*
9-
* $Header: /cvsroot/pgsql/src/bin/pg_controldata/pg_controldata.c,v 1.8 2003/01/08 22:26:34 momjian Exp $
9+
* $Header: /cvsroot/pgsql/src/bin/pg_controldata/pg_controldata.c,v 1.9 2003/04/04 20:42:12 momjian Exp $
1010
*/
1111
#include "postgres.h"
1212

@@ -82,10 +82,7 @@ main(int argc, char *argv[])
8282
textdomain("pg_controldata");
8383
#endif
8484

85-
if (!strrchr(argv[0], '/'))
86-
progname = argv[0];
87-
else
88-
progname = strrchr(argv[0], '/') + 1;
85+
progname = get_progname(argv[0]);
8986

9087
if (argc > 1)
9188
{

src/bin/pg_dump/pg_dump.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* by PostgreSQL
1313
*
1414
* IDENTIFICATION
15-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.325 2003/03/31 20:48:45 momjian Exp $
15+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.326 2003/04/04 20:42:12 momjian Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -244,10 +244,7 @@ main(int argc, char **argv)
244244

245245
dataOnly = schemaOnly = dumpData = attrNames = false;
246246

247-
if (!strrchr(argv[0], '/'))
248-
progname = argv[0];
249-
else
250-
progname = strrchr(argv[0], '/') + 1;
247+
progname = get_progname(argv[0]);
251248

252249
/* Set default options based on progname */
253250
if (strcmp(progname, "pg_backup") == 0)

0 commit comments

Comments
 (0)