Blob


1 #include <u.h>
2 #include <libc.h>
3 #include <fcall.h>
4 #include <thread.h>
6 int
7 threadread9pmsg(int fd, void *abuf, uint n)
8 {
9 int m, len;
10 uchar *buf;
12 buf = abuf;
14 /* read count */
15 m = threadreadn(fd, buf, BIT32SZ);
16 if(m != BIT32SZ){
17 if(m < 0)
18 return -1;
19 return 0;
20 }
22 len = GBIT32(buf);
23 if(len <= BIT32SZ || len > n){
24 werrstr("bad length in 9P2000 message header");
25 return -1;
26 }
27 len -= BIT32SZ;
28 m = threadreadn(fd, buf+BIT32SZ, len);
29 if(m < len)
30 return 0;
31 return BIT32SZ+m;
32 }