1 056fe1ba 2003-11-23 devnull #include <u.h>
2 056fe1ba 2003-11-23 devnull #include <libc.h>
3 056fe1ba 2003-11-23 devnull #include <venti.h>
6 056fe1ba 2003-11-23 devnull vtputstring(Packet *p, char *s)
8 056fe1ba 2003-11-23 devnull uchar buf[2];
11 056fe1ba 2003-11-23 devnull if(s == nil){
12 056fe1ba 2003-11-23 devnull werrstr("null string in packet");
13 056fe1ba 2003-11-23 devnull return -1;
15 056fe1ba 2003-11-23 devnull n = strlen(s);
16 056fe1ba 2003-11-23 devnull if(n > VtMaxStringSize){
17 056fe1ba 2003-11-23 devnull werrstr("string too long in packet");
18 056fe1ba 2003-11-23 devnull return -1;
20 056fe1ba 2003-11-23 devnull buf[0] = n>>8;
21 056fe1ba 2003-11-23 devnull buf[1] = n;
22 056fe1ba 2003-11-23 devnull packetappend(p, buf, 2);
23 056fe1ba 2003-11-23 devnull packetappend(p, (uchar*)s, n);
24 056fe1ba 2003-11-23 devnull return 0;
28 056fe1ba 2003-11-23 devnull vtgetstring(Packet *p, char **ps)
30 056fe1ba 2003-11-23 devnull uchar buf[2];
34 056fe1ba 2003-11-23 devnull if(packetconsume(p, buf, 2) < 0)
35 056fe1ba 2003-11-23 devnull return -1;
36 056fe1ba 2003-11-23 devnull n = (buf[0]<<8) + buf[1];
37 056fe1ba 2003-11-23 devnull if(n > VtMaxStringSize) {
38 056fe1ba 2003-11-23 devnull werrstr("string too long in packet");
39 056fe1ba 2003-11-23 devnull return -1;
41 056fe1ba 2003-11-23 devnull s = vtmalloc(n+1);
42 056fe1ba 2003-11-23 devnull if(packetconsume(p, (uchar*)s, n) < 0){
43 056fe1ba 2003-11-23 devnull vtfree(s);
44 056fe1ba 2003-11-23 devnull return -1;
46 056fe1ba 2003-11-23 devnull s[n] = 0;
48 056fe1ba 2003-11-23 devnull return 0;