blob: 46e55397518c5d70f2544994dc36294b1139ac68 [file] [log] [blame]
Ed Tanous73030632022-01-14 10:09:47 -08001#pragma once
2
3#include <filesystem>
4#include <ios>
5
6// An RAII compliant object for holding a posix file descriptor
7class FileHandle
8{
9 private:
10 int fd;
11
12 public:
13 FileHandle() = delete;
14 FileHandle(const FileHandle&) = delete;
15 FileHandle& operator=(const FileHandle&) = delete;
16 FileHandle(FileHandle&&) noexcept;
17 FileHandle& operator=(FileHandle&&) noexcept;
18
19 explicit FileHandle(const std::filesystem::path& name,
20 std::ios_base::openmode mode = std::ios_base::in |
21 std::ios_base::out);
22
23 explicit FileHandle(int fd);
24
25 ~FileHandle();
26 int handle();
27};