added util lib with file helpers

will have more stuff in the future
This commit is contained in:
Henny022p 2021-11-27 06:50:37 +01:00
parent 794d5fc97c
commit 3bda4ba3e8
4 changed files with 30 additions and 0 deletions

View File

@ -1,3 +1,6 @@
# libraries
add_subdirectory(util)
# binaries
add_subdirectory(agb2mid)
add_subdirectory(aif2pcm)
add_subdirectory(asset_processor)

View File

@ -0,0 +1,5 @@
add_library(util INTERFACE)
target_include_directories(util INTERFACE .)
# dummy target to make sure headers compile
add_executable(util_dummy dummy.cpp)

4
tools/src/util/dummy.cpp Normal file
View File

@ -0,0 +1,4 @@
#include "util/file.h"
int main() {
}

View File

@ -0,0 +1,18 @@
#ifndef TOOLS_FILE_H
#define TOOLS_FILE_H
#include <cstdio>
#include <memory>
#include <string_view>
namespace util {
namespace {
auto file_ptr_deleter = [](std::FILE* file) { std::fclose(file); };
}
using file_ptr_t = std::unique_ptr<std::FILE, decltype(file_ptr_deleter)>;
file_ptr_t open_file(std::string_view filename, std::string_view mode) {
return { std::fopen(filename.data(), mode.data()), file_ptr_deleter };
}
} // namespace util
#endif // TOOLS_FILE_H