diff options
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 |