diff options
Diffstat (limited to 'src/path.c')
| -rw-r--r-- | src/path.c | 32 |
1 files changed, 26 insertions, 6 deletions
@@ -15,6 +15,8 @@ #include <fwd/path.h> #include <fwd/debug.h> +#include <fwd/tracker.h> +#include <fwd/coverage.h> char *fwd_basename(const char *file) { @@ -25,10 +27,19 @@ char *fwd_basename(const char *file) break; } + char *s = NULL; if (n == 0) - return strdup(file); + s = strdupc(file); + else + s = strndupc(file + n + 1, l - n); + + if (!s) { + internal_error("failed allocating basename"); + return NULL; + } - return strndup(file + n + 1, l - n); + track_ptr(s); + return s; } char *fwd_dirname(const char *file) @@ -40,7 +51,14 @@ char *fwd_dirname(const char *file) break; } - return strndup(file, n); + char *s = strndupc(file, n); + if (!s) { + internal_error("failed allocating dirname"); + return NULL; + } + + track_ptr(s); + return s; } char *fwd_cwdname() @@ -52,13 +70,15 @@ char *fwd_cwdname() else size = (size_t)path_max; - char *buf = malloc(size); - if (!buf) + char *buf = mallocc(size); + if (!buf) { + internal_error("failed allocating cwd buf"); return NULL; + } + track_ptr(buf); if (!getcwd(buf, size)) { error("%s\n", strerror(errno)); - free(buf); return NULL; } |
