[hackers] [sbase][PATCH] Minor optimizations for 'yes'

From: AGitBoy <aidanwillie0317_AT_protonmail.com>
Date: Wed, 26 Jun 2019 06:52:34 +0000

---
 yes.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/yes.c b/yes.c
index dd97ea6..49f5ed6 100644
--- a/yes.c
+++ b/yes.c
_AT_@ -6,13 +6,20 @@
 int
 main(int argc, char *argv[])
 {
-	char **p;
+	if (argc > 1) {
+		char **p;
 
-	argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
+		argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
 
-	for (p = argv; ; p = (*p && *(p + 1)) ? p + 1 : argv) {
-		fputs(*p ? *p : "y", stdout);
-		putchar((!*p || !*(p + 1)) ? '\n' : ' ');
+		for (p = argv; ; p = (*p && *(p + 1)) ? p + 1 : argv) {
+			fputs(*p, stdout);
+			putchar((!*p || !*(p + 1)) ? '\n' : ' ');
+		}
+	} else {
+		while (1) {
+			fputc('y', stdout);
+			fputc('\n', stdout);
+		}
 	}
 
 	return 1; /* not reached */
-- 
2.21.0
Received on Wed Jun 26 2019 - 08:52:34 CEST

This archive was generated by hypermail 2.3.0 : Wed Jun 26 2019 - 09:00:25 CEST