diff options
author | dec05eba <dec05eba@protonmail.com> | 2017-12-09 02:43:02 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2017-12-09 02:43:02 +0100 |
commit | d9090882cae78695765204a3e1b60c6a9bf27977 (patch) | |
tree | e3e75fef97df7e02cd715af718ae7c3ffeaee00f /src/FileUtil.cpp | |
parent | fb2072deb3e50afdb062570a3a80ec1afb5bfb56 (diff) |
Added ninja backend, very simple project works
Diffstat (limited to 'src/FileUtil.cpp')
-rw-r--r-- | src/FileUtil.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
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<StringView>::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 |