Simplify code used in is_absolute_path() macro; also add comment about
authorBruce Momjian <[email protected]>
Thu, 3 Feb 2011 15:46:31 +0000 (10:46 -0500)
committerBruce Momjian <[email protected]>
Thu, 3 Feb 2011 15:47:06 +0000 (10:47 -0500)
'E:abc' Win32 path handling.

src/include/port.h
src/port/path.c

index 4f0c0c1b08caa5d8ec249be3739c2d56899a2efe..2020a260607168e3c6ce3dabf36a737b5fab7e40 100644 (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.
  */
 #ifndef WIN32
+#define IS_DIR_SEP(ch) ((ch) == '/')
+
 #define is_absolute_path(filename) \
 ( \
-   ((filename)[0] == '/') \
+   IS_DIR_SEP((filename)[0]) \
 )
 #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) \
 ( \
-   ((filename)[0] == '/') || \
-   (filename)[0] == '\\' || \
+   IS_DIR_SEP((filename)[0]) || \
    (isalpha((unsigned char) ((filename)[0])) && (filename)[1] == ':' && \
-   ((filename)[2] == '\\' || (filename)[2] == '/')) \
+    IS_DIR_SEP((filename)[2])) \
 )
 #endif
 
index ccf801ead6413a5796ab6c8fe346bd495d9f94af..5b0056dfe58b2aa3e7f2025502fbb60d38b87980 100644 (file)
 #include "pg_config_paths.h"
 
 
-#ifndef WIN32
-#define IS_DIR_SEP(ch) ((ch) == '/')
-#else
-#define IS_DIR_SEP(ch) ((ch) == '/' || (ch) == '\\')
-#endif
-
 #ifndef WIN32
 #define IS_PATH_VAR_SEP(ch) ((ch) == ':')
 #else