]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/venti/write.c
cc: use 7 octal digits for 21 bit runes
[plan9front.git] / sys / src / cmd / venti / write.c
1 #include <u.h>
2 #include <libc.h>
3 #include <venti.h>
4 #include <libsec.h>
5 #include <thread.h>
6
7 void
8 usage(void)
9 {
10         fprint(2, "usage: write [-z] [-h host] [-t type] <datablock\n");
11         threadexitsall("usage");
12 }
13
14 void
15 threadmain(int argc, char *argv[])
16 {
17         char *host;
18         int dotrunc, n, type;
19         uchar *p, score[VtScoreSize];
20         VtConn *z;
21
22         fmtinstall('F', vtfcallfmt);
23         fmtinstall('V', vtscorefmt);
24
25         host = nil;
26         dotrunc = 0;
27         type = VtDataType;
28         ARGBEGIN{
29         case 'z':
30                 dotrunc = 1;
31                 break;
32         case 'h':
33                 host = EARGF(usage());
34                 break;
35         case 't':
36                 type = atoi(EARGF(usage()));
37                 break;
38         default:
39                 usage();
40                 break;
41         }ARGEND
42
43         if(argc != 0)
44                 usage();
45
46         p = vtmallocz(VtMaxLumpSize+1);
47         n = readn(0, p, VtMaxLumpSize+1);
48         if(n > VtMaxLumpSize)
49                 sysfatal("input too big: max block size is %d", VtMaxLumpSize);
50         z = vtdial(host);
51         if(z == nil)
52                 sysfatal("could not connect to server: %r");
53         if(vtconnect(z) < 0)
54                 sysfatal("vtconnect: %r");
55         if(dotrunc)
56                 n = vtzerotruncate(type, p, n);
57         if(vtwrite(z, score, type, p, n) < 0)
58                 sysfatal("vtwrite: %r");
59         vthangup(z);
60         print("%V\n", score);
61         threadexitsall(0);
62 }