add write -l
This commit is contained in:
parent
83c4506aa5
commit
276bf4edf1
1 changed files with 27 additions and 5 deletions
24
src/cmd/9p.c
24
src/cmd/9p.c
|
|
@ -1,6 +1,7 @@
|
||||||
#include <u.h>
|
#include <u.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
|
#include <bio.h>
|
||||||
#include <fcall.h>
|
#include <fcall.h>
|
||||||
#include <9pclient.h>
|
#include <9pclient.h>
|
||||||
#include <auth.h>
|
#include <auth.h>
|
||||||
|
|
@ -15,7 +16,7 @@ usage(void)
|
||||||
fprint(2, "possible cmds:\n");
|
fprint(2, "possible cmds:\n");
|
||||||
fprint(2, " read name\n");
|
fprint(2, " read name\n");
|
||||||
fprint(2, " readfd name\n");
|
fprint(2, " readfd name\n");
|
||||||
fprint(2, " write name\n");
|
fprint(2, " write [-l] name\n");
|
||||||
fprint(2, " writefd name\n");
|
fprint(2, " writefd name\n");
|
||||||
fprint(2, " stat name\n");
|
fprint(2, " stat name\n");
|
||||||
// fprint(2, " ls name\n");
|
// fprint(2, " ls name\n");
|
||||||
|
|
@ -176,8 +177,14 @@ xwrite(int argc, char **argv)
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
int n, did;
|
int n, did;
|
||||||
CFid *fid;
|
CFid *fid;
|
||||||
|
Biobuf *b;
|
||||||
|
char *p;
|
||||||
|
int byline;
|
||||||
|
|
||||||
|
byline = 0;
|
||||||
ARGBEGIN{
|
ARGBEGIN{
|
||||||
|
case 'l':
|
||||||
|
byline = 1;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
}ARGEND
|
}ARGEND
|
||||||
|
|
@ -187,11 +194,26 @@ xwrite(int argc, char **argv)
|
||||||
|
|
||||||
did = 0;
|
did = 0;
|
||||||
fid = xopen(argv[0], OWRITE|OTRUNC);
|
fid = xopen(argv[0], OWRITE|OTRUNC);
|
||||||
|
if(byline){
|
||||||
|
n = 0;
|
||||||
|
b = malloc(sizeof *b);
|
||||||
|
if(b == nil)
|
||||||
|
sysfatal("out of memory");
|
||||||
|
Binit(b, 0, OREAD);
|
||||||
|
while((p = Brdstr(b, '\n', 0)) != nil){
|
||||||
|
n = strlen(p);
|
||||||
|
did = 1;
|
||||||
|
if(fswrite(fid, p, n) != n)
|
||||||
|
sysfatal("write error: %r");
|
||||||
|
}
|
||||||
|
free(b);
|
||||||
|
}else{
|
||||||
while((n = read(0, buf, sizeof buf)) > 0){
|
while((n = read(0, buf, sizeof buf)) > 0){
|
||||||
did = 1;
|
did = 1;
|
||||||
if(fswrite(fid, buf, n) != n)
|
if(fswrite(fid, buf, n) != n)
|
||||||
sysfatal("write error: %r");
|
sysfatal("write error: %r");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(n == 0 && !did){
|
if(n == 0 && !did){
|
||||||
if(fswrite(fid, buf, 0) != 0)
|
if(fswrite(fid, buf, 0) != 0)
|
||||||
sysfatal("write error: %r");
|
sysfatal("write error: %r");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue