From 39813fb7ac3e622b25f27dcd78e98242e121011e Mon Sep 17 00:00:00 2001 From: Wang Shilong Date: Wed, 18 Sep 2013 16:27:35 +0800 Subject: Btrfs-progs: move ask_user() to utils.c Signed-off-by: Wang Shilong Signed-off-by: David Sterba Signed-off-by: Chris Mason --- utils.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'utils.c') diff --git a/utils.c b/utils.c index d365380e..5fa193b4 100644 --- a/utils.c +++ b/utils.c @@ -1957,3 +1957,21 @@ int is_vol_small(char *file) return 0; } } + +/* + * This reads a line from the stdin and only returns non-zero if the + * first whitespace delimited token is a case insensitive match with yes + * or y. + */ +int ask_user(char *question) +{ + char buf[30] = {0,}; + char *saveptr = NULL; + char *answer; + + printf("%s [y/N]: ", question); + + return fgets(buf, sizeof(buf) - 1, stdin) && + (answer = strtok_r(buf, " \t\n\r", &saveptr)) && + (!strcasecmp(answer, "yes") || !strcasecmp(answer, "y")); +} -- cgit v1.2.3