You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
falk-werner_webfuse/src/webfuse/filesystem/filemode.cpp

51 lines
1.1 KiB

#include "webfuse/filesystem/filemode.hpp"
#include <sys/stat.h>
namespace webfuse
{
filemode::filemode(uint32_t value)
: value_(value)
{
}
filemode::operator uint32_t() const
{
return value_;
}
filemode filemode::from_mode(mode_t value)
{
uint32_t result = value & 07777; // NOLINT(readability-magic-numbers)
if (S_ISREG(value) ) { result |= filemode::reg; }
if (S_ISDIR(value) ) { result |= filemode::dir; }
if (S_ISCHR(value) ) { result |= filemode::chr; }
if (S_ISBLK(value) ) { result |= filemode::blk; }
if (S_ISFIFO(value)) { result |= filemode::fifo; }
if (S_ISLNK(value) ) { result |= filemode::lnk; }
if (S_ISSOCK(value)) { result |= filemode::sock; }
return filemode(result);
}
mode_t filemode::to_mode() const
{
mode_t result = value_ & 07777; // NOLINT(readability-magic-numbers)
if (is_reg() ) { result |= S_IFREG; }
if (is_dir() ) { result |= S_IFDIR; }
if (is_chr() ) { result |= S_IFCHR; }
if (is_blk() ) { result |= S_IFBLK; }
if (is_fifo()) { result |= S_IFIFO; }
if (is_lnk() ) { result |= S_IFLNK; }
if (is_sock()) { result |= S_IFSOCK; }
return result;
}
}