Last active
April 27, 2020 16:48
-
-
Save danielhams/871743b55bf93b79350556940defdd96 to your computer and use it in GitHub Desktop.
Suggested approach to fixing ninja getcwd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Previous code like this: | |
-------------------------- | |
bool first = true; | |
vector<char> cwd; | |
char* success = NULL; | |
do { | |
cwd.resize(cwd.size() + 1024); | |
errno = 0; | |
success = getcwd(&cwd[0], cwd.size()); | |
} while (!success && errno == ERANGE); | |
if (!success) { | |
Error("cannot determine working directory: %s", strerror(errno)); | |
return 1; | |
} | |
-------------------------- | |
Something like this I guess: | |
-------------------------- | |
bool first = true; | |
vector<char> cwd; | |
#if defined(__sgi) | |
errno = 0; | |
char * libcgetcwd = getcwd(NULL,-1); | |
if( libcgetcwd == NULL ) { | |
Error("cannot determine working directory: %s", strerror(errno)); | |
return 1; | |
} else { | |
cwd.resize(strlen(libcgetcwd)+1); | |
strcpy(&cwd[0],libcgetcwd); | |
free(libcgetcwd); | |
} | |
errno = 0; | |
#else | |
char * success; | |
do { | |
cwd.resize(cwd.size() + 1024); | |
errno = 0; | |
success = getcwd(&cwd[0], cwd.size()); | |
} while (!success && errno == ERANGE); | |
if (!success) { | |
Error("cannot determine working directory: %s", strerror(errno)); | |
return 1; | |
} | |
#endif | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment