blob: d95729cc99beff60d823c4531723a525ada5004b [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 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02007 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
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 */
Eric Andersenaad1a882001-03-16 22:47:14 +000013#include "libbb.h"
14
Denis Vlasenkodefc1ea2008-06-27 02:52:20 +000015int FAST_FUNC bb_ask_confirmation(void)
Eric Andersenaad1a882001-03-16 22:47:14 +000016{
Denys Vlasenko52b971f2009-10-27 09:49:04 +010017 char first = 0;
Manuel Novoa III cad53642003-03-19 09:13:01 +000018 int c;
Eric Andersenaad1a882001-03-16 22:47:14 +000019
Manuel Novoa III cad53642003-03-19 09:13:01 +000020 while (((c = getchar()) != EOF) && (c != '\n')) {
Denys Vlasenko52b971f2009-10-27 09:49:04 +010021 if (first == 0 && !isblank(c)) {
22 first = c|0x20;
Eric Andersenaad1a882001-03-16 22:47:14 +000023 }
24 }
Eric Andersenaad1a882001-03-16 22:47:14 +000025
Denys Vlasenko52b971f2009-10-27 09:49:04 +010026 return first == 'y';
Manuel Novoa III cad53642003-03-19 09:13:01 +000027}