diff options
author | rsc <devnull@localhost> | 2003-11-23 18:19:58 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2003-11-23 18:19:58 +0000 |
commit | 056fe1ba7fa0b70f871dfb9005b24eb8e4cc230b (patch) | |
tree | 9ad42f31c3bc124cf6617cf9eb41dd525eccce83 /src/libventi/string.c | |
parent | 9df487d720a59bf8cb0dc4ccffc30ad8eb48256a (diff) | |
download | plan9port-056fe1ba7fa0b70f871dfb9005b24eb8e4cc230b.tar.gz plan9port-056fe1ba7fa0b70f871dfb9005b24eb8e4cc230b.tar.bz2 plan9port-056fe1ba7fa0b70f871dfb9005b24eb8e4cc230b.zip |
new venti library.
Diffstat (limited to 'src/libventi/string.c')
-rw-r--r-- | src/libventi/string.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/libventi/string.c b/src/libventi/string.c new file mode 100644 index 00000000..9763149a --- /dev/null +++ b/src/libventi/string.c @@ -0,0 +1,50 @@ +#include <u.h> +#include <libc.h> +#include <venti.h> + +int +vtputstring(Packet *p, char *s) +{ + uchar buf[2]; + int n; + + if(s == nil){ + werrstr("null string in packet"); + return -1; + } + n = strlen(s); + if(n > VtMaxStringSize){ + werrstr("string too long in packet"); + return -1; + } + buf[0] = n>>8; + buf[1] = n; + packetappend(p, buf, 2); + packetappend(p, (uchar*)s, n); + return 0; +} + +int +vtgetstring(Packet *p, char **ps) +{ + uchar buf[2]; + int n; + char *s; + + if(packetconsume(p, buf, 2) < 0) + return -1; + n = (buf[0]<<8) + buf[1]; + if(n > VtMaxStringSize) { + werrstr("string too long in packet"); + return -1; + } + s = vtmalloc(n+1); + if(packetconsume(p, (uchar*)s, n) < 0){ + vtfree(s); + return -1; + } + s[n] = 0; + *ps = s; + return 0; +} + |