diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 20:46:53 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 20:46:53 +0000 |
commit | 19da58be2d9359a9641381feb559be0b918ef710 (patch) | |
tree | 109724175f07436696f51b14b5abbd3f4d704d6d /libmisc/yesno.c | |
parent | Initial commit. (diff) | |
download | shadow-19da58be2d9359a9641381feb559be0b918ef710.tar.xz shadow-19da58be2d9359a9641381feb559be0b918ef710.zip |
Adding upstream version 1:4.13+dfsg1.upstream/1%4.13+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libmisc/yesno.c')
-rw-r--r-- | libmisc/yesno.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/libmisc/yesno.c b/libmisc/yesno.c new file mode 100644 index 0000000..cfbe6ec --- /dev/null +++ b/libmisc/yesno.c @@ -0,0 +1,56 @@ +/* + * SPDX-FileCopyrightText: 1992 - 1994, Julianne Frances Haugh + * SPDX-FileCopyrightText: 2007 - 2008, Nicolas François + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/* + * Common code for yes/no prompting + * + * Used by pwck.c and grpck.c + */ + +#include <config.h> + +#ident "$Id$" + +#include <stdio.h> +#include "prototypes.h" + +/* + * yes_or_no - get answer to question from the user + * + * It returns false if no. + * + * If the read_only flag is set, it will print No, and will return + * false. + */ +bool yes_or_no (bool read_only) +{ + char buf[80]; + + /* + * In read-only mode all questions are answered "no". + */ + if (read_only) { + (void) puts (_("No")); + return false; + } + + /* + * Typically, there's a prompt on stdout, sometimes unflushed. + */ + (void) fflush (stdout); + + /* + * Get a line and see what the first character is. + */ + /* TODO: use gettext */ + if (fgets (buf, (int) sizeof buf, stdin) == buf) { + return buf[0] == 'y' || buf[0] == 'Y'; + } + + return false; +} + |