From 547a401ac73d21b769939a3244f991112dd9d2f7 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 22 Oct 2010 11:19:52 +0200 Subject: Add additional path functions These include: absolute(), relative(), current(), complete(), and normalize(). --- cutl/fs/path.cxx | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'cutl/fs/path.cxx') 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 // _getcwd, _wgetcwd, _MAX_PATH +#else +# include // mbstowcs +# include // PATH_MAX +# include // getcwd +#endif + #include namespace cutl @@ -14,5 +22,43 @@ namespace cutl { return "invalid filesystem path"; } + + template <> + basic_path basic_path:: + current () + { +#ifdef _WIN32 + char cwd[_MAX_PATH]; + if(_getcwd(cwd, _MAX_PATH) == 0) + throw invalid_basic_path ("."); +#else + char cwd[PATH_MAX]; + if (getcwd (cwd, PATH_MAX) == 0) + throw invalid_basic_path ("."); +#endif + + return basic_path (cwd); + } + + template <> + basic_path basic_path:: + current () + { +#ifdef _WIN32 + wchar_t wcwd[_MAX_PATH]; + if(_wgetcwd(wcwd, _MAX_PATH) == 0) + throw invalid_basic_path ("."); +#else + char cwd[PATH_MAX]; + if (getcwd (cwd, PATH_MAX) == 0) + throw invalid_basic_path (L"."); + + wchar_t wcwd[PATH_MAX]; + if (mbstowcs (wcwd, cwd, PATH_MAX) == size_type (-1)) + throw invalid_basic_path (L"."); +#endif + + return basic_path (wcwd); + } } } -- cgit v1.1