commit b4705757e57c6f5e21715e8a1e9513af09c37775 from: rsc date: Sun Feb 29 22:54:49 2004 UTC Threaded read9pmsg. commit - 2517c38a8c265bf80a3befbb9bb18863ba453504 commit + b4705757e57c6f5e21715e8a1e9513af09c37775 blob - /dev/null blob + 652fc82fad698958b43ab9d3373e9f49f5ae3ad1 (mode 644) --- /dev/null +++ src/libthread/read9pmsg.c @@ -0,0 +1,32 @@ +#include +#include +#include +#include + +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; +}