From dbe0fd17f2323f108715db0bd0f734e9563e40d8 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 8 May 2013 12:27:25 -0400 Subject: mtd-utils: new prompt() helper for talking to the user We've got a few tools that prompt the user for "yes/no" questions. Add a common helper to simplify the various implementations. Signed-off-by: Mike Frysinger Signed-off-by: Artem Bityutskiy --- ftl_format.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'ftl_format.c') diff --git a/ftl_format.c b/ftl_format.c index 0f69b8f..b58677f 100644 --- a/ftl_format.c +++ b/ftl_format.c @@ -51,6 +51,7 @@ #include #include #include +#include "common.h" /*====================================================================*/ @@ -164,15 +165,9 @@ static int format_partition(int fd, int quiet, int interrogate, fflush(stdout); } - if (interrogate) { - char str[3]; - printf("This will destroy all data on the target device. " - "Confirm (y/n): "); - if (fgets(str, 3, stdin) == NULL) + if (interrogate) + if (!prompt("This will destroy all data on the target device. Confirm?", false)) return -1; - if ((strcmp(str, "y\n") != 0) && (strcmp(str, "Y\n") != 0)) - return -1; - } /* Create basic block allocation table for control blocks */ nbam = ((mtd.erasesize >> hdr.BlockSize) * sizeof(u_int) -- cgit v1.2.3