Blob


1 #include <u.h>
2 #include <libc.h>
4 static Waitmsg*
5 _wait(int nohang)
6 {
7 int n, l;
8 char buf[512], *fld[5];
9 Waitmsg *w;
11 n = (nohang ? awaitnohang : await)(buf, sizeof buf-1);
12 if(n <= 0)
13 return nil;
14 buf[n] = '\0';
15 if(tokenize(buf, fld, nelem(fld)) != nelem(fld)){
16 werrstr("couldn't parse wait message");
17 return nil;
18 }
19 l = strlen(fld[4])+1;
20 w = malloc(sizeof(Waitmsg)+l);
21 if(w == nil)
22 return nil;
23 w->pid = atoi(fld[0]);
24 w->time[0] = atoi(fld[1]);
25 w->time[1] = atoi(fld[2]);
26 w->time[2] = atoi(fld[3]);
27 w->msg = (char*)&w[1];
28 memmove(w->msg, fld[4], l);
29 return w;
30 }
32 Waitmsg*
33 wait(void)
34 {
35 return _wait(0);
36 }
38 Waitmsg*
39 waitnohang(void)
40 {
41 return _wait(1);
42 }