]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Added t_abspath*().
authorTimo Sirainen <tss@iki.fi>
Fri, 11 Dec 2009 23:36:19 +0000 (18:36 -0500)
committerTimo Sirainen <tss@iki.fi>
Fri, 11 Dec 2009 23:36:19 +0000 (18:36 -0500)
--HG--
branch : HEAD

src/lib/Makefile.am
src/lib/abspath.c [new file with mode: 0644]
src/lib/abspath.h [new file with mode: 0644]

index 6c86278a45e8009c2a44ffdd4c3cb383eb456897..6269d6d2b9ca17fd19eeeba7abf42a3cb08eb277 100644 (file)
@@ -9,6 +9,7 @@ $(srcdir)/unicodemap.c: unicodemap.pl
        perl $(srcdir)/unicodemap.pl < UnicodeData.txt > $@
 
 liblib_la_SOURCES = \
+       abspath.c \
        array.c \
        aqueue.c \
        askpass.c \
@@ -113,6 +114,7 @@ liblib_la_SOURCES = \
        write-full.c
 
 headers = \
+       abspath.h \
        aqueue.h \
        array.h \
        array-decl.h \
diff --git a/src/lib/abspath.c b/src/lib/abspath.c
new file mode 100644 (file)
index 0000000..88bc4e3
--- /dev/null
@@ -0,0 +1,26 @@
+/* Copyright (c) 2009 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "abspath.h"
+
+#include <unistd.h>
+
+const char *t_abspath(const char *path)
+{
+       char dir[PATH_MAX];
+
+       if (*path == '/')
+               return path;
+
+       if (getcwd(dir, sizeof(dir)) == NULL)
+               i_fatal("getcwd() failed: %m");
+       return t_strconcat(dir, "/", path, NULL);
+}
+
+const char *t_abspath_to(const char *path, const char *root)
+{
+       if (*path == '/')
+               return path;
+
+       return t_strconcat(root, "/", path, NULL);
+}
diff --git a/src/lib/abspath.h b/src/lib/abspath.h
new file mode 100644 (file)
index 0000000..ee174a9
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef ABSPATH_H
+#define ABSPATH_H
+
+/* Returns path as absolute path. If it's not already absolute path,
+   it's assumed to be relative to current working directory. */
+const char *t_abspath(const char *path);
+/* Like t_abspath(), but path is relative to given root. */
+const char *t_abspath_to(const char *path, const char *root);
+
+#endif