diff options
Diffstat (limited to 'src/posix_extras.cc')
-rw-r--r-- | src/posix_extras.cc | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/posix_extras.cc b/src/posix_extras.cc index 5fc60f6..17fe275 100644 --- a/src/posix_extras.cc +++ b/src/posix_extras.cc @@ -25,6 +25,7 @@ #include <dirent.h> #include <fcntl.h> #include <glog/logging.h> +#include <stdio.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> @@ -129,6 +130,16 @@ std::vector<std::uint8_t> File::Read(off_t offset, size_t bytes) const { return result; } +void File::RenameAt(const char* old_path, const char* new_path) const { + if (old_path[0] == '/' || new_path[0] == '/') { + throw std::invalid_argument("absolute path"); + } + + if (renameat(fd_, old_path, fd_, new_path) == -1) { + throw SystemError(); + } +} + void File::RmDirAt(const char* const path) const { if (path[0] == '/') { throw std::invalid_argument("absolute path"); |