[prev in list] [next in list] [prev in thread] [next in thread]
List: util-linux-ng
Subject: Re: [PATCH text-utils/line] trivial rewrite
From: Davidlohr Bueso <dave () gnu ! org>
Date: 2010-07-30 14:54:37
Message-ID: 1280501677.1929.3.camel () cowboy
[Download RAW message or body]
On Thu, 2010-07-29 at 17:19 +0200, Karel Zak wrote:
> 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?
Yeah, it's a pretty useless tool.
> > -#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
>
>
--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic