Skip to content

Instantly share code, notes, and snippets.

@danielhams
Last active April 27, 2020 16:48
Show Gist options
  • Save danielhams/871743b55bf93b79350556940defdd96 to your computer and use it in GitHub Desktop.
Save danielhams/871743b55bf93b79350556940defdd96 to your computer and use it in GitHub Desktop.
Suggested approach to fixing ninja getcwd
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