summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
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 <[email protected]>
+ * 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 <[email protected]>
+
* eu-config.h: Define O_BINARY to 0 if it doesn't exist.
2017-05-04 Ulf Hermann <[email protected]>
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