On Sun, Jul 10, 2022 at 1:08 PM Scott Cheloha <[email protected]>
wrote:
> ok?
>
> Index: echo.c
> ===================================================================
> RCS file: /cvs/src/bin/echo/echo.c,v
> retrieving revision 1.10
> diff -u -p -r1.10 echo.c
> --- echo.c 9 Oct 2015 01:37:06 -0000 1.10
> +++ echo.c 10 Jul 2022 22:00:18 -0000
> @@ -53,12 +53,15 @@ main(int argc, char *argv[])
> nflag = 0;
>
> while (*argv) {
> - (void)fputs(*argv, stdout);
> - if (*++argv)
> - putchar(' ');
> + if (fputs(*argv, stdout) == EOF)
> + err(1, "stdout");
> + if (*++argv && putchar(' ') == EOF)
> + err(1, "stdout");
> }
> if (!nflag)
> putchar('\n');
> + if (fclose(stdout) == EOF)
> + err(1, "stdout");
>
> return 0;
> }
>
>
Three thoughts:
1) Since stdio errors are sticky, is there any real advantage to checking
each call instead of just checking the final fclose()?
2) It is claimed that POSIX requires *all* standard utilities to return
failure if any writes to stdout failed. If it's important to fix this in
'echo', can we sketch out how we might fix make fixing this in the other
utilities easier? I believe at least some chunk of the GNU utilities now
use an atexit() handler to do that; is that a reasonable idea and if not
can we come up with something better?
3) It would be no end of surprise and frustration for the external echo
utility to behave differently than the sh builtin.
Philip