2007-12-26 16:50:38 +00:00
|
|
|
/*
|
2021-12-05 09:35:27 -06:00
|
|
|
* SPDX-FileCopyrightText: 1992 - 1994, Julianne Frances Haugh
|
|
|
|
* SPDX-FileCopyrightText: 2007 - 2008, Nicolas François
|
2007-12-26 16:50:38 +00:00
|
|
|
*
|
2021-12-05 09:35:27 -06:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2007-12-26 16:50:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Common code for yes/no prompting
|
|
|
|
*
|
|
|
|
* Used by pwck.c and grpck.c
|
|
|
|
*/
|
|
|
|
|
2008-01-05 13:32:32 +00:00
|
|
|
#include <config.h>
|
2007-12-26 16:50:38 +00:00
|
|
|
|
|
|
|
#ident "$Id$"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "prototypes.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* yes_or_no - get answer to question from the user
|
|
|
|
*
|
2008-05-25 23:01:14 +00:00
|
|
|
* It returns false if no.
|
2007-12-26 16:50:38 +00:00
|
|
|
*
|
2008-05-25 23:01:14 +00:00
|
|
|
* If the read_only flag is set, it will print No, and will return
|
|
|
|
* false.
|
2007-12-26 16:50:38 +00:00
|
|
|
*/
|
2008-05-25 23:01:14 +00:00
|
|
|
bool yes_or_no (bool read_only)
|
2007-12-26 16:50:38 +00:00
|
|
|
{
|
|
|
|
char buf[80];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In read-only mode all questions are answered "no".
|
|
|
|
*/
|
|
|
|
if (read_only) {
|
2009-04-23 11:14:56 +00:00
|
|
|
(void) puts (_("No"));
|
2008-05-25 23:01:14 +00:00
|
|
|
return false;
|
2007-12-26 16:50:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Typically, there's a prompt on stdout, sometimes unflushed.
|
|
|
|
*/
|
2008-05-25 23:01:14 +00:00
|
|
|
(void) fflush (stdout);
|
2007-12-26 16:50:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 18:11:09 +00:00
|
|
|
if (fgets (buf, (int) sizeof buf, stdin) == buf) {
|
2007-12-26 16:50:38 +00:00
|
|
|
return buf[0] == 'y' || buf[0] == 'Y';
|
2008-05-25 23:01:14 +00:00
|
|
|
}
|
2007-12-26 16:50:38 +00:00
|
|
|
|
2008-05-25 23:01:14 +00:00
|
|
|
return false;
|
2007-12-26 16:50:38 +00:00
|
|
|
}
|
2008-05-25 23:01:14 +00:00
|
|
|
|