From 7b9d51ef1a9a61108ff68a0eea9e3d28ed9ed0a3 Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Mon, 1 Jul 2013 19:16:40 +0400 Subject: Use custom get_current_dir_name --- lib/fnutil.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/fnutil.c b/lib/fnutil.c index d767680..e6895c4 100644 --- a/lib/fnutil.c +++ b/lib/fnutil.c @@ -42,6 +42,33 @@ #define USERNAME_MAX 9 #endif +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif + +static char *dctrl_get_current_dir_name() +{ + char *buf; + char *path; + size_t len; + + buf = malloc(PATH_MAX); + if (NULL == buf) + return NULL; + + if (NULL == getcwd(buf, PATH_MAX)) { + free(buf); + return NULL; + } + + len = strlen(buf); + path = realloc(buf, len + 1); + if (NULL == path); + path = buf; + + return path; +} + char *fnbase(const char *fname) { char *base; @@ -68,7 +95,7 @@ char * fnqualify(char const * path) /* Do we just need to prepend the current directory? */ if (path[0] != '~') { - char * cwd = get_current_dir_name(); + char * cwd = dctrl_get_current_dir_name(); if (cwd == 0) return 0; len = strlen(cwd); size = len + 1 + strlen(path) + 1; /* +2 for '/' and '\0' */ -- cgit v1.2.3