blob: 4642fa03667343fafab5859899a7646c9f7cb19d [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
14#include <stdio.h>
Manuel Novoa III cad53642003-03-19 09:13:01 +000015#include <ctype.h>
Eric Andersenaad1a882001-03-16 22:47:14 +000016#include "libbb.h"
17
Manuel Novoa III cad53642003-03-19 09:13:01 +000018int bb_ask_confirmation(void)
Eric Andersenaad1a882001-03-16 22:47:14 +000019{
Manuel Novoa III cad53642003-03-19 09:13:01 +000020 int retval = 0;
21 int first = 1;
22 int c;
Eric Andersenaad1a882001-03-16 22:47:14 +000023
Manuel Novoa III cad53642003-03-19 09:13:01 +000024 while (((c = getchar()) != EOF) && (c != '\n')) {
25 /* Make sure we get the actual function call for isspace,
26 * as speed is not critical here. */
27 if (first && !(isspace)(c)) {
28 --first;
29 if ((c == 'y') || (c == 'Y')) {
30 ++retval;
31 }
Eric Andersenaad1a882001-03-16 22:47:14 +000032 }
33 }
Eric Andersenaad1a882001-03-16 22:47:14 +000034
Manuel Novoa III cad53642003-03-19 09:13:01 +000035 return retval;
36}