[U-Boot] [PATCH 3/5] readline(): Add ability to modify a string buffer

Peter Tyser ptyser at xes-inc.com
Fri Oct 23 02:59:21 CEST 2009


If the 'buf' parameter is a non-0-length string, its contents will be
edited.  Previously, the initial value of 'buf' was ignored and the
user entered its contents from scratch.

Signed-off-by: Peter Tyser <ptyser at xes-inc.com>
---
 common/main.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/common/main.c b/common/main.c
index b47e443..10d8904 100644
--- a/common/main.c
+++ b/common/main.c
@@ -720,6 +720,10 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len)
 	int insert = 1;
 	int esc_len = 0;
 	char esc_save[8];
+	int init_len = strlen(buf);
+
+	if (init_len)
+		cread_add_str(buf, init_len, 1, &num, &eol_num, buf, *len);
 
 	while (1) {
 #ifdef CONFIG_BOOT_RETRY_TIME
@@ -937,6 +941,12 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len)
  */
 int readline (const char *const prompt)
 {
+	/*
+	 * If console_buffer isn't 0-length the user will be prompted to modify
+	 * it instead of entering it from scratch as desired.
+	 */
+	console_buffer[0] = '\0';
+
 	return readline_into_buffer(prompt, console_buffer);
 }
 
-- 
1.6.2.1



More information about the U-Boot mailing list