Blob
1 #include "stdinc.h"2 #include "dat.h"3 #include "fns.h"5 char *host;7 void8 usage(void)9 {10 fprint(2, "usage: write [-z] [-h host] [-t type] <datablock\n");11 threadexitsall("usage");12 }14 void15 threadmain(int argc, char *argv[])16 {17 uchar *p, score[VtScoreSize];18 int type, n, dotrunc;19 VtConn *z;21 dotrunc = 0;22 type = VtDataType;23 ARGBEGIN{24 case 'z':25 dotrunc = 1;26 break;27 case 'h':28 host = EARGF(usage());29 break;30 case 't':31 type = atoi(EARGF(usage()));32 break;33 default:34 usage();35 break;36 }ARGEND38 if(argc != 0)39 usage();42 fmtinstall('V', vtscorefmt);44 p = ezmalloc(VtMaxLumpSize+1);45 n = readn(0, p, VtMaxLumpSize+1);46 if(n > VtMaxLumpSize)47 sysfatal("data too big");48 z = vtdial(host);49 if(z == nil)50 sysfatal("could not connect to server: %r");51 if(vtconnect(z) < 0)52 sysfatal("vtconnect: %r");53 if(dotrunc)54 n = vtzerotruncate(type, p, n);55 if(vtwrite(z, score, type, p, n) < 0)56 sysfatal("vtwrite: %r");57 vthangup(z);58 print("%V\n", score);59 threadexitsall(0);60 }