aboutsummaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2023-08-11 10:40:58 +0000
committerOmar Polo <op@omarpolo.com>2023-08-11 10:40:58 +0000
commit07ad49102564bf72092cc8080322852308490065 (patch)
treede6669ffc74ac7c58f18ad59fc8faf336d5a64ef /utils.c
parent95500a936a1b0e42d304315fd2f7ae20ca391042 (diff)
getcwd(NULL) is an extension; don't rely on it
also, while here, add some error checking too
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/utils.c b/utils.c
index f75fa1c..47a9a21 100644
--- a/utils.c
+++ b/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;
}