diff options
author | Thomas <thomas@xteddy.org> | 2013-10-11 14:33:29 +0100 |
---|---|---|
committer | Thomas <thomas@xteddy.org> | 2013-10-11 14:33:29 +0100 |
commit | 7f479ffdce8f49f6c57d575b708c4cbe8cbe18df (patch) | |
tree | c0b1ddfb340c9bd59bbc02e83f30bf34aeb29a88 /cmd-string.c | |
parent | c190c73240576aa2a8274a305844f1fa7fcb0e71 (diff) | |
parent | 4901d9ddc8d8c33ecdca363dcb67e66482745fa5 (diff) | |
download | rtmux-7f479ffdce8f49f6c57d575b708c4cbe8cbe18df.tar.gz rtmux-7f479ffdce8f49f6c57d575b708c4cbe8cbe18df.tar.bz2 rtmux-7f479ffdce8f49f6c57d575b708c4cbe8cbe18df.zip |
Merge branch 'obsd-master' into mtemp
Diffstat (limited to 'cmd-string.c')
-rw-r--r-- | cmd-string.c | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/cmd-string.c b/cmd-string.c index 7e84eda6..e793ea02 100644 --- a/cmd-string.c +++ b/cmd-string.c @@ -318,10 +318,13 @@ cmd_string_expand_tilde(const char *s, size_t *p) { struct passwd *pw; struct environ_entry *envent; - char *home, *path, *username; + char *home, *path, *user, *cp; + int last; home = NULL; - if (cmd_string_getc(s, p) == '/') { + + last = cmd_string_getc(s, p); + if (last == EOF || last == '/' || last == ' '|| last == '\t') { envent = environ_find(&global_environ, "HOME"); if (envent != NULL && *envent->value != '\0') home = envent->value; @@ -329,15 +332,27 @@ cmd_string_expand_tilde(const char *s, size_t *p) home = pw->pw_dir; } else { cmd_string_ungetc(p); - if ((username = cmd_string_string(s, p, '/', 0)) == NULL) - return (NULL); - if ((pw = getpwnam(username)) != NULL) + + cp = user = xmalloc(strlen(s)); + for (;;) { + last = cmd_string_getc(s, p); + if (last == EOF || last == '/' || last == ' '|| last == '\t') + break; + *cp++ = last; + } + *cp = '\0'; + + if ((pw = getpwnam(user)) != NULL) home = pw->pw_dir; - free(username); + free(user); } + if (home == NULL) return (NULL); - xasprintf(&path, "%s/", home); + if (last != EOF) + xasprintf(&path, "%s%c", home, last); + else + xasprintf(&path, "%s", home); return (path); } |