diff options
author | Benjamin Barenblat <bbaren@mit.edu> | 2016-02-21 20:14:05 -0500 |
---|---|---|
committer | Benjamin Barenblat <bbaren@mit.edu> | 2016-02-21 20:38:12 -0500 |
commit | 90c61f66909affa269dfb396f0e5cc67f4e4de44 (patch) | |
tree | cce220e2b634edac84352ec6a104dc03cb8a0a35 /src/posix_extras.cc | |
parent | 273ed4f9042fbdb8fc4f8335638b09058bb5def0 (diff) |
Implement mkdir/rmdir
Diffstat (limited to 'src/posix_extras.cc')
-rw-r--r-- | src/posix_extras.cc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/posix_extras.cc b/src/posix_extras.cc index 7b82f0a..5fc60f6 100644 --- a/src/posix_extras.cc +++ b/src/posix_extras.cc @@ -78,6 +78,16 @@ struct stat File::LinkStatAt(const char* const path) const { return result; } +void File::MkDir(const char* const path, const mode_t mode) const { + if (path[0] == '/') { + throw std::invalid_argument("absolute path"); + } + + if (mkdirat(fd_, path, mode | S_IFDIR) == -1) { + throw SystemError(); + } +} + void File::MkNod(const char* const path, const mode_t mode, const dev_t dev) const { if (path[0] == '/') { @@ -119,6 +129,16 @@ std::vector<std::uint8_t> File::Read(off_t offset, size_t bytes) const { return result; } +void File::RmDirAt(const char* const path) const { + if (path[0] == '/') { + throw std::invalid_argument("absolute path"); + } + + if (unlinkat(fd_, path, AT_REMOVEDIR) == -1) { + throw SystemError(); + } +} + void File::UnlinkAt(const char* const path) const { if (path[0] == '/') { throw std::invalid_argument("absolute path"); |