Mercurial > illumos > illumos-gate
diff usr/src/cmd/yes/yes.c @ 14126:62364715172d
3927 yes(1) needs error handling to avoid spinning
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Marcel Telka <Marcel.Telka@nexenta.com>
Reviewed by: Garrett D'Amore <garrett@damore.org>
Reviewed by: Irek Szczesniak <iszczesniak@gmail.com>
Approved by: Richard Lowe <richlowe@richlowe.net>
author | Jonathan Perkin <jperkin@joyent.com> |
---|---|
date | Thu, 17 Jan 2013 00:48:10 +0000 |
parents | 68f95e015346 |
children |
line wrap: on
line diff
--- a/usr/src/cmd/yes/yes.c Tue Aug 21 22:07:55 2012 +0000 +++ b/usr/src/cmd/yes/yes.c Thu Jan 17 00:48:10 2013 +0000 @@ -23,8 +23,9 @@ * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ - -#pragma ident "%Z%%M% %I% %E% SMI" +/* + * Copyright (c) 2013, Joyent, Inc. All rights reserved. + */ #include <stdio.h> @@ -32,24 +33,24 @@ main(int argc, char **argv) { if (argc <= 1) { - for (;;) { - (void) putchar('y'); - (void) putchar('\n'); - } + while (puts("y") != EOF) + continue; } else { for (;;) { int i; for (i = 1; i < argc; i++) { if (i > 1) - (void) putchar(' '); - (void) fputs(argv[i], stdout); + if (putchar(' ') == EOF) + goto err; + if (fputs(argv[i], stdout) == EOF) + goto err; } - (void) putchar('\n'); + if (putchar('\n') == EOF) + goto err; } } -#if defined(lint) - /*NOTREACHED*/ - return (0); -#endif + +err: + return (1); }