aboutsummaryrefslogtreecommitdiff
path: root/libbb/lineedit.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2015-03-14 20:33:00 +0000
committerRon Yorston <rmy@pobox.com>2015-03-14 20:33:00 +0000
commita4f58436b78fe59e57620c6e0301f213ee25f273 (patch)
tree8355f724926e605280af2d6f2b1ccc6b1bd02dee /libbb/lineedit.c
parentba0c36cfcf84efbac6f89e27238e04bb57e9cd45 (diff)
parent49acc1a7618a28d34381cbb7661d7c981fcb238f (diff)
downloadbusybox-w32-a4f58436b78fe59e57620c6e0301f213ee25f273.tar.gz
busybox-w32-a4f58436b78fe59e57620c6e0301f213ee25f273.tar.bz2
busybox-w32-a4f58436b78fe59e57620c6e0301f213ee25f273.zip
Merge branch 'busybox' into merge
Conflicts: coreutils/od_bloaty.c libbb/lineedit.c
Diffstat (limited to 'libbb/lineedit.c')
-rw-r--r--libbb/lineedit.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 3d96a8e9f..7982f2997 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -714,23 +714,20 @@ static char *username_path_completion(char *ud)
714 */ 714 */
715static NOINLINE unsigned complete_username(const char *ud) 715static NOINLINE unsigned complete_username(const char *ud)
716{ 716{
717 /* Using _r function to avoid pulling in static buffers */ 717 struct passwd *pw;
718 char line_buff[256];
719 struct passwd pwd;
720 struct passwd *result;
721 unsigned userlen; 718 unsigned userlen;
722 719
723 ud++; /* skip ~ */ 720 ud++; /* skip ~ */
724 userlen = strlen(ud); 721 userlen = strlen(ud);
725 722
726 setpwent(); 723 setpwent();
727 while (!getpwent_r(&pwd, line_buff, sizeof(line_buff), &result)) { 724 while ((pw = getpwent()) != NULL) {
728 /* Null usernames should result in all users as possible completions. */ 725 /* Null usernames should result in all users as possible completions. */
729 if (/*!userlen || */ strncmp(ud, pwd.pw_name, userlen) == 0) { 726 if (/* !ud[0] || */ is_prefixed_with(pw->pw_name, ud)) {
730 add_match(xasprintf("~%s/", pwd.pw_name)); 727 add_match(xasprintf("~%s/", pw->pw_name));
731 } 728 }
732 } 729 }
733 endpwent(); 730 endpwent(); /* don't keep password file open */
734 731
735 return 1 + userlen; 732 return 1 + userlen;
736} 733}
@@ -845,7 +842,7 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type)
845 if (!pfind[0] && DOT_OR_DOTDOT(name_found)) 842 if (!pfind[0] && DOT_OR_DOTDOT(name_found))
846 continue; 843 continue;
847 /* match? */ 844 /* match? */
848 if (strncmp(name_found, pfind, pf_len) != 0) 845 if (!is_prefixed_with(name_found, pfind))
849 continue; /* no */ 846 continue; /* no */
850 847
851 found = concat_path_file(paths[i], name_found); 848 found = concat_path_file(paths[i], name_found);
@@ -1932,19 +1929,25 @@ static void parse_and_put_prompt(const char *prmt_ptr)
1932 cwd_buf = xrealloc_getcwd_or_warn(NULL); 1929 cwd_buf = xrealloc_getcwd_or_warn(NULL);
1933 if (!cwd_buf) 1930 if (!cwd_buf)
1934 cwd_buf = (char *)bb_msg_unknown; 1931 cwd_buf = (char *)bb_msg_unknown;
1935 else { 1932 else if (home_pwd_buf[0]) {
1933 char *after_home_user;
1934
1936 /* /home/user[/something] -> ~[/something] */ 1935 /* /home/user[/something] -> ~[/something] */
1937 l = strlen(home_pwd_buf);
1938 if (l != 0
1939#if !ENABLE_PLATFORM_MINGW32 1936#if !ENABLE_PLATFORM_MINGW32
1940 && strncmp(home_pwd_buf, cwd_buf, l) == 0 1937 after_home_user = is_prefixed_with(cwd_buf, home_pwd_buf);
1941#else 1938#else
1942 && strncasecmp(home_pwd_buf, cwd_buf, l) == 0 1939 after_home_user = NULL;
1940 l = strlen(home_pwd_buf);
1941 if (l != 0
1942 && strncasecmp(home_pwd_buf, cwd_buf, l) == 0) {
1943 after_home_user = cwd_buf + l;
1944 }
1943#endif 1945#endif
1944 && (cwd_buf[l] == '/' || cwd_buf[l] == '\0') 1946 if (after_home_user
1947 && (*after_home_user == '/' || *after_home_user == '\0')
1945 ) { 1948 ) {
1946 cwd_buf[0] = '~'; 1949 cwd_buf[0] = '~';
1947 overlapping_strcpy(cwd_buf + 1, cwd_buf + l); 1950 overlapping_strcpy(cwd_buf + 1, after_home_user);
1948 } 1951 }
1949 } 1952 }
1950 } 1953 }