diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f3903fa..c89ed9d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,6 +91,8 @@ list ( posix/except.hpp posix/fd.cpp posix/fd.hpp + posix/util.cpp + posix/util.hpp ) diff --git a/posix/util.cpp b/posix/util.cpp new file mode 100644 index 00000000..5127e556 --- /dev/null +++ b/posix/util.cpp @@ -0,0 +1,65 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 2017 Danny Robson + */ + +#include "util.hpp" + +#include "fd.hpp" + +#include "except.hpp" + + +/////////////////////////////////////////////////////////////////////////////// +struct ::stat +cruft::posix::stat (char const *path) +{ + struct stat buffer; + error::try_call (::stat, path, &buffer); + return buffer; +} + + +//----------------------------------------------------------------------------- +struct ::stat +cruft::posix::stat (std::filesystem::path const &path) +{ + return stat (path.u8string ().c_str ()); +} + + +/////////////////////////////////////////////////////////////////////////////// +struct ::stat +cruft::posix::fstat (int src) +{ + struct stat buffer; + error::try_call (::fstat, src, &buffer); + return buffer; +} + + +//----------------------------------------------------------------------------- +struct ::stat +cruft::posix::fstat (fd const &src) +{ + return fstat (src.native ()); +} + + +//----------------------------------------------------------------------------- +struct ::stat +cruft::posix::stat (int src) +{ + return fstat (src); +} + + +//----------------------------------------------------------------------------- +struct ::stat +cruft::posix::stat (fd const &src) +{ + return fstat (src); +} diff --git a/posix/util.hpp b/posix/util.hpp new file mode 100644 index 00000000..b7c2e9ea --- /dev/null +++ b/posix/util.hpp @@ -0,0 +1,26 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 2017 Danny Robson + */ + +#pragma once + +#include "fwd.hpp" + +#include + +#include + +namespace cruft::posix { + struct stat stat (char const *path); + struct stat stat (std::filesystem::path const&); + + struct stat fstat (int); + struct stat fstat (fd const&); + + struct stat stat (int); + struct stat stat (fd const&); +} \ No newline at end of file