blob: 2771e5ea02ee0e8e398c4dba47c6f1d69300e935 [file] [log] [blame]
#ifndef STG_FILE_DESCRIPTOR_H_
#define STG_FILE_DESCRIPTOR_H_
#include <utility>
namespace stg {
// RAII wrapper over file descriptor
class FileDescriptor {
public:
FileDescriptor() {}
FileDescriptor(const char* filename, int flags, mode_t mode = 0);
FileDescriptor(const FileDescriptor&) = delete;
FileDescriptor& operator=(const FileDescriptor&) = delete;
FileDescriptor(FileDescriptor&& other) {
std::swap(fd_, other.fd_);
}
FileDescriptor& operator=(FileDescriptor&& other) {
std::swap(fd_, other.fd_);
return *this;
}
~FileDescriptor() noexcept(false);
int Value() const;
private:
int fd_ = -1;
};
} // namespace stg
#endif // STG_FILE_DESCRIPTOR_H_