mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-09-29 11:16:29 +03:00
dump: move openStdioFile() to util/dump_util.h
This commit is contained in:
committed by
Matthew Barr
parent
bc953717c1
commit
4edf1e4195
@@ -30,6 +30,8 @@
|
||||
#define DUMP_UTIL
|
||||
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace ue2 {
|
||||
|
||||
@@ -38,6 +40,20 @@ namespace ue2 {
|
||||
*/
|
||||
FILE *fopen_or_throw(const char *path, const char *mode);
|
||||
|
||||
/**
|
||||
* \brief Helper function: returns a C stdio FILE* handle wrapped in
|
||||
* a unique_ptr that takes care of closing the file on destruction.
|
||||
*
|
||||
* If the file cannot be opened, throws an exception.
|
||||
*/
|
||||
inline
|
||||
std::unique_ptr<FILE, decltype(&fclose)>
|
||||
openStdioFile(const std::string &filename, const char *mode) {
|
||||
return std::unique_ptr<FILE, decltype(&fclose)>(
|
||||
fopen_or_throw(filename.c_str(), mode), &fclose);
|
||||
}
|
||||
|
||||
|
||||
} // namespace ue2
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user