aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2004-06-10 22:26:24 +0000
committerBruce Momjian <bruce@momjian.us>2004-06-10 22:26:24 +0000
commit6cc4175b256cfc87411f9e704f9a34cf54f6b256 (patch)
tree7bdf7438dc345bd1154f30efd2cc097f3f0c0c4e /src
parentd4117de50a78afb11d5b7004aa4e34540dc9193a (diff)
downloadpostgresql-6cc4175b256cfc87411f9e704f9a34cf54f6b256.tar.gz
postgresql-6cc4175b256cfc87411f9e704f9a34cf54f6b256.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/backend/commands/dbcommands.c4
-rw-r--r--src/backend/utils/fmgr/dfmgr.c18
-rw-r--r--src/bin/initdb/initdb.c4
-rw-r--r--src/include/port.h18
-rw-r--r--src/interfaces/ecpg/ecpglib/connect.c4
-rw-r--r--src/interfaces/ecpg/preproc/ecpg.c4
-rw-r--r--src/interfaces/libpq/fe-connect.c4
-rw-r--r--src/port/exec.c15
-rw-r--r--src/port/path.c53
9 files changed, 77 insertions, 47 deletions
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index 02c1bf8e204..337ec5395fb 100644
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.134 2004/05/26 13:56:45 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.135 2004/06/10 22:26:18 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -941,7 +941,7 @@ resolve_alt_dbpath(const char *dbpath, Oid dboid)
if (dbpath == NULL || dbpath[0] == '\0')
return NULL;
- if (first_path_separator(dbpath))
+ if (first_dir_separator(dbpath))
{
if (!is_absolute_path(dbpath))
ereport(ERROR,
diff --git a/src/backend/utils/fmgr/dfmgr.c b/src/backend/utils/fmgr/dfmgr.c
index 0d1bfc3b20b..6be4093166e 100644
--- a/src/backend/utils/fmgr/dfmgr.c
+++ b/src/backend/utils/fmgr/dfmgr.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.73 2004/05/26 18:35:39 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.74 2004/06/10 22:26:19 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -288,7 +288,7 @@ expand_dynamic_library_name(const char *name)
AssertArg(name);
- have_slash = (first_path_separator(name) != NULL);
+ have_slash = (first_dir_separator(name) != NULL);
if (!have_slash)
{
@@ -343,7 +343,7 @@ substitute_libpath_macro(const char *name)
if (name[0] != '$')
return pstrdup(name);
- if ((sep_ptr = first_path_separator(name)) == NULL)
+ if ((sep_ptr = first_dir_separator(name)) == NULL)
sep_ptr = name + strlen(name);
if (strlen("$libdir") != sep_ptr - name ||
@@ -374,7 +374,7 @@ find_in_dynamic_libpath(const char *basename)
size_t baselen;
AssertArg(basename != NULL);
- AssertArg(first_path_separator(basename) == NULL);
+ AssertArg(first_dir_separator(basename) == NULL);
AssertState(Dynamic_library_path != NULL);
p = Dynamic_library_path;
@@ -390,13 +390,17 @@ find_in_dynamic_libpath(const char *basename)
char *mangled;
char *full;
- len = strcspn(p, ":");
-
- if (len == 0)
+ piece = first_path_separator(p);
+ if(piece == p)
ereport(ERROR,
(errcode(ERRCODE_INVALID_NAME),
errmsg("zero-length component in parameter \"dynamic_library_path\"")));
+ if(piece == 0)
+ len = strlen(p);
+ else
+ len = piece - p;
+
piece = palloc(len + 1);
strncpy(piece, p, len);
piece[len] = '\0';
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index 726e4658fd7..3ded3d8775b 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -39,7 +39,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
* Portions taken from FreeBSD.
*
- * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.36 2004/06/10 16:35:16 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.37 2004/06/10 22:26:20 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1934,7 +1934,7 @@ main(int argc, char *argv[])
/* store binary directory */
strcpy(bin_path, backend_exec);
- *last_path_separator(bin_path) = '\0';
+ *last_dir_separator(bin_path) = '\0';
if (!share_path)
{
diff --git a/src/include/port.h b/src/include/port.h
index 8d089a8e23e..1a4a4d43361 100644
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/port.h,v 1.41 2004/06/10 16:35:18 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/port.h,v 1.42 2004/06/10 22:26:20 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -22,8 +22,22 @@
bool set_noblock(int sock);
/* Portable path handling for Unix/Win32 */
+
+/* Find the location of the first directory separator, return
+ * NULL if not found.
+ */
+extern char *first_dir_separator(const char *filename);
+
+/* Find the location of the last directory separator, return
+ * NULL if not found.
+ */
+extern char *last_dir_separator(const char *filename);
+
+/* Find the location of the first path separator (i.e. ':' on
+ * Unix, ';' on Windows), return NULL if not found.
+ */
extern char *first_path_separator(const char *filename);
-extern char *last_path_separator(const char *filename);
+
extern void canonicalize_path(char *path);
extern const char *get_progname(const char *argv0);
extern void get_share_path(const char *my_exec_path, char *ret_path);
diff --git a/src/interfaces/ecpg/ecpglib/connect.c b/src/interfaces/ecpg/ecpglib/connect.c
index 82504723d12..838cedf5c94 100644
--- a/src/interfaces/ecpg/ecpglib/connect.c
+++ b/src/interfaces/ecpg/ecpglib/connect.c
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.21 2004/03/15 16:27:43 momjian Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.22 2004/06/10 22:26:21 momjian Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
@@ -323,7 +323,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
*tmp = '\0';
}
- tmp = last_path_separator(dbname + offset);
+ tmp = last_dir_separator(dbname + offset);
if (tmp != NULL) /* database name given */
{
realname = strdup(tmp + 1);
diff --git a/src/interfaces/ecpg/preproc/ecpg.c b/src/interfaces/ecpg/preproc/ecpg.c
index fb2f14a20f0..f8013e487c3 100644
--- a/src/interfaces/ecpg/preproc/ecpg.c
+++ b/src/interfaces/ecpg/preproc/ecpg.c
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.87 2004/05/17 14:35:34 momjian Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.88 2004/06/10 22:26:23 momjian Exp $ */
/* New main for ecpg, the PostgreSQL embedded SQL precompiler. */
/* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */
@@ -268,7 +268,7 @@ main(int argc, char *const argv[])
strcpy(input_filename, argv[fnr]);
/* take care of relative paths */
- ptr2ext = last_path_separator(input_filename);
+ ptr2ext = last_dir_separator(input_filename);
ptr2ext = (ptr2ext ? strrchr(ptr2ext, '.') : strrchr(input_filename, '.'));
/* no extension? */
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index f741509d080..720c47fb86b 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.273 2004/06/08 13:49:23 momjian Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.274 2004/06/10 22:26:24 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -679,7 +679,7 @@ update_db_info(PGconn *conn)
*tmp = '\0';
}
- tmp = last_path_separator(conn->dbName + offset);
+ tmp = last_dir_separator(conn->dbName + offset);
if (tmp != NULL) /* database name given */
{
if (conn->dbName)
diff --git a/src/port/exec.c b/src/port/exec.c
index dbdc04b0ba2..c8ba1227a15 100644
--- a/src/port/exec.c
+++ b/src/port/exec.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/port/exec.c,v 1.15 2004/05/24 22:35:37 momjian Exp $
+ * $PostgreSQL: pgsql/src/port/exec.c,v 1.16 2004/06/10 22:26:24 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -28,13 +28,6 @@
#define _(x) gettext(x)
-/* $PATH (or %PATH%) path separator */
-#ifdef WIN32
-#define PATHSEP ';'
-#else
-#define PATHSEP ':'
-#endif
-
#ifndef S_IRUSR /* XXX [TRH] should be in a header */
#define S_IRUSR S_IREAD
#define S_IWUSR S_IWRITE
@@ -196,7 +189,7 @@ find_my_exec(const char *argv0, char *retpath)
* it).
*/
/* Does argv0 have a separator? */
- if ((path = last_path_separator(argv0)))
+ if ((path = last_dir_separator(argv0)))
{
if (*++path == '\0')
{
@@ -247,7 +240,7 @@ find_my_exec(const char *argv0, char *retpath)
else
startp = endp + 1;
- endp = strchr(startp, PATHSEP);
+ endp = first_path_separator(startp);
if (!endp)
endp = startp + strlen(startp); /* point to end */
@@ -303,7 +296,7 @@ find_other_exec(const char *argv0, const char *target,
return -1;
/* Trim off program name and keep just directory */
- *last_path_separator(retpath) = '\0';
+ *last_dir_separator(retpath) = '\0';
snprintf(retpath + strlen(retpath), MAXPGPATH - strlen(retpath),
"/%s%s", target, EXE);
diff --git a/src/port/path.c b/src/port/path.c
index 7e6f5b4b737..864cb1e3a6a 100644
--- a/src/port/path.c
+++ b/src/port/path.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/port/path.c,v 1.18 2004/06/08 13:49:23 momjian Exp $
+ * $PostgreSQL: pgsql/src/port/path.c,v 1.19 2004/06/10 22:26:24 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -21,9 +21,15 @@
#ifndef WIN32
-#define ISSEP(ch) ((ch) == '/')
+#define IS_DIR_SEP(ch) ((ch) == '/')
#else
-#define ISSEP(ch) ((ch) == '/' || (ch) == '\\')
+#define IS_DIR_SEP(ch) ((ch) == '/' || (ch) == '\\')
+#endif
+
+#ifndef WIN32
+#define IS_PATH_SEP(ch) ((ch) == ':')
+#else
+#define IS_PATH_SEP(ch) ((ch) == ';')
#endif
const static char *relative_path(const char *bin_path, const char *other_path);
@@ -33,7 +39,7 @@ static void trim_trailing_separator(char *path);
/* Move to last of consecutive separators or to null byte */
#define MOVE_TO_SEP_END(p) \
{ \
- while (ISSEP((p)[0]) && (ISSEP((p)[1]) || !(p)[1])) \
+ while (IS_DIR_SEP((p)[0]) && (IS_DIR_SEP((p)[1]) || !(p)[1])) \
(p)++; \
}
@@ -47,6 +53,20 @@ do { \
} while (0)
/*
+ * first_dir_separator
+ */
+char *
+first_dir_separator(const char *filename)
+{
+ char *p;
+
+ for (p = (char *)filename; *p; p++)
+ if (IS_DIR_SEP(*p))
+ return p;
+ return NULL;
+}
+
+/*
* first_path_separator
*/
char *
@@ -55,22 +75,21 @@ first_path_separator(const char *filename)
char *p;
for (p = (char *)filename; *p; p++)
- if (ISSEP(*p))
+ if (IS_PATH_SEP(*p))
return p;
return NULL;
}
-
/*
- * last_path_separator
+ * last_dir_separator
*/
char *
-last_path_separator(const char *filename)
+last_dir_separator(const char *filename)
{
char *p, *ret = NULL;
for (p = (char *)filename; *p; p++)
- if (ISSEP(*p))
+ if (IS_DIR_SEP(*p))
ret = p;
return ret;
}
@@ -108,10 +127,10 @@ canonicalize_path(char *path)
const char *
get_progname(const char *argv0)
{
- if (!last_path_separator(argv0))
+ if (!last_dir_separator(argv0))
return argv0;
else
- return last_path_separator(argv0) + 1;
+ return last_dir_separator(argv0) + 1;
}
@@ -307,7 +326,7 @@ relative_path(const char *bin_path, const char *other_path)
break;
/* Win32 filesystem is case insensitive */
- if ((!ISSEP(*bin_path) || !ISSEP(*other_path)) &&
+ if ((!IS_DIR_SEP(*bin_path) || !IS_DIR_SEP(*other_path)) &&
#ifndef WIN32
*bin_path != *other_path)
#else
@@ -315,7 +334,7 @@ relative_path(const char *bin_path, const char *other_path)
#endif
break;
- if (ISSEP(*other_path))
+ if (IS_DIR_SEP(*other_path))
other_sep = other_path + 1; /* past separator */
bin_path++;
@@ -327,7 +346,7 @@ relative_path(const char *bin_path, const char *other_path)
return NULL;
/* advance past directory name */
- while (!ISSEP(*bin_path) && *bin_path)
+ while (!IS_DIR_SEP(*bin_path) && *bin_path)
bin_path++;
MOVE_TO_SEP_END(bin_path);
@@ -353,9 +372,9 @@ trim_directory(char *path)
if (path[0] == '\0')
return;
- for (p = path + strlen(path) - 1; ISSEP(*p) && p > path; p--)
+ for (p = path + strlen(path) - 1; IS_DIR_SEP(*p) && p > path; p--)
;
- for (; !ISSEP(*p) && p > path; p--)
+ for (; !IS_DIR_SEP(*p) && p > path; p--)
;
*p = '\0';
return;
@@ -373,6 +392,6 @@ trim_trailing_separator(char *path)
/* trim off trailing slashes */
if (p > path)
- for (p--; p >= path && ISSEP(*p); p--)
+ for (p--; p >= path && IS_DIR_SEP(*p); p--)
*p = '\0';
}