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