diff options
Diffstat (limited to 'libcontacts_get_path.c')
-rw-r--r-- | libcontacts_get_path.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/libcontacts_get_path.c b/libcontacts_get_path.c new file mode 100644 index 0000000..cc20b7d --- /dev/null +++ b/libcontacts_get_path.c @@ -0,0 +1,23 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +char * +libcontacts_get_path(const char *id, const struct passwd *user) +{ + size_t len; + char *buf; + + if (!id || !user || !user->pw_dir || !*user->pw_dir) { + errno = EINVAL; + return NULL; + } + + len = strlen(user->pw_dir) + sizeof("/.config/contacts/") + strlen(id); + buf = malloc(len); + if (!buf) + return NULL; + + stpcpy(stpcpy(stpcpy(buf, user->pw_dir), "/.config/contacts/"), id); + return buf; +} |