blob: 646ec4b7e1d3cfefd490bd633258a63792d8b14f [file] [log] [blame]
Eric Andersenaad1a882001-03-16 22:47:14 +00001/* vi: set sw=4 ts=4: */
2/*
Manuel Novoa III cad53642003-03-19 09:13:01 +00003 * bb_ask_confirmation implementation for busybox
Eric Andersenaad1a882001-03-16 22:47:14 +00004 *
Manuel Novoa III cad53642003-03-19 09:13:01 +00005 * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org>
Eric Andersenaad1a882001-03-16 22:47:14 +00006 *
"Robert P. J. Day"5d8843e2006-07-10 11:41:19 +00007 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Manuel Novoa III cad53642003-03-19 09:13:01 +00008 */
9
10/* Read a line from stdin. If the first non-whitespace char is 'y' or 'Y',
11 * return 1. Otherwise return 0.
Eric Andersenaad1a882001-03-16 22:47:14 +000012 */
13
Eric Andersenaad1a882001-03-16 22:47:14 +000014#include "libbb.h"
15
Manuel Novoa III cad53642003-03-19 09:13:01 +000016int bb_ask_confirmation(void)
Eric Andersenaad1a882001-03-16 22:47:14 +000017{
Manuel Novoa III cad53642003-03-19 09:13:01 +000018 int retval = 0;
19 int first = 1;
20 int c;
Eric Andersenaad1a882001-03-16 22:47:14 +000021
Manuel Novoa III cad53642003-03-19 09:13:01 +000022 while (((c = getchar()) != EOF) && (c != '\n')) {
23 /* Make sure we get the actual function call for isspace,
24 * as speed is not critical here. */
25 if (first && !(isspace)(c)) {
26 --first;
27 if ((c == 'y') || (c == 'Y')) {
28 ++retval;
29 }
Eric Andersenaad1a882001-03-16 22:47:14 +000030 }
31 }
Eric Andersenaad1a882001-03-16 22:47:14 +000032
Manuel Novoa III cad53642003-03-19 09:13:01 +000033 return retval;
34}