diff options
author | rsc <devnull@localhost> | 2006-01-06 18:00:42 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2006-01-06 18:00:42 +0000 |
commit | e29d0c84fea05f317385ab1a8f3abceb7726b1bb (patch) | |
tree | c68c3567f0adc7ed79ec6f4281468e2ae25bc324 /src/cmd/9p.c | |
parent | d9742d7e94acc0279f687d3fd0c6360d36480f8b (diff) | |
download | plan9port-e29d0c84fea05f317385ab1a8f3abceb7726b1bb.tar.gz plan9port-e29d0c84fea05f317385ab1a8f3abceb7726b1bb.tar.bz2 plan9port-e29d0c84fea05f317385ab1a8f3abceb7726b1bb.zip |
add con
Diffstat (limited to 'src/cmd/9p.c')
-rw-r--r-- | src/cmd/9p.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/cmd/9p.c b/src/cmd/9p.c index 2570aa3e..7d218e67 100644 --- a/src/cmd/9p.c +++ b/src/cmd/9p.c @@ -33,11 +33,13 @@ void xwritefd(int, char**); void xstat(int, char**); void xls(int, char**); void xrdwr(int, char**); +void xcon(int, char**); struct { char *s; void (*f)(int, char**); } cmds[] = { + "con", xcon, "read", xread, "write", xwrite, "readfd", xreadfd, @@ -318,6 +320,61 @@ xrdwr(int argc, char **argv) threadexitsall(0); } +void +rdcon(void *v) +{ + char buf[4096]; + CFid *fid; + + fid = v; + for(;;){ + n = read(0, buf, sizeof buf); + if(n <= 0) + threadexitsall(0); + if(fswrite(fid, buf, n) != n) + fprint(2, "write: %r\n"); + } +} + +void +xcon(int argc, char **argv) +{ + char buf[4096], *r, *w, *e; + int n, nocr; + CFid *fid; + + nocr = 1; + + ARGBEGIN{ + case 'r': + nocr = 0; + break; + default: + usage(); + }ARGEND + + if(argc != 1) + usage(); + + fid = xopen(argv[0], ORDWR); + proccreate(rdcon, fid, STACK); + for(;;){ + n = fsread(fid, buf, n); + if(n <= 0) + threadexitsall(0); + if(nocr){ + for(r=w=buf, e=buf+n; r<e; r++) + if(*r != '\r') + *w++ = *r; + n = w-buf; + } + if(write(1, buf, n) != n) + threadexitsall(0); + } + fsclose(fid); + threadexitsall(0); +} + static char *mon[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", |