diff options
| author | Bruce Momjian <bruce@momjian.us> | 2004-06-10 22:26:24 +0000 |
|---|---|---|
| committer | Bruce Momjian <bruce@momjian.us> | 2004-06-10 22:26:24 +0000 |
| commit | 6cc4175b256cfc87411f9e704f9a34cf54f6b256 (patch) | |
| tree | 7bdf7438dc345bd1154f30efd2cc097f3f0c0c4e /src/port/path.c | |
| parent | d4117de50a78afb11d5b7004aa4e34540dc9193a (diff) | |
| download | postgresql-6cc4175b256cfc87411f9e704f9a34cf54f6b256.tar.gz | |
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/port/path.c')
| -rw-r--r-- | src/port/path.c | 53 |
1 files changed, 36 insertions, 17 deletions
diff --git a/src/port/path.c b/src/port/path.c index 7e6f5b4b73..864cb1e3a6 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'; } |
