aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/venti/write.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2003-11-23 17:54:58 +0000
committerrsc <devnull@localhost>2003-11-23 17:54:58 +0000
commit7a4ee46d253e291044bba2d0c54b818b67ac013c (patch)
tree7bdcaf69a15ecd24c057a697936b67bbde93e00b /src/cmd/venti/write.c
parent4fbfdd7acd4bf4fc71b1329230e05fc761907566 (diff)
downloadplan9port-7a4ee46d253e291044bba2d0c54b818b67ac013c.tar.gz
plan9port-7a4ee46d253e291044bba2d0c54b818b67ac013c.tar.bz2
plan9port-7a4ee46d253e291044bba2d0c54b818b67ac013c.zip
Initial stab at Venti.
Diffstat (limited to 'src/cmd/venti/write.c')
-rw-r--r--src/cmd/venti/write.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/cmd/venti/write.c b/src/cmd/venti/write.c
new file mode 100644
index 00000000..94b61be4
--- /dev/null
+++ b/src/cmd/venti/write.c
@@ -0,0 +1,60 @@
+#include "stdinc.h"
+#include "dat.h"
+#include "fns.h"
+
+char *host;
+
+void
+usage(void)
+{
+ fprint(2, "usage: write [-z] [-h host] [-t type] <datablock\n");
+ threadexitsall("usage");
+}
+
+void
+threadmain(int argc, char *argv[])
+{
+ uchar *p, score[VtScoreSize];
+ int type, n, dotrunc;
+ VtConn *z;
+
+ dotrunc = 0;
+ type = VtDataType;
+ ARGBEGIN{
+ case 'z':
+ dotrunc = 1;
+ break;
+ case 'h':
+ host = EARGF(usage());
+ break;
+ case 't':
+ type = atoi(EARGF(usage()));
+ break;
+ default:
+ usage();
+ break;
+ }ARGEND
+
+ if(argc != 0)
+ usage();
+
+
+ fmtinstall('V', vtscorefmt);
+
+ p = ezmalloc(VtMaxLumpSize+1);
+ n = readn(0, p, VtMaxLumpSize+1);
+ if(n > VtMaxLumpSize)
+ sysfatal("data too big");
+ z = vtdial(host);
+ if(z == nil)
+ sysfatal("could not connect to server: %r");
+ if(vtconnect(z) < 0)
+ sysfatal("vtconnect: %r");
+ if(dotrunc)
+ n = vtzerotruncate(type, p, n);
+ if(vtwrite(z, score, type, p, n) < 0)
+ sysfatal("vtwrite: %r");
+ vthangup(z);
+ print("%V\n", score);
+ threadexitsall(0);
+}