summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2013-07-01 19:16:40 +0400
committerIgor Pashev <pashev.igor@gmail.com>2013-07-10 16:00:55 +0400
commit7b9d51ef1a9a61108ff68a0eea9e3d28ed9ed0a3 (patch)
treeddd0e62daa430b4bec14c7e996a000acef962843
parentd1e644e59ee5eb679a7118b35a055e1249d250e2 (diff)
downloaddctrl-tools-7b9d51ef1a9a61108ff68a0eea9e3d28ed9ed0a3.tar.gz
Use custom get_current_dir_name
-rw-r--r--lib/fnutil.c29
1 files changed, 28 insertions, 1 deletions
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' */