utils: add "line"
authorAlan Cox <alan@linux.intel.com>
Mon, 13 Nov 2017 11:46:51 +0000 (11:46 +0000)
committerAlan Cox <alan@linux.intel.com>
Mon, 13 Nov 2017 11:46:51 +0000 (11:46 +0000)
Not a very useful command in the normal run of the mill but it's part of the
base command list expected so provide it anyway.

Applications/util/Makefile.z80
Applications/util/line.c [new file with mode: 0644]

index bb2c551..2aa264f 100644 (file)
@@ -26,6 +26,7 @@ SRCSNS = \
        head.c \
        init.c \
        kill.c \
+       line.c \
        ln.c \
        logname.c \
        mkdir.c \
diff --git a/Applications/util/line.c b/Applications/util/line.c
new file mode 100644 (file)
index 0000000..7d3f3de
--- /dev/null
@@ -0,0 +1,25 @@
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+
+int main(int argc, char *argv[])
+{
+    char buf[512];
+    char *e;
+    int l;
+    while((l = read(0, buf, 512)) > 0) {
+        e = memchr(buf, '\n', l);
+        if (e) {
+            l = e + 1 - buf;
+            write(1, buf, l);
+            return 0;
+        }
+        write(1, buf, l);
+    }
+    /* No newline was found */
+    write(1, "\n", l);
+    return 1;
+}
+
+            
\ No newline at end of file