shadow/libmisc/yesno.c
Alejandro Colomar bddcd9b095 Remove superfluous casts
-  Every non-const pointer converts automatically to void *.
-  Every pointer converts automatically to void *.
-  void * converts to any other pointer.
-  const void * converts to any other const pointer.
-  Integer variables convert to each other.

I changed the declaration of a few variables in order to allow removing
a cast.

However, I didn't attempt to edit casts inside comparisons, since they
are very delicate.  I also kept casts in variadic functions, since they
are necessary, and in allocation functions, because I have other plans
for them.

I also changed a few casts to int that are better as ptrdiff_t.

This change has triggered some warnings about const correctness issues,
which have also been fixed in this patch (see for example src/login.c).

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-02-09 10:03:03 -06:00

57 lines
970 B
C

/*
* 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, sizeof buf, stdin) == buf) {
return buf[0] == 'y' || buf[0] == 'Y';
}
return false;
}