read9pmsg.c - 9base - revived minimalist port of Plan 9 userland to Unix
(HTM) git clone git://git.suckless.org/9base
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
read9pmsg.c (462B)
---
1 #include <u.h>
2 #include <libc.h>
3 #include <fcall.h>
4
5 int
6 read9pmsg(int fd, void *abuf, uint n)
7 {
8 int m, len;
9 uchar *buf;
10
11 buf = abuf;
12
13 /* read count */
14 m = readn(fd, buf, BIT32SZ);
15 if(m != BIT32SZ){
16 if(m < 0)
17 return -1;
18 return 0;
19 }
20
21 len = GBIT32(buf);
22 if(len <= BIT32SZ || len > n){
23 werrstr("bad length in 9P2000 message header");
24 return -1;
25 }
26 len -= BIT32SZ;
27 m = readn(fd, buf+BIT32SZ, len);
28 if(m < len)
29 return 0;
30 return BIT32SZ+m;
31 }