aboutsummaryrefslogtreecommitdiff
path: root/butl/path.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-02-12 09:08:32 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-02-12 09:08:32 +0200
commite4a63cd55c6347dd24938ec8a1ef203409be058e (patch)
tree56d41e47355067685fa9590b8f3d6fac18d05af6 /butl/path.cxx
parentd2c8cfc1f02b40d3fef5414e5830dd6f1fc20fe9 (diff)
Add path::realize(), which on POSIX calls realpath(3)
Diffstat (limited to 'butl/path.cxx')
-rw-r--r--butl/path.cxx37
1 files changed, 34 insertions, 3 deletions
diff --git a/butl/path.cxx b/butl/path.cxx
index 5b68749..3e82190 100644
--- a/butl/path.cxx
+++ b/butl/path.cxx
@@ -6,14 +6,15 @@
#ifdef _WIN32
# include <stdlib.h> // _MAX_PATH
-# include <direct.h> // _[w]getcwd, _[w]chdir
+# include <direct.h> // _[w]getcwd(), _[w]chdir()
#else
# include <errno.h> // EINVAL
-# include <stdlib.h> // mbstowcs, wcstombs
+# include <stdlib.h> // mbstowcs(), wcstombs(), realpath()
# include <limits.h> // PATH_MAX
-# include <unistd.h> // getcwd, chdir
+# include <unistd.h> // getcwd(), chdir()
#endif
+#include <cassert>
#include <system_error>
#ifndef _WIN32
@@ -68,6 +69,27 @@ namespace butl
#endif
}
+#ifndef _WIN32
+ template <>
+ void path_traits<char>::
+ realize (string_type& s)
+ {
+ char r[PATH_MAX];
+ if (realpath (s.c_str (), r) == nullptr)
+ {
+ // @@ If there were a message in invalid_basic_path, we could have said
+ // what exactly is wrong with the path.
+ //
+ if (errno == EACCES || errno == ENOENT || errno == ENOTDIR)
+ throw invalid_basic_path<char> (s);
+ else
+ throw system_error (errno, system_category ());
+ }
+
+ s = r;
+ }
+#endif
+
//
// wchar_t
//
@@ -112,4 +134,13 @@ namespace butl
throw system_error (errno, system_category ());
#endif
}
+
+#ifndef _WIN32
+ template <>
+ void path_traits<wchar_t>::
+ realize (string_type&)
+ {
+ assert (false); // Implement if/when needed.
+ }
+#endif
}