Re: [PATCH 02/11] line: do not print new line if nothing else was printed

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thursday 08 June 2017, Sami Kerola wrote:
> Earlier the following printed stray new line.
>
> $ printf "" | ./line

This breaks test "misc/line", see commit caad4ded
and
https://github.com/karelzak/util-linux/issues/236

> Signed-off-by: Sami Kerola <kerolasa@xxxxxx>
> ---
>  text-utils/line.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/text-utils/line.c b/text-utils/line.c
> index 486e5dd31..ae10809c2 100644
> --- a/text-utils/line.c
> +++ b/text-utils/line.c
> @@ -42,7 +42,7 @@ static void __attribute__((__noreturn__))
> usage(FILE *out) int main(int argc, char **argv)
>  {
>  	wint_t c;
> -	int opt;
> +	int opt, print_nl = 0;
>  	int status = EXIT_SUCCESS;
>
>  	static const struct option longopts[] = {
> @@ -77,8 +77,10 @@ int main(int argc, char **argv)
>  		if (c == '\n')
>  			break;
>  		putwchar(c);
> +		print_nl = 1;
>  	}
> -	putwchar(L'\n');
> +	if (print_nl)
> +		putwchar(L'\n');
>
>  	return status;
>  }
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux