diff options
author | rsc <devnull@localhost> | 2004-02-29 22:54:49 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2004-02-29 22:54:49 +0000 |
commit | b4705757e57c6f5e21715e8a1e9513af09c37775 (patch) | |
tree | 70ba8a852a440f187f6d0e4a6085d63001f7b8f3 | |
parent | 2517c38a8c265bf80a3befbb9bb18863ba453504 (diff) | |
download | plan9port-b4705757e57c6f5e21715e8a1e9513af09c37775.tar.gz plan9port-b4705757e57c6f5e21715e8a1e9513af09c37775.tar.bz2 plan9port-b4705757e57c6f5e21715e8a1e9513af09c37775.zip |
Threaded read9pmsg.
-rw-r--r-- | src/libthread/read9pmsg.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/libthread/read9pmsg.c b/src/libthread/read9pmsg.c new file mode 100644 index 00000000..652fc82f --- /dev/null +++ b/src/libthread/read9pmsg.c @@ -0,0 +1,32 @@ +#include <u.h> +#include <libc.h> +#include <fcall.h> +#include <thread.h> + +int +threadread9pmsg(int fd, void *abuf, uint n) +{ + int m, len; + uchar *buf; + + buf = abuf; + + /* read count */ + m = threadreadn(fd, buf, BIT32SZ); + if(m != BIT32SZ){ + if(m < 0) + return -1; + return 0; + } + + len = GBIT32(buf); + if(len <= BIT32SZ || len > n){ + werrstr("bad length in 9P2000 message header"); + return -1; + } + len -= BIT32SZ; + m = threadreadn(fd, buf+BIT32SZ, len); + if(m < len) + return 0; + return BIT32SZ+m; +} |