Re: [hackers] [sbase][PATCH] cp: add -i flag

From: Roberto E. Vargas Caballero <k0ga_AT_shike2.net>
Date: Fri, 18 Apr 2025 14:30:04 +0200

Hi,

On Thu, Apr 17, 2025 at 09:44:31PM +0000, NRK wrote:
> A couple facts:
>
> 1. POSIX requires a single whole line to be read (as Roberto pointed out
> already).
> 2. POSIX doesn't define what "affirmative" response is.
> GNU Coreutils reads the first char and discards the rest [0].
> Busybox skips blanks, then takes a char as answer and discards the rest [1].
> Both of these are "valid" according to POSIX.
>
> [0]: https://github.com/coreutils/gnulib/blob/71288b12a5eb299e173a17245f548d5e2adb85c0/lib/yesno.c#L54-L59
> [1]: https://github.com/mirror/busybox/blob/371fe9f71d445d18be28c82a2a6d82115c8af19d/libbb/ask_confirmation.c#L11-L27
>
> Now to Roberto's proposal:
>
> while (isspace(ch = getchar()))
> ;
>
> This is wrong because isspace() will return true on newlines, thus it'll
> end up reading *multiple* lines. We must read only one. You want
> isblank() instead.

Good catch! I just wrote without testing and that was an obvious bug ^^!

> Other than that:
>
> 1) Skipping leading blanks seems okay to me.
> 2) Rejecting any non-space trailing char is valid by POSIX but will also
> lead to some surprising results, such as "yes" being rejected.
> 3) IMO busybox's approach seems like a good behavior: skip leading
> blanks, ignore trailing chars.

Based in that I rewrote the patch following the busybox approach. Please,
THIBAUT AUBIN and NRK can you review it (specially THIBAUT because you are
the author of the patch and you will get credit for it):

---8<
Received on Fri Apr 18 2025 - 14:30:04 CEST

This archive was generated by hypermail 2.3.0 : Fri Apr 18 2025 - 14:36:38 CEST