blob: e4814e21594df9d58f7f22fe05ac94c983ff6d59 [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
Denys Vlasenkobae8fc42018-04-07 15:21:35 +020011/* Read a line from fp. If the first non-whitespace char is 'y' or 'Y',
Manuel Novoa III cad53642003-03-19 09:13:01 +000012 * return 1. Otherwise return 0.
Eric Andersenaad1a882001-03-16 22:47:14 +000013 */
Denys Vlasenkobae8fc42018-04-07 15:21:35 +020014int FAST_FUNC bb_ask_y_confirmation_FILE(FILE *fp)
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
Denys Vlasenkobae8fc42018-04-07 15:21:35 +020019 fflush_all();
20 while (((c = fgetc(fp)) != 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}
Denys Vlasenkobae8fc42018-04-07 15:21:35 +020028
29int FAST_FUNC bb_ask_y_confirmation(void)
30{
31 return bb_ask_y_confirmation_FILE(stdin);
32}