60 FileHandle(
const char* filename,
const char* mode) : file_(std::fopen(filename, mode)) {}
62 FileHandle(
const std::string& filename,
const char* mode)
63 : file_(std::fopen(filename.c_str(), mode))
86 other.file_ =
nullptr;
98 other.file_ =
nullptr;
118 return file_ !=
nullptr;
124 explicit operator bool()
const
163 PipeHandle(
const char* command,
const char* mode) : pipe_(::popen(command, mode)) {}
165 PipeHandle(
const std::string& command,
const char* mode) : pipe_(::popen(command.c_str(), mode))
188 other.pipe_ =
nullptr;
200 other.pipe_ =
nullptr;
220 return pipe_ !=
nullptr;
243 const int status = ::pclose(pipe_);
251 explicit operator bool()
const
FileHandle & operator=(const FileHandle &)=delete
FILE * release()
Release ownership of FILE* without closing.
FileHandle(const std::string &filename, const char *mode)
bool isOpen() const
Check if file is open.
~FileHandle()
Destructor - automatically closes file.
FILE * get() const
Get raw FILE* pointer.
FileHandle(const FileHandle &)=delete
FileHandle & operator=(FileHandle &&other) noexcept
FileHandle(FileHandle &&other) noexcept
FileHandle(const char *filename, const char *mode)
Open file with specified mode.
FILE * release()
Release ownership of FILE* without closing.
int close()
Close the pipe early and return pclose's exit status.
bool isOpen() const
Check if pipe is open.
FILE * get() const
Get raw FILE* pointer.
PipeHandle & operator=(PipeHandle &&other) noexcept
PipeHandle(const PipeHandle &)=delete
PipeHandle(const std::string &command, const char *mode)
PipeHandle(PipeHandle &&other) noexcept
~PipeHandle()
Destructor - automatically closes pipe.
PipeHandle & operator=(const PipeHandle &)=delete
PipeHandle(const char *command, const char *mode)
Open pipe for command execution.