diff options
author | Russ Cox <rsc@swtch.com> | 2008-06-19 18:52:22 -0400 |
---|---|---|
committer | Russ Cox <rsc@swtch.com> | 2008-06-19 18:52:22 -0400 |
commit | 55d98d64b8352383ba4653f4baf5dc109e434ca2 (patch) | |
tree | d8fba6b4b20da549eb85ed8e3bea30d1dd4e24a0 /src/cmd/9p.c | |
parent | ad95037a488aee537c4e1f6fb5aaedfddc0e0d6e (diff) | |
download | plan9port-55d98d64b8352383ba4653f4baf5dc109e434ca2.tar.gz plan9port-55d98d64b8352383ba4653f4baf5dc109e434ca2.tar.bz2 plan9port-55d98d64b8352383ba4653f4baf5dc109e434ca2.zip |
9p: exit on write error (sqweek)
Diffstat (limited to 'src/cmd/9p.c')
-rw-r--r-- | src/cmd/9p.c | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/cmd/9p.c b/src/cmd/9p.c index 2e70399e..689e00ee 100644 --- a/src/cmd/9p.c +++ b/src/cmd/9p.c @@ -25,6 +25,21 @@ usage(void) threadexitsall("usage"); } +int +writen(int fd, void *buf, int n) +{ + long m, tot; + + for(tot=0; tot<n; tot+=m){ + m = n - tot; + if(m > 8192) + m = 8192; + if(write(fd, (uchar*)buf+tot, m) != m) + break; + } + return tot; +} + CFsys *(*nsmnt)(char*, char*) = nsamount; CFsys *(*fsmnt)(int, char*) = fsamount; @@ -163,7 +178,8 @@ xread(int argc, char **argv) fid = xopen(argv[0], OREAD); while((n = fsread(fid, buf, sizeof buf)) > 0) - write(1, buf, n); + if(writen(1, buf, n) < 0) + sysfatal("write error: %r"); fsclose(fid); if(n < 0) sysfatal("read error: %r"); @@ -187,7 +203,8 @@ xreadfd(int argc, char **argv) fd = xopenfd(argv[0], OREAD); while((n = read(fd, buf, sizeof buf)) > 0) - write(1, buf, n); + if(writen(1, buf, n) < 0) + sysfatal("write error: %r"); if(n < 0) sysfatal("read error: %r"); threadexitsall(0); @@ -264,7 +281,7 @@ xwritefd(int argc, char **argv) fd = xopenfd(argv[0], OWRITE|OTRUNC); while((n = read(0, buf, sizeof buf)) > 0) - if(write(fd, buf, n) != n) + if(writen(fd, buf, n) != n) sysfatal("write error: %r"); if(n < 0) sysfatal("read error: %r"); @@ -317,8 +334,8 @@ xrdwr(int argc, char **argv) if((n = fsread(fid, buf, sizeof buf)) < 0) fprint(2, "read: %r\n"); else{ - write(1, buf, n); - write(1, "\n", 1); + if(writen(1, buf, n) < 0 || writen(1, "\n", 1) < 0) + sysfatal("write error: %r"); } n = read(0, buf, sizeof buf); if(n <= 0) |