1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-16 06:01:02 +03:00

Simplify code used in is_absolute_path() macro; also add comment about

'E:abc' Win32 path handling.
This commit is contained in:
Bruce Momjian
2011-02-03 10:46:31 -05:00
parent 76129e7f14
commit 35b0a6b205
2 changed files with 14 additions and 10 deletions

View File

@ -68,17 +68,27 @@ extern void pgfnames_cleanup(char **filenames);
* By making this a macro we avoid needing to include path.c in libpq. * By making this a macro we avoid needing to include path.c in libpq.
*/ */
#ifndef WIN32 #ifndef WIN32
#define IS_DIR_SEP(ch) ((ch) == '/')
#define is_absolute_path(filename) \ #define is_absolute_path(filename) \
( \ ( \
((filename)[0] == '/') \ IS_DIR_SEP((filename)[0]) \
) )
#else #else
#define IS_DIR_SEP(ch) ((ch) == '/' || (ch) == '\\')
/*
* On Win32, a drive letter _not_ followed by a slash, e.g. 'E:abc', is
* relative to the cwd on that drive, or the drive's root directory
* if that drive has no cwd. Because the path itself cannot tell us
* which is the case, we have to assume the worst, i.e. that it is not
* absolute; this check is done by IS_DIR_SEP(filename[2]).
*/
#define is_absolute_path(filename) \ #define is_absolute_path(filename) \
( \ ( \
((filename)[0] == '/') || \ IS_DIR_SEP((filename)[0]) || \
(filename)[0] == '\\' || \
(isalpha((unsigned char) ((filename)[0])) && (filename)[1] == ':' && \ (isalpha((unsigned char) ((filename)[0])) && (filename)[1] == ':' && \
((filename)[2] == '\\' || (filename)[2] == '/')) \ IS_DIR_SEP((filename)[2])) \
) )
#endif #endif

View File

@ -34,12 +34,6 @@
#include "pg_config_paths.h" #include "pg_config_paths.h"
#ifndef WIN32
#define IS_DIR_SEP(ch) ((ch) == '/')
#else
#define IS_DIR_SEP(ch) ((ch) == '/' || (ch) == '\\')
#endif
#ifndef WIN32 #ifndef WIN32
#define IS_PATH_VAR_SEP(ch) ((ch) == ':') #define IS_PATH_VAR_SEP(ch) ((ch) == ':')
#else #else