aboutsummaryrefslogtreecommitdiff
path: root/build/path.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-06-18 14:41:45 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-06-18 14:41:45 +0200
commit63e7a4a77cb8ceed7b42561fe3202b0b48d86db6 (patch)
treebde5a79522225f32ec188ba46d0834486c30f00f /build/path.cxx
parent28c82c861e38fe05a25e916563e0551ed8fce91e (diff)
Move path and filesystem from build2 to libbutl
Diffstat (limited to 'build/path.cxx')
-rw-r--r--build/path.cxx109
1 files changed, 0 insertions, 109 deletions
diff --git a/build/path.cxx b/build/path.cxx
deleted file mode 100644
index 3a3ea3d..0000000
--- a/build/path.cxx
+++ /dev/null
@@ -1,109 +0,0 @@
-// file : build/path.cxx -*- C++ -*-
-// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
-// license : MIT; see accompanying LICENSE file
-
-#include <build/path>
-
-#ifdef _WIN32
-# include <stdlib.h> // _MAX_PATH
-# include <direct.h> // _[w]getcwd, _[w]chdir
-#else
-# include <errno.h> // EINVAL
-# include <stdlib.h> // mbstowcs, wcstombs
-# include <limits.h> // PATH_MAX
-# include <unistd.h> // getcwd, chdir
-#endif
-
-#include <system_error>
-
-using namespace std;
-
-namespace build
-{
- char const* invalid_path_base::
- what () const throw ()
- {
- return "invalid filesystem path";
- }
-
- //
- // char
- //
-
- template <>
- path_traits<char>::string_type path_traits<char>::
- current ()
- {
- // @@ throw system_error (and in the other current() versions).
-
-#ifdef _WIN32
- char cwd[_MAX_PATH];
- if(_getcwd(cwd, _MAX_PATH) == 0)
- throw system_error (errno, system_category ());
-#else
- char cwd[PATH_MAX];
- if (getcwd (cwd, PATH_MAX) == 0)
- throw system_error (errno, system_category ());
-#endif
-
- return string_type (cwd);
- }
-
- template <>
- void path_traits<char>::
- current (string_type const& s)
- {
-#ifdef _WIN32
- if(_chdir(s.c_str ()) != 0)
- throw system_error (errno, system_category ());
-#else
- if (chdir (s.c_str ()) != 0)
- throw system_error (errno, system_category ());
-#endif
- }
-
- //
- // wchar_t
- //
-
- template <>
- path_traits<wchar_t>::string_type path_traits<wchar_t>::
- current ()
- {
-#ifdef _WIN32
- wchar_t wcwd[_MAX_PATH];
- if(_wgetcwd(wcwd, _MAX_PATH) == 0)
- throw system_error (errno, system_category ());
-#else
- char cwd[PATH_MAX];
- if (getcwd (cwd, PATH_MAX) == 0)
- throw system_error (errno, system_category ());
-
- wchar_t wcwd[PATH_MAX];
- if (mbstowcs (wcwd, cwd, PATH_MAX) == size_type (-1))
- throw system_error (EINVAL, system_category ());
-#endif
-
- return string_type (wcwd);
- }
-
- template <>
- void path_traits<wchar_t>::
- current (string_type const& s)
- {
-#ifdef _WIN32
- if(_wchdir(s.c_str ()) != 0)
- throw system_error (errno, system_category ());
-#else
- char ns[PATH_MAX + 1];
-
- if (wcstombs (ns, s.c_str (), PATH_MAX) == size_type (-1))
- throw system_error (EINVAL, system_category ());
-
- ns[PATH_MAX] = '\0';
-
- if (chdir (ns) != 0)
- throw system_error (errno, system_category ());
-#endif
- }
-}