~ubuntu-branches/ubuntu/feisty/9base/feisty

« back to all changes in this revision

Viewing changes to lib9/wait.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2006-01-25 15:33:00 UTC
  • Revision ID: james.westby@ubuntu.com-20060125153300-6hh4p9wx8iqqply5
Tags: upstream-2
ImportĀ upstreamĀ versionĀ 2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <u.h>
 
2
#include <libc.h>
 
3
 
 
4
static Waitmsg*
 
5
_wait(int n, char *buf)
 
6
{
 
7
        int l;
 
8
        char *fld[5];
 
9
        Waitmsg *w;
 
10
 
 
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
}
 
30
 
 
31
Waitmsg*
 
32
wait(void)
 
33
{
 
34
        char buf[256];
 
35
 
 
36
        return _wait(await(buf, sizeof buf-1), buf);
 
37
}
 
38
 
 
39
Waitmsg*
 
40
waitnohang(void)
 
41
{
 
42
        char buf[256];
 
43
 
 
44
        return _wait(awaitnohang(buf, sizeof buf-1), buf);
 
45
}
 
46
 
 
47
Waitmsg*
 
48
waitfor(int pid)
 
49
{
 
50
        char buf[256];
 
51
 
 
52
        return _wait(awaitfor(pid, buf, sizeof buf-1), buf);
 
53
}
 
54