posix/util: add stat
wrappers
This commit is contained in:
parent
0144018992
commit
cd8a2d9816
@ -91,6 +91,8 @@ list (
|
|||||||
posix/except.hpp
|
posix/except.hpp
|
||||||
posix/fd.cpp
|
posix/fd.cpp
|
||||||
posix/fd.hpp
|
posix/fd.hpp
|
||||||
|
posix/util.cpp
|
||||||
|
posix/util.hpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
65
posix/util.cpp
Normal file
65
posix/util.cpp
Normal file
@ -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 <danny@nerdcruft.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
26
posix/util.hpp
Normal file
26
posix/util.hpp
Normal file
@ -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 <danny@nerdcruft.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "fwd.hpp"
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
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&);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user