Blob
1 #include <lib9.h>3 Waitmsg*4 wait(void)5 {6 int n, l;7 char buf[512], *fld[5];8 Waitmsg *w;10 n = await(buf, sizeof buf-1);11 if(n < 0)12 return nil;13 buf[n] = '\0';14 if(tokenize(buf, fld, nelem(fld)) != nelem(fld)){15 werrstr("couldn't parse wait message");16 return nil;17 }18 l = strlen(fld[4])+1;19 w = malloc(sizeof(Waitmsg)+l);20 if(w == nil)21 return nil;22 w->pid = atoi(fld[0]);23 w->time[0] = atoi(fld[1]);24 w->time[1] = atoi(fld[2]);25 w->time[2] = atoi(fld[3]);26 w->msg = (char*)&w[1];27 memmove(w->msg, fld[4], l);28 return w;29 }