1 /* vi: set sw=4 ts=4: */
2 /*
3  * bb_ask_y_confirmation implementation for busybox
4  *
5  * Copyright (C) 2003  Manuel Novoa III  <mjn3@codepoet.org>
6  *
7  * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8  */
9 #include "libbb.h"
10 
11 /* Read a line from fp.  If the first non-whitespace char is 'y' or 'Y',
12  * return 1.  Otherwise return 0.
13  */
bb_ask_y_confirmation_FILE(FILE * fp)14 int FAST_FUNC bb_ask_y_confirmation_FILE(FILE *fp)
15 {
16 	char first = 0;
17 	int c;
18 
19 	fflush_all();
20 	while (((c = fgetc(fp)) != EOF) && (c != '\n')) {
21 		if (first == 0 && !isblank(c)) {
22 			first = c|0x20;
23 		}
24 	}
25 
26 	return first == 'y';
27 }
28 
bb_ask_y_confirmation(void)29 int FAST_FUNC bb_ask_y_confirmation(void)
30 {
31 	return bb_ask_y_confirmation_FILE(stdin);
32 }
33