summaryrefslogtreecommitdiff
path: root/utils/echo/echo.c
diff options
context:
space:
mode:
authorCharles.Forsyth <devnull@localhost>2006-12-22 21:39:35 +0000
committerCharles.Forsyth <devnull@localhost>2006-12-22 21:39:35 +0000
commit74a4d8c26dd3c1e9febcb717cfd6cb6512991a7a (patch)
treec6e220ba61db3a6ea4052e6841296d829654e664 /utils/echo/echo.c
parent46439007cf417cbd9ac8049bb4122c890097a0fa (diff)
20060303
Diffstat (limited to 'utils/echo/echo.c')
-rw-r--r--utils/echo/echo.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/utils/echo/echo.c b/utils/echo/echo.c
new file mode 100644
index 00000000..9574e129
--- /dev/null
+++ b/utils/echo/echo.c
@@ -0,0 +1,33 @@
+#include <lib9.h>
+
+void
+main(int argc, char *argv[])
+{
+ int nflag;
+ int i, len;
+ char *buf, *p;
+
+ nflag = 0;
+ if(argc > 1 && strcmp(argv[1], "-n") == 0)
+ nflag = 1;
+
+ len = 1;
+ for(i = 1+nflag; i < argc; i++)
+ len += strlen(argv[i])+1;
+
+ buf = malloc(len);
+ if(buf == 0)
+ exits("no memory");
+
+ p = buf;
+ for(i = 1+nflag; i < argc; i++)
+ p += sprint(p, i == argc-1 ? "%s":"%s ", argv[i]);
+
+ if(!nflag)
+ sprint(p, "\n");
+
+ if(write(1, buf, strlen(buf)) < 0)
+ fprint(2, "echo: write error: %r\n");
+
+ exits((char *)0);
+}