From: Timo Sirainen Date: Fri, 11 Dec 2009 23:36:19 +0000 (-0500) Subject: Added t_abspath*(). X-Git-Tag: 2.0.beta1~21 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9d930f59fda0bac96da3c5b3e3374a81e279527e;p=thirdparty%2Fdovecot%2Fcore.git Added t_abspath*(). --HG-- branch : HEAD --- diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 6c86278a45..6269d6d2b9 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -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 index 0000000000..88bc4e3a67 --- /dev/null +++ b/src/lib/abspath.c @@ -0,0 +1,26 @@ +/* Copyright (c) 2009 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "abspath.h" + +#include + +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 index 0000000000..ee174a92ab --- /dev/null +++ b/src/lib/abspath.h @@ -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