[dovecot-cvs] dovecot/src/lib home-expand.c, 1.2, 1.2.2.1 home-expand.h, 1.1, 1.1.2.1

tss at dovecot.org tss at dovecot.org
Wed Jan 3 22:38:27 UTC 2007


Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv9177

Modified Files:
      Tag: branch_1_0
	home-expand.c home-expand.h 
Log Message:
Added home_try_expand()


Index: home-expand.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/home-expand.c,v
retrieving revision 1.2
retrieving revision 1.2.2.1
diff -u -d -r1.2 -r1.2.2.1
--- home-expand.c	1 Jul 2003 18:48:13 -0000	1.2
+++ home-expand.c	3 Jan 2007 22:38:25 -0000	1.2.2.1
@@ -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;
 }

Index: home-expand.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/home-expand.h,v
retrieving revision 1.1
retrieving revision 1.1.2.1
diff -u -d -r1.1 -r1.1.2.1
--- home-expand.h	11 Feb 2003 19:37:16 -0000	1.1
+++ home-expand.h	3 Jan 2007 22:38:25 -0000	1.1.2.1
@@ -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



More information about the dovecot-cvs mailing list