summaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-09-29 23:55:30 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-09-29 23:55:30 +0000
commit43f0a0bb3a178794ac9fa3f5010db680c5d1b018 (patch)
tree7f3c2fae714d8260c100fbad6627c7ae4e8c43fe /libbb
parente755e827f7c8ecb21787a4369d7afdeda54d112b (diff)
downloadbusybox-w32-1_7_2.tar.gz
busybox-w32-1_7_2.tar.bz2
busybox-w32-1_7_2.zip
apply all post-1.7.1 patches, set version to 1.7.21_7_2
Diffstat (limited to 'libbb')
-rw-r--r--libbb/lineedit.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 62f8949d6..f2972e422 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -81,8 +81,9 @@ static int num_ok_lines = 1;
81#endif 81#endif
82 82
83#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR 83#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR
84static char *user_buf = (char*)""; 84static const char null_str[] = "";
85static char *home_pwd_buf = (char*)""; 85static char *user_buf;
86static char *home_pwd_buf = (char*)null_str;
86#endif 87#endif
87 88
88/* Put 'command_ps[cursor]', cursor++. 89/* Put 'command_ps[cursor]', cursor++.
@@ -311,7 +312,7 @@ static void username_tab_completion(char *ud, char *with_shash_flg)
311 312
312 if (with_shash_flg) { /* "~/..." or "~user/..." */ 313 if (with_shash_flg) { /* "~/..." or "~user/..." */
313 char *sav_ud = ud - 1; 314 char *sav_ud = ud - 1;
314 char *home = 0; 315 char *home = NULL;
315 char *temp; 316 char *temp;
316 317
317 if (*ud == '/') { /* "~/..." */ 318 if (*ud == '/') { /* "~/..." */
@@ -1119,7 +1120,7 @@ static void parse_prompt(const char *prmt_ptr)
1119 switch (c) { 1120 switch (c) {
1120#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR 1121#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR
1121 case 'u': 1122 case 'u':
1122 pbuf = user_buf; 1123 pbuf = user_buf ? user_buf : (char*)"";
1123 break; 1124 break;
1124#endif 1125#endif
1125 case 'h': 1126 case 'h':
@@ -1143,7 +1144,7 @@ static void parse_prompt(const char *prmt_ptr)
1143 case 'w': 1144 case 'w':
1144 pbuf = pwd_buf; 1145 pbuf = pwd_buf;
1145 l = strlen(home_pwd_buf); 1146 l = strlen(home_pwd_buf);
1146 if (home_pwd_buf[0] != 0 1147 if (l != 0
1147 && strncmp(home_pwd_buf, pbuf, l) == 0 1148 && strncmp(home_pwd_buf, pbuf, l) == 0
1148 && (pbuf[l]=='/' || pbuf[l]=='\0') 1149 && (pbuf[l]=='/' || pbuf[l]=='\0')
1149 && strlen(pwd_buf+l)<PATH_MAX 1150 && strlen(pwd_buf+l)<PATH_MAX
@@ -1253,6 +1254,11 @@ static void win_changed(int nsig)
1253#undef CTRL 1254#undef CTRL
1254#define CTRL(a) ((a) & ~0x40) 1255#define CTRL(a) ((a) & ~0x40)
1255 1256
1257/* Returns:
1258 * -1 on read errors or EOF, or on bare Ctrl-D.
1259 * 0 on ctrl-C,
1260 * >0 length of input string, including terminating '\n'
1261 */
1256int read_line_input(const char* prompt, char* command, int maxsize, line_input_t *st) 1262int read_line_input(const char* prompt, char* command, int maxsize, line_input_t *st)
1257{ 1263{
1258 int lastWasTab = FALSE; 1264 int lastWasTab = FALSE;
@@ -1305,8 +1311,14 @@ int read_line_input(const char* prompt, char* command, int maxsize, line_input_t
1305 1311
1306 entry = getpwuid(geteuid()); 1312 entry = getpwuid(geteuid());
1307 if (entry) { 1313 if (entry) {
1314 /* If we enter read_line_input for the Nth time,
1315 * they may be already allocated! Need to free. */
1316 free(user_buf);
1317 if (home_pwd_buf != null_str)
1318 free(home_pwd_buf);
1308 user_buf = xstrdup(entry->pw_name); 1319 user_buf = xstrdup(entry->pw_name);
1309 home_pwd_buf = xstrdup(entry->pw_dir); 1320 home_pwd_buf = xstrdup(entry->pw_dir);
1321 /* They are not freed on exit (too small to bother) */
1310 } 1322 }
1311 } 1323 }
1312#endif 1324#endif