From 5006226e945fc645e6d9b21252c9eee53cc191cc Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 23 Sep 2018 12:22:37 +0200 Subject: Fix various things, add generated zig header files to global include Fix compile_commands.json missing build steps. Fix c includes -> zig includes flags. Fix crash when running sibs new/init without defining lang. Add generated zig header files to global include so they can be used from c/c++. Add zig and zig/c (using zig and c in the same project) examples. --- src/FileUtil.cpp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src/FileUtil.cpp') diff --git a/src/FileUtil.cpp b/src/FileUtil.cpp index aca2778..53430c4 100644 --- a/src/FileUtil.cpp +++ b/src/FileUtil.cpp @@ -288,6 +288,31 @@ namespace sibs return Result::Err(strerror(errno)); } + Result createDirectory(const _tinydir_char_t *path) + { + size_t pathLength = strlen(path); + if(pathLength > _TINYDIR_PATH_MAX - 1) + { + string errMsg = "Directory path too long: "; + errMsg += string(path, pathLength); + return Result::Err(errMsg, ENAMETOOLONG); + } + + if(mkdir(path, S_IRWXU) != 0) + { + int error = errno; + if(error != EEXIST) + { + string errMsg = "Failed to create directory: "; + errMsg += toUtf8(path); + errMsg += "; reason: "; + errMsg += strerror(error); + return Result::Err(errMsg, error); + } + } + return Result::Ok(true); + } + Result createDirectoryRecursive(const _tinydir_char_t *path) { char pathBuffer[_TINYDIR_PATH_MAX]; @@ -303,7 +328,8 @@ namespace sibs char *p = pathBuffer; for(size_t i = 0; i < pathLength; ++i) { - if(i > 0 && *p == '/') + char c = *p; + if(i > 0 && (c == '/' || c == '\\')) { *p = '\0'; if(mkdir(pathBuffer, S_IRWXU) != 0) @@ -318,7 +344,7 @@ namespace sibs return Result::Err(errMsg, error); } } - *p = '/'; + *p = c; } ++p; } -- cgit v1.2.3