Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | ||||
Denys Vlasenko | 77cb6b9 | 2018-04-07 15:08:12 +0200 | [diff] [blame] | 3 | * bb_ask_y_confirmation implementation for busybox |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 4 | * |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 5 | * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org> |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 6 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 8 | */ |
Denys Vlasenko | ebe6d9d | 2017-10-05 14:40:24 +0200 | [diff] [blame] | 9 | #include "libbb.h" |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 10 | |
Denys Vlasenko | bae8fc4 | 2018-04-07 15:21:35 +0200 | [diff] [blame] | 11 | /* Read a line from fp. If the first non-whitespace char is 'y' or 'Y', |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 12 | * return 1. Otherwise return 0. |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 13 | */ |
Denys Vlasenko | bae8fc4 | 2018-04-07 15:21:35 +0200 | [diff] [blame] | 14 | int FAST_FUNC bb_ask_y_confirmation_FILE(FILE *fp) |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 15 | { |
Denys Vlasenko | 52b971f | 2009-10-27 09:49:04 +0100 | [diff] [blame] | 16 | char first = 0; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 17 | int c; |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 18 | |
Denys Vlasenko | bae8fc4 | 2018-04-07 15:21:35 +0200 | [diff] [blame] | 19 | fflush_all(); |
20 | while (((c = fgetc(fp)) != EOF) && (c != '\n')) { | ||||
Denys Vlasenko | 52b971f | 2009-10-27 09:49:04 +0100 | [diff] [blame] | 21 | if (first == 0 && !isblank(c)) { |
22 | first = c|0x20; | ||||
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 23 | } |
24 | } | ||||
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 25 | |
Denys Vlasenko | 52b971f | 2009-10-27 09:49:04 +0100 | [diff] [blame] | 26 | return first == 'y'; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 27 | } |
Denys Vlasenko | bae8fc4 | 2018-04-07 15:21:35 +0200 | [diff] [blame] | 28 | |
29 | int FAST_FUNC bb_ask_y_confirmation(void) | ||||
30 | { | ||||
31 | return bb_ask_y_confirmation_FILE(stdin); | ||||
32 | } |