wait.c 565 B

1234567891011121314151617181920212223242526272829303132
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <fcall.h>
  4. Waitmsg*
  5. wait(void)
  6. {
  7. int n, l;
  8. char buf[512], *fld[5];
  9. 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. }