utils: Import yes from ELKS sh-utils and ANSIfy
authorAlan Cox <alan@linux.intel.com>
Tue, 30 Dec 2014 11:37:22 +0000 (11:37 +0000)
committerAlan Cox <alan@linux.intel.com>
Tue, 30 Dec 2014 11:37:22 +0000 (11:37 +0000)
Applications/util/Makefile
Applications/util/yes.c [new file with mode: 0644]

index 8308a8b..5cebaba 100644 (file)
@@ -82,12 +82,14 @@ SRCS  = banner.c \
        tr.c \
        true.c \
        umount.c \
+       uname.c \
        uniq.c \
        uud.c \
        uue.c \
        wc.c \
        which.c \
-       whoami.c
+       whoami.c \
+       yes.c
 
 OBJS = $(SRCS:.c=.rel)
 
diff --git a/Applications/util/yes.c b/Applications/util/yes.c
new file mode 100644 (file)
index 0000000..f3cea7b
--- /dev/null
@@ -0,0 +1,25 @@
+/*     yes 1.4 - print 'y' or argv[1] continuously.    Author: Kees J. Bot
+ *                                                             15 Apr 1989
+ */
+#include <sys/types.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+int main(int argc, char *argv[])
+{
+    char *yes;
+    int n;
+    static char y[] = "y";
+
+    yes = argc == 1 ? y : argv[1];
+
+    n = strlen(yes);
+               
+    yes[n++] = '\n';
+
+    while (write(1, yes, n) != -1)
+       /* Do nothing */;
+
+    exit(1);
+}