Re: [hackers] [PATCH][sbase] cmp: Make output POSIX compliant

From: Michael Forney <mforney_AT_mforney.org>
Date: Sun, 19 May 2019 11:25:05 -0700

On 2019-05-19, Richard Ipsum <richardipsum_AT_fastmail.co.uk> wrote:
> From POSIX:
>
> In the POSIX locale, results of the comparison shall be written to
> standard output. When no options are used, the format shall be:
>
> "%s %s differ: char %d, line %d\n", file1, file2,
> <byte number>, <line number>
>
> ....
> in the POSIX locale the following
> diagnostic message shall be written:
>
> "cmp: EOF on %s%s\n", <name of shorter file>, <additional info>
> ---
> cmp.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/cmp.c b/cmp.c
> index ea8902f..6949191 100644
> --- a/cmp.c
> +++ b/cmp.c
> _AT_@ -57,12 +57,12 @@ main(int argc, char *argv[])
> continue;
> } else if (b[0] == EOF || b[1] == EOF) {
> if (!sflag)
> - weprintf("cmp: EOF on %s\n", argv[(b[0] != EOF)]);
> + printf("cmp: EOF on %s\n", argv[(b[0] != EOF)]);

I think stderr is correct for this message:

        The standard error shall be used only for diagnostic messages. ... in
the POSIX locale the following diagnostic message shall be written

However, we probably want to avoid the double-prefix on the message with just

        weprintf("EOF on %s\n", argv[(b[0] != EOF)]);

> same = 0;
> break;
> } else if (!lflag) {
> if (!sflag)
> - printf("%s %s differ: byte %zu, line %zu\n",
> + printf("%s %s differ: char %zu, line %zu\n",
> argv[0], argv[1], n, line);
> same = 0;
> break;
> --
> 2.21.0
Received on Sun May 19 2019 - 20:25:05 CEST

This archive was generated by hypermail 2.3.0 : Sun May 19 2019 - 20:36:23 CEST