summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2017-04-06 15:14:09 +0200
committerUlf Hermann <ulf.hermann@qt.io>2017-05-08 09:45:39 +0000
commite5cde7378c246a32d7dbc3bff8db15befad8b1a9 (patch)
tree7586f1b4901236f1dbe28e022d6a4c9b84bef74e /lib
parent037d971fa81644af1d3be30db409309155fda721 (diff)
Use OS-specific paths
In general we need to use ';' as path separator and '\' and directory separator on windows. The shell will automatically translate paths to some extent, but we have to call "pwd -W" rather than plain "pwd" to get something useful. Change-Id: I1a117d219a2aa00c1f77ae7d3a1d92b9bae526db Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'lib')
-rw-r--r--lib/ChangeLog5
-rw-r--r--lib/system.h16
2 files changed, 21 insertions, 0 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 9fa8ff0f..59939bd1 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,5 +1,10 @@
2017-05-04 Ulf Hermann <ulf.hermann@qt.io>
+ * system.h: Define FILE_SYSTEM_PREFIX_LEN, ISDIRSEP, DIRSEP, PATHSEP,
+ and IS_ABSOLUTE_PATH to help with handling file system paths.
+
+2017-05-04 Ulf Hermann <ulf.hermann@qt.io>
+
* eu-config.h: Define O_BINARY to 0 if it doesn't exist.
2017-05-04 Ulf Hermann <ulf.hermann@qt.io>
diff --git a/lib/system.h b/lib/system.h
index ffa2bc70..3a6b8e93 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -51,6 +51,22 @@
# error "Unknown byte order"
#endif
+#if (defined _WIN32 || defined __WIN32__)
+# define _IS_DRIVE_LETTER(c) (((unsigned int) (c) | ('a' - 'A')) - 'a' <= 'z' - 'a')
+# define FILE_SYSTEM_PREFIX_LEN(filename) \
+ (_IS_DRIVE_LETTER ((filename)[0]) && (filename)[1] == ':' ? 2 : 0)
+# define ISDIRSEP(c) ((c) == '/' || (c) == '\\')
+# define DIRSEP '\\'
+# define PATHSEP ';'
+# define IS_ABSOLUTE_PATH(f) ISDIRSEP ((f)[FILE_SYSTEM_PREFIX_LEN (f)])
+#else
+# define FILE_SYSTEM_PREFIX_LEN(filename) 0
+# define ISDIRSEP(c) ((c) == '/')
+# define DIRSEP '/'
+# define PATHSEP ':'
+# define IS_ABSOLUTE_PATH(p) (ISDIRSEP ((p)[0]))
+#endif
+
#ifndef MAX
#define MAX(m, n) ((m) < (n) ? (n) : (m))
#endif