diff options
author | David Robillard <d@drobilla.net> | 2023-08-23 17:58:15 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-08-23 18:58:46 -0400 |
commit | 1420be7916429425f826a214d2bc7e1e19ae11e8 (patch) | |
tree | 4e7b6acb766d54bc559b810a3ef617c2c78d597c /src/posix | |
parent | 4f1822cd1e428252b0dfc5ba88c1147e91aa7aa8 (diff) | |
download | zix-1420be7916429425f826a214d2bc7e1e19ae11e8.tar.gz zix-1420be7916429425f826a214d2bc7e1e19ae11e8.tar.bz2 zix-1420be7916429425f826a214d2bc7e1e19ae11e8.zip |
Improve test coverage
Diffstat (limited to 'src/posix')
-rw-r--r-- | src/posix/filesystem_posix.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/posix/filesystem_posix.c b/src/posix/filesystem_posix.c index 8d65611..a5ac857 100644 --- a/src/posix/filesystem_posix.c +++ b/src/posix/filesystem_posix.c @@ -429,22 +429,23 @@ zix_current_path(ZixAllocator* const allocator) { #if defined(PATH_MAX) // Some POSIX systems have a static PATH_MAX so we can store it on the stack - char buffer[PATH_MAX] = {0}; - if (getcwd(buffer, PATH_MAX)) { - return copy_path(allocator, buffer, strlen(buffer)); - } + char buffer[PATH_MAX] = {0}; + char* const cwd = getcwd(buffer, PATH_MAX); + return cwd ? copy_path(allocator, cwd, strlen(cwd)) : NULL; #elif USE_PATHCONF // Others don't so we have to query PATH_MAX at runtime to allocate the result const size_t size = max_path_size(); char* const buffer = (char*)zix_calloc(allocator, size, 1); char* const current = getcwd(buffer, size); - if (current) { - return current; + if (!current) { + zix_free(allocator, buffer); } - zix_free(allocator, buffer); -#endif + return current; +#else return NULL; + +#endif } |