2007-12-26 22:20:38 +05:30
|
|
|
/*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-FileCopyrightText: 1992 - 1994, Julianne Frances Haugh
|
|
|
|
* SPDX-FileCopyrightText: 2007 - 2008, Nicolas François
|
2007-12-26 22:20:38 +05:30
|
|
|
*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2007-12-26 22:20:38 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Common code for yes/no prompting
|
|
|
|
*
|
|
|
|
* Used by pwck.c and grpck.c
|
|
|
|
*/
|
|
|
|
|
2008-01-05 19:02:32 +05:30
|
|
|
#include <config.h>
|
2007-12-26 22:20:38 +05:30
|
|
|
|
|
|
|
#ident "$Id$"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "prototypes.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* yes_or_no - get answer to question from the user
|
|
|
|
*
|
2008-05-26 04:31:14 +05:30
|
|
|
* It returns false if no.
|
2007-12-26 22:20:38 +05:30
|
|
|
*
|
2008-05-26 04:31:14 +05:30
|
|
|
* If the read_only flag is set, it will print No, and will return
|
|
|
|
* false.
|
2007-12-26 22:20:38 +05:30
|
|
|
*/
|
2008-05-26 04:31:14 +05:30
|
|
|
bool yes_or_no (bool read_only)
|
2007-12-26 22:20:38 +05:30
|
|
|
{
|
|
|
|
char buf[80];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In read-only mode all questions are answered "no".
|
|
|
|
*/
|
|
|
|
if (read_only) {
|
2009-04-23 16:44:56 +05:30
|
|
|
(void) puts (_("No"));
|
2008-05-26 04:31:14 +05:30
|
|
|
return false;
|
2007-12-26 22:20:38 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Typically, there's a prompt on stdout, sometimes unflushed.
|
|
|
|
*/
|
2008-05-26 04:31:14 +05:30
|
|
|
(void) fflush (stdout);
|
2007-12-26 22:20:38 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a line and see what the first character is.
|
|
|
|
*/
|
|
|
|
/* TODO: use gettext */
|
* libmisc/console.c, libmisc/hushed.c, libmisc/yesno.c,
libmisc/loginprompt.c, libmisc/ttytype.c, libmisc/tz.c,
src/login_nopam.c, src/chpasswd.c, src/chgpasswd.c, lib/port.c:
The size argument of fgets is an int, not a size_t.
* libmisc/loginprompt.c: Ignore the return value from signal()
when the signal handlers are restored.
* src/chpasswd.c: Cast the return value of time() to a long
integer.
* src/chpasswd.c: Use the SCALE macro instead of (24L * 3600L)
for the values to be set in /etc/shadow.
2008-06-13 23:41:09 +05:30
|
|
|
if (fgets (buf, (int) sizeof buf, stdin) == buf) {
|
2007-12-26 22:20:38 +05:30
|
|
|
return buf[0] == 'y' || buf[0] == 'Y';
|
2008-05-26 04:31:14 +05:30
|
|
|
}
|
2007-12-26 22:20:38 +05:30
|
|
|
|
2008-05-26 04:31:14 +05:30
|
|
|
return false;
|
2007-12-26 22:20:38 +05:30
|
|
|
}
|
2008-05-26 04:31:14 +05:30
|
|
|
|