72 lines
2.4 KiB
C++
72 lines
2.4 KiB
C++
/*
|
|
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
|
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in all copies or
|
|
substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
|
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
|
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
#ifndef INCLUDE_UTILS_UNIX_UNIX_UTILS_HPP_
|
|
#define INCLUDE_UTILS_UNIX_UNIX_UTILS_HPP_
|
|
#ifndef _WIN32
|
|
|
|
#include "common.hpp"
|
|
#include "types/remote.hpp"
|
|
#include "types/repertory.hpp"
|
|
|
|
namespace repertory::utils {
|
|
#if __linux__
|
|
static const std::array<std::string, 4u> attribute_namespaces = {
|
|
"security",
|
|
"system",
|
|
"trusted",
|
|
"user",
|
|
};
|
|
#endif
|
|
|
|
#if __APPLE__
|
|
template <typename t> std::uint64_t convert_to_uint64(const t *v);
|
|
#else
|
|
std::uint64_t convert_to_uint64(const pthread_t &t);
|
|
#endif
|
|
|
|
int get_last_error_code();
|
|
|
|
std::uint64_t get_thread_id();
|
|
|
|
bool is_uid_member_of_group(const uid_t &uid, const gid_t &gid);
|
|
|
|
void set_last_error_code(int error_code);
|
|
|
|
int translate_api_error(const api_error &e);
|
|
|
|
std::int32_t unix_error_to_windows(const int &e);
|
|
|
|
UINT64 unix_time_to_windows_time(const remote::file_time &ts);
|
|
|
|
void windows_create_to_unix(const UINT32 &create_options, const UINT32 &granted_access,
|
|
std::uint32_t &flags, remote::file_mode &mode);
|
|
|
|
remote::file_time windows_time_to_unix_time(const std::uint64_t &t);
|
|
|
|
// template implementations
|
|
#if __APPLE__
|
|
template <typename t> std::uint64_t convert_to_uint64(const t *v) {
|
|
return static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(v));
|
|
}
|
|
#endif
|
|
} // namespace repertory::utils
|
|
|
|
#endif // !_WIN32
|
|
#endif // INCLUDE_UTILS_UNIX_UNIX_UTILS_HPP_
|