blob: ccd983c29f224311587edf215f3bbdb29d770aa5 [file] [log] [blame]
Eric Andersenaad1a882001-03-16 22:47:14 +00001/* vi: set sw=4 ts=4: */
2/*
Denys Vlasenko77cb6b92018-04-07 15:08:12 +02003 * bb_ask_y_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 */
Denys Vlasenkoebe6d9d2017-10-05 14:40:24 +02009#include "libbb.h"
Manuel Novoa III cad53642003-03-19 09:13:01 +000010
11/* Read a line from stdin. If the first non-whitespace char is 'y' or 'Y',
12 * return 1. Otherwise return 0.
Eric Andersenaad1a882001-03-16 22:47:14 +000013 */
Denys Vlasenko77cb6b92018-04-07 15:08:12 +020014int FAST_FUNC bb_ask_y_confirmation(void)
Eric Andersenaad1a882001-03-16 22:47:14 +000015{
Denys Vlasenko52b971f2009-10-27 09:49:04 +010016 char first = 0;
Manuel Novoa III cad53642003-03-19 09:13:01 +000017 int c;
Eric Andersenaad1a882001-03-16 22:47:14 +000018
Manuel Novoa III cad53642003-03-19 09:13:01 +000019 while (((c = getchar()) != EOF) && (c != '\n')) {
Denys Vlasenko52b971f2009-10-27 09:49:04 +010020 if (first == 0 && !isblank(c)) {
21 first = c|0x20;
Eric Andersenaad1a882001-03-16 22:47:14 +000022 }
23 }
Eric Andersenaad1a882001-03-16 22:47:14 +000024
Denys Vlasenko52b971f2009-10-27 09:49:04 +010025 return first == 'y';
Manuel Novoa III cad53642003-03-19 09:13:01 +000026}