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 */
|
2023-02-01 13:50:48 +01:00
|
|
|
if (fgets (buf, 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
|
|
|
|