From d9090882cae78695765204a3e1b60c6a9bf27977 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 9 Dec 2017 02:43:02 +0100 Subject: Added ninja backend, very simple project works --- src/FileUtil.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/FileUtil.cpp') diff --git a/src/FileUtil.cpp b/src/FileUtil.cpp index 30fe03d..8502e84 100644 --- a/src/FileUtil.cpp +++ b/src/FileUtil.cpp @@ -18,6 +18,7 @@ namespace sibs } } + // TODO: Handle failure (directory doesn't exist, no permission etc) void walkDirFiles(const char *directory, FileWalkCallbackFunc callbackFunc) { tinydir_dir dir; @@ -50,6 +51,7 @@ namespace sibs size_t fileSize = ftell(file); fseek(file, 0, SEEK_SET); + // TODO: Change this to string so it can be deallocated and use std::move to prevent copies char *result = (char*)malloc(fileSize + 1); if(!result) { @@ -62,4 +64,16 @@ namespace sibs fclose(file); return Result::Ok(StringView(result, fileSize)); } + + bool fileOverwrite(const char *filepath, StringView data) + { + FILE *file = fopen(filepath, "wb"); + if(!file || errno != 0) + { + perror(filepath); + return false; + } + fwrite(data.data, 1, data.size, file); + fclose(file); + } } \ No newline at end of file -- cgit v1.2.3