diff options
author | rsc <devnull@localhost> | 2003-11-23 18:04:47 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2003-11-23 18:04:47 +0000 |
commit | bc7cb1a15a67c859c8c71c4b52bb35fe9425a63d (patch) | |
tree | 8ca0fe4e2418e6aa18dc74a236c577a719f6c6ed /src/cmd/echo.c | |
parent | f08fdedcee12c06e3ce9ac9bec363915978e8289 (diff) | |
download | plan9port-bc7cb1a15a67c859c8c71c4b52bb35fe9425a63d.tar.gz plan9port-bc7cb1a15a67c859c8c71c4b52bb35fe9425a63d.tar.bz2 plan9port-bc7cb1a15a67c859c8c71c4b52bb35fe9425a63d.zip |
new utilities.
the .C files compile but are renamed to avoid building automatically.
Diffstat (limited to 'src/cmd/echo.c')
-rw-r--r-- | src/cmd/echo.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/cmd/echo.c b/src/cmd/echo.c new file mode 100644 index 00000000..25b69692 --- /dev/null +++ b/src/cmd/echo.c @@ -0,0 +1,38 @@ +#include <u.h> +#include <libc.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++){ + strcpy(p, argv[i]); + p += strlen(p); + if(i < argc-1) + *p++ = ' '; + } + + if(!nflag) + *p++ = '\n'; + + if(write(1, buf, p-buf) < 0) + fprint(2, "echo: write error: %r\n"); + + exits((char *)0); +} |