BLI: add function for changing working directory #104525
|
@ -57,7 +57,7 @@
|
|||
#include "BLI_threads.h"
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
#if !defined (__APPLE__)
|
||||
#if !defined(__APPLE__)
|
||||
SonnyCampbell_Unity marked this conversation as resolved
|
||||
bool BLI_change_working_dir(const char *dir)
|
||||
{
|
||||
BLI_assert(BLI_thread_is_main());
|
||||
|
@ -65,24 +65,24 @@ bool BLI_change_working_dir(const char *dir)
|
|||
if (!BLI_is_dir(dir)) {
|
||||
return false;
|
||||
}
|
||||
#if defined(WIN32)
|
||||
# if defined(WIN32)
|
||||
SonnyCampbell_Unity marked this conversation as resolved
Bastien Montagne
commented
These (and the ones below inside the These (and the ones below inside the `#if !defined (__APPLE__)` block) should be indented (`# if defined(WIN32)`). clangformat should handle that for you if [configured in your IDE](https://wiki.blender.org/wiki/Tools/ClangFormat#IDE_Integration)... Otherwise please run `make format` before committing. ;)
|
||||
wchar_t wdir[FILE_MAX];
|
||||
if (conv_utf_8_to_16(dir, wdir, ARRAY_SIZE(wdir)) != 0) {
|
||||
return false;
|
||||
}
|
||||
return _wchdir(wdir) == 0;
|
||||
#else
|
||||
# else
|
||||
int result = chdir(dir);
|
||||
if (result == 0) {
|
||||
BLI_setenv("PWD", dir);
|
||||
}
|
||||
return result == 0;
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
|
||||
char *BLI_current_working_dir(char *dir, const size_t maxncpy)
|
||||
{
|
||||
#if defined(WIN32)
|
||||
# if defined(WIN32)
|
||||
wchar_t path[MAX_PATH];
|
||||
if (_wgetcwd(path, MAX_PATH)) {
|
||||
if (BLI_strncpy_wchar_as_utf8(dir, path, maxncpy) != maxncpy) {
|
||||
|
@ -90,7 +90,7 @@ char *BLI_current_working_dir(char *dir, const size_t maxncpy)
|
|||
}
|
||||
}
|
||||
return NULL;
|
||||
#else
|
||||
# else
|
||||
const char *pwd = BLI_getenv("PWD");
|
||||
if (pwd) {
|
||||
size_t srclen = BLI_strnlen(pwd, maxncpy);
|
||||
|
@ -101,9 +101,9 @@ char *BLI_current_working_dir(char *dir, const size_t maxncpy)
|
|||
return NULL;
|
||||
}
|
||||
return getcwd(dir, maxncpy);
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
#endif /* !defined (__APPLE__) */
|
||||
SonnyCampbell_Unity marked this conversation as resolved
Bastien Montagne
commented
Although not strictly mandatory, it's good practice to add a comment reminder of the entering condition when the closing Although not strictly mandatory, it's good practice to add a comment reminder of the entering condition when the closing `#endif` is a bit far away in code: `#endif /* !defined (__APPLE__) */`
|
||||
|
||||
double BLI_dir_free_space(const char *dir)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
I think it would be nice to have a comment here that explains that the Apple implementation lives in
storage_apply.mm
.