about summary refs log tree commit diff stats
path: root/xombrero.c
diff options
context:
space:
mode:
authorJosh Rickmar <jrick@devio.us>2012-06-01 17:40:07 -0400
committerJosh Rickmar <jrick@devio.us>2012-06-01 17:40:07 -0400
commitbd853cb3f256c4faeb9295c87435c1a1eadafd29 (patch)
tree3d0a76b392b32c6fe011e61631475fcce3bdedce /xombrero.c
parent1e2c5ad606b967ebff3f1f81c7e49b48520c8f6a (diff)
downloadxombrero-bd853cb3f256c4faeb9295c87435c1a1eadafd29.tar.gz
Fix some random stuff the rebasing lost. At least the build still
works, will have to check later to make sure all the other features
got in.
Diffstat (limited to 'xombrero.c')
-rw-r--r--xombrero.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/xombrero.c b/xombrero.c
index 4a34938..19c3a88 100644
--- a/xombrero.c
+++ b/xombrero.c
@@ -1345,6 +1345,35 @@ save_tabs_and_quit(struct tab *t, struct karg *args)
 	return (1);
 }
 
+void
+expand_tilde(char *path, size_t len, const char *s)
+{
+	struct passwd		*pwd;
+	int			i;
+	char			user[LOGIN_NAME_MAX];
+	const char		*sc = s;
+
+	if (path == NULL || s == NULL)
+		errx(1, "expand_tilde");
+
+	if (s[0] != '~') {
+		strlcpy(path, sc, len);
+		return;
+	}
+
+	++s;
+	for (i = 0; s[i] != '/' && s[i] != '\0'; ++i)
+		user[i] = s[i];
+	user[i] = '\0';
+	s = &s[i];
+
+	pwd = strlen(user) == 0 ? getpwuid(getuid()) : getpwnam(user);
+	if (pwd == NULL)
+		strlcpy(path, sc, len);
+	else
+		snprintf(path, len, "%s%s", pwd->pw_dir, s);
+}
+
 int
 run_page_script(struct tab *t, struct karg *args)
 {