Re: [hackers] [sbase][PATCH] cp: add -i flag
Hi,
On Wed, Apr 16, 2025 at 12:06:25PM +0000, NRK wrote:
> The whole line needs to be read, even when the first char is `y|Y`.
> Also, getchar may return EOF before newline leading to an infinite loop.
> Suggestion (untested):
>
> int ans = getchar();
> for (int c = ans; c != '\n' && c != EOF;)
> c = getchar();
> if (ans != 'Y' && ans != 'y')
> return 0;
I think this approach can still be a bit problematic, and we should skip
spaces at the beginning, and detect trailing characters (not tested):
while (isspace(ch = getchar()))
;
ans = ch;
while (isspace(ch = getchar()) && ch != '\n')
;
if (ch != '\n' && toupper(ans) != 'Y')
return 0;
Kind Regards,
Roberto Vargas
Received on Thu Apr 17 2025 - 00:40:14 CEST
This archive was generated by hypermail 2.3.0
: Thu Apr 17 2025 - 00:48:38 CEST