Mercurial > dovecot > original-hg > dovecot-1.2
changeset 4984:0caa09cc3edb HEAD
Added home_try_expand()
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 04 Jan 2007 00:38:27 +0200 |
parents | 8089e7461519 |
children | c2a4ea08d681 |
files | src/lib/home-expand.c src/lib/home-expand.h |
diffstat | 2 files changed, 19 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/home-expand.c Sun Dec 31 18:11:14 2006 +0200 +++ b/src/lib/home-expand.c Thu Jan 04 00:38:27 2007 +0200 @@ -6,14 +6,14 @@ #include <stdlib.h> #include <pwd.h> -/* expand ~/ or ~user/ in beginning of path */ -const char *home_expand(const char *path) +int home_try_expand(const char **_path) { + const char *path = *_path; const char *home, *p, *orig_path; struct passwd *pw; if (path == NULL || *path != '~') - return path; + return 0; orig_path = path++; if (*path == '/' || *path == '\0') { @@ -33,9 +33,17 @@ } if (home == NULL) - return orig_path; - else if (*path == '\0') - return t_strdup(home); + return -1; + + if (*path == '\0') + *_path = t_strdup(home); else - return t_strconcat(home, "/", path, NULL); + *_path = t_strconcat(home, "/", path, NULL); + return 0; } + +const char *home_expand(const char *path) +{ + (void)home_try_expand(&path); + return path; +}
--- a/src/lib/home-expand.h Sun Dec 31 18:11:14 2006 +0200 +++ b/src/lib/home-expand.h Thu Jan 04 00:38:27 2007 +0200 @@ -1,7 +1,10 @@ #ifndef __HOME_EXPAND_H #define __HOME_EXPAND_H -/* expand ~/ or ~user/ in beginning of path */ +/* expand ~/ or ~user/ in beginning of path. If user is unknown, the original + path is returned without modification. */ const char *home_expand(const char *path); +/* Returns 0 if ok, -1 if user wasn't found. */ +int home_try_expand(const char **path); #endif