diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2010-10-22 11:19:52 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2010-10-22 11:19:52 +0200 |
commit | 547a401ac73d21b769939a3244f991112dd9d2f7 (patch) | |
tree | 6ffeaba2df9ed2877ea423e7a51619e38bea854b /cutl/fs/path.cxx | |
parent | 13fe7d4568db4da0ec7dca7a69055f77933ce3f3 (diff) |
Add additional path functions
These include: absolute(), relative(), current(), complete(), and
normalize().
Diffstat (limited to 'cutl/fs/path.cxx')
-rw-r--r-- | cutl/fs/path.cxx | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/cutl/fs/path.cxx b/cutl/fs/path.cxx index 578cc5b..5aaf2a9 100644 --- a/cutl/fs/path.cxx +++ b/cutl/fs/path.cxx @@ -3,6 +3,14 @@ // copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC // license : MIT; see accompanying LICENSE file +#ifdef _WIN32 +# include <direct.h> // _getcwd, _wgetcwd, _MAX_PATH +#else +# include <stdlib.h> // mbstowcs +# include <limits.h> // PATH_MAX +# include <unistd.h> // getcwd +#endif + #include <cutl/fs/path.hxx> namespace cutl @@ -14,5 +22,43 @@ namespace cutl { return "invalid filesystem path"; } + + template <> + basic_path<char> basic_path<char>:: + current () + { +#ifdef _WIN32 + char cwd[_MAX_PATH]; + if(_getcwd(cwd, _MAX_PATH) == 0) + throw invalid_basic_path<char> ("."); +#else + char cwd[PATH_MAX]; + if (getcwd (cwd, PATH_MAX) == 0) + throw invalid_basic_path<char> ("."); +#endif + + return basic_path<char> (cwd); + } + + template <> + basic_path<wchar_t> basic_path<wchar_t>:: + current () + { +#ifdef _WIN32 + wchar_t wcwd[_MAX_PATH]; + if(_wgetcwd(wcwd, _MAX_PATH) == 0) + throw invalid_basic_path<wchar_t> ("."); +#else + char cwd[PATH_MAX]; + if (getcwd (cwd, PATH_MAX) == 0) + throw invalid_basic_path<wchar_t> (L"."); + + wchar_t wcwd[PATH_MAX]; + if (mbstowcs (wcwd, cwd, PATH_MAX) == size_type (-1)) + throw invalid_basic_path<wchar_t> (L"."); +#endif + + return basic_path<wchar_t> (wcwd); + } } } |