Skip to content

Commit 35b0a6b

Browse files
committed
Simplify code used in is_absolute_path() macro; also add comment about
'E:abc' Win32 path handling.
1 parent 76129e7 commit 35b0a6b

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/include/port.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,27 @@ extern void pgfnames_cleanup(char **filenames);
6868
* By making this a macro we avoid needing to include path.c in libpq.
6969
*/
7070
#ifndef WIN32
71+
#define IS_DIR_SEP(ch) ((ch) == '/')
72+
7173
#define is_absolute_path(filename) \
7274
( \
73-
((filename)[0] == '/') \
75+
IS_DIR_SEP((filename)[0]) \
7476
)
7577
#else
78+
#define IS_DIR_SEP(ch) ((ch) == '/' || (ch) == '\\')
79+
80+
/*
81+
* On Win32, a drive letter _not_ followed by a slash, e.g. 'E:abc', is
82+
* relative to the cwd on that drive, or the drive's root directory
83+
* if that drive has no cwd. Because the path itself cannot tell us
84+
* which is the case, we have to assume the worst, i.e. that it is not
85+
* absolute; this check is done by IS_DIR_SEP(filename[2]).
86+
*/
7687
#define is_absolute_path(filename) \
7788
( \
78-
((filename)[0] == '/') || \
79-
(filename)[0] == '\\' || \
89+
IS_DIR_SEP((filename)[0]) || \
8090
(isalpha((unsigned char) ((filename)[0])) && (filename)[1] == ':' && \
81-
((filename)[2] == '\\' || (filename)[2] == '/')) \
91+
IS_DIR_SEP((filename)[2])) \
8292
)
8393
#endif
8494

src/port/path.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@
3434
#include "pg_config_paths.h"
3535

3636

37-
#ifndef WIN32
38-
#define IS_DIR_SEP(ch) ((ch) == '/')
39-
#else
40-
#define IS_DIR_SEP(ch) ((ch) == '/' || (ch) == '\\')
41-
#endif
42-
4337
#ifndef WIN32
4438
#define IS_PATH_VAR_SEP(ch) ((ch) == ':')
4539
#else

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy