Store the original working directory in a strbuf instead of in a
fixed-sized buffer, in order to be able to handle longer paths.
Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
* here so that we can chdir() back to it at the end of the
* function:
*/
- char cwd[1024] = "";
+ struct strbuf cwd = STRBUF_INIT;
int buf_index = 1;
}
if (*buf) {
- if (!*cwd && !getcwd(cwd, sizeof(cwd))) {
+ if (!cwd.len && strbuf_getcwd(&cwd)) {
if (die_on_error)
die_errno("Could not get current working directory");
else
retval = buf;
error_out:
free(last_elem);
- if (*cwd && chdir(cwd))
- die_errno("Could not change back to '%s'", cwd);
+ if (cwd.len && chdir(cwd.buf))
+ die_errno("Could not change back to '%s'", cwd.buf);
+ strbuf_release(&cwd);
return retval;
}