mirror of https://github.com/omar-polo/gmid.git
getcwd(NULL) is an extension; don't rely on it
also, while here, add some error checking too
This commit is contained in:
parent
95500a936a
commit
07ad491025
6
utils.c
6
utils.c
|
@ -67,7 +67,7 @@ ends_with(const char *str, const char *sufx)
|
|||
char *
|
||||
absolutify_path(const char *path)
|
||||
{
|
||||
char *wd, *r;
|
||||
char wd[PATH_MAX], *r;
|
||||
|
||||
if (*path == '/') {
|
||||
if ((r = strdup(path)) == NULL)
|
||||
|
@ -75,10 +75,10 @@ absolutify_path(const char *path)
|
|||
return r;
|
||||
}
|
||||
|
||||
wd = getcwd(NULL, 0);
|
||||
if (getcwd(wd, sizeof(wd)) == NULL)
|
||||
fatal("getcwd");
|
||||
if (asprintf(&r, "%s/%s", wd, path) == -1)
|
||||
fatal("asprintf");
|
||||
free(wd);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue