Re: [PATCH text-utils/line] trivial rewrite

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

 



On Wed, Jul 28, 2010 at 05:25:31PM -0400, Davidlohr Bueso wrote:
> line: Rewrite of line(1), making the already simple program a bit more readable. It does not need
>  a global variable and a function other than main() to do the work.

OK. BTW, I have doubts that someone uses this tool. Maybe we can add
line(1) to the DEPRECATED file. Comments?

> -#include	<unistd.h>
> +#include <stdio.h>
> +#include <unistd.h>
>  
> -static int	status;		/* exit status */
> -
> -static void
> -doline(int fd)
> +int main(void)
>  {
>  	char c;
>  
> -	for (;;) {
> -		if (read(fd, &c, 1) <= 0) {
> -			status = 1;
> -			break;
> +	while(1) {
> +		if(read(0, &c, 1) <= 0) {
> +			perror("read");
> +			return 1;

 Please, use   err(EXIT_FAILURE, "read faild");

>  		}
> -		if (c == '\n')
> +		
> +		else if(c == '\n')
>  			break;
> -		putchar(c);
> +
> +		else
> +			printf("%c", c);
>  	}
> -	putchar('\n');
> -}
>  
> -int
> -main(int argc, char **argv)
> -{
> -	doline(0);
> -	return status;
> +	printf("\n");
> +
> +	return 0;

  return EXIT_SUCCES

    Karel


-- 
 Karel Zak  <kzak@xxxxxxxxxx>
 http://karelzak.blogspot.com
--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" 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