summaryrefslogtreecommitdiff
path: root/common/console.c
diff options
context:
space:
mode:
authorPierre Aubert <p.aubert@staubli.com>2014-04-24 10:30:07 +0200
committerPantelis Antoniou <panto@antoniou-consulting.com>2014-05-23 11:53:05 +0300
commita5dffa4b67fb0ad635088c9853abf6fcb181ac3c (patch)
tree5fd9cf1fc261a3ad69045731c1ccdfcb0caaa75e /common/console.c
parent91fdabc67aebc2468ad362c02449f215e0971c68 (diff)
downloadu-boot-imx-a5dffa4b67fb0ad635088c9853abf6fcb181ac3c.zip
u-boot-imx-a5dffa4b67fb0ad635088c9853abf6fcb181ac3c.tar.gz
u-boot-imx-a5dffa4b67fb0ad635088c9853abf6fcb181ac3c.tar.bz2
Add the function 'confirm_yesno' for interactive
User's confirmation is asked in different commands. This commit adds a function for such confirmation. Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com> Signed-off-by: Pierre Aubert <p.aubert@staubli.com>
Diffstat (limited to 'common/console.c')
-rw-r--r--common/console.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/common/console.c b/common/console.c
index 2dfb788..5453726 100644
--- a/common/console.c
+++ b/common/console.c
@@ -537,7 +537,33 @@ int ctrlc(void)
}
return 0;
}
-
+/* Reads user's confirmation.
+ Returns 1 if user's input is "y", "Y", "yes" or "YES"
+*/
+int confirm_yesno(void)
+{
+ int i;
+ char str_input[5];
+
+ /* Flush input */
+ while (tstc())
+ getc();
+ i = 0;
+ while (i < sizeof(str_input)) {
+ str_input[i] = getc();
+ putc(str_input[i]);
+ if (str_input[i] == '\r')
+ break;
+ i++;
+ }
+ putc('\n');
+ if (strncmp(str_input, "y\r", 2) == 0 ||
+ strncmp(str_input, "Y\r", 2) == 0 ||
+ strncmp(str_input, "yes\r", 4) == 0 ||
+ strncmp(str_input, "YES\r", 4) == 0)
+ return 1;
+ return 0;
+}
/* pass 1 to disable ctrlc() checking, 0 to enable.
* returns previous state
*/