diff options
author | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
---|---|---|
committer | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
commit | e5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch) | |
tree | d8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/libventi/string.c |
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/libventi/string.c')
-rwxr-xr-x | sys/src/libventi/string.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/sys/src/libventi/string.c b/sys/src/libventi/string.c new file mode 100755 index 000000000..9763149a1 --- /dev/null +++ b/sys/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; +} + |