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
This commit is contained in:
Bruce Momjian 2004-06-10 22:26:24 +00:00
parent d4117de50a
commit 6cc4175b25
10 changed files with 85 additions and 50 deletions

View File

@ -1,5 +1,5 @@
<!--
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.265 2004/05/26 18:51:43 momjian Exp $
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.266 2004/06/10 22:26:17 momjian Exp $
-->
<Chapter Id="runtime">
@ -2617,8 +2617,9 @@ SET ENABLE_SEQSCAN TO OFF;
</para>
<para>
The value for <varname>dynamic_library_path</varname> has to be a colon-separated
list of absolute directory names. If a directory name starts
The value for <varname>dynamic_library_path</varname> has to be a
list of absolute directory names separated by colon or, in windows
environments with semi-colon. If a directory name starts
with the special value <literal>$libdir</literal>, the
compiled-in <productname>PostgreSQL</productname> package
library directory is substituted. This where the modules
@ -2628,6 +2629,10 @@ SET ENABLE_SEQSCAN TO OFF;
example:
<programlisting>
dynamic_library_path = '/usr/local/lib/postgresql:/home/my_project/lib:$libdir'
</programlisting>
or, in a windows environment:
<programlisting>
dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir'
</programlisting>
</para>

View File

@ -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,

View File

@ -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';

View File

@ -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)
{

View File

@ -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);

View File

@ -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);

View File

@ -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? */

View File

@ -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)

View File

@ -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);

View File

@ -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)++; \
}
@ -46,6 +52,20 @@ do { \
snprintf(ret_path, MAXPGPATH, "%s/%s", path, p); \
} 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
*/
@ -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';
}