OSDN Git Service

libgo: Use -fgo-pkgpath.
[pf3gnuchains/gcc-fork.git] / libgo / go / syscall / wait.c
1 /* wait.c -- functions for getting wait status values.
2
3    Copyright 2011 The Go Authors. All rights reserved.
4    Use of this source code is governed by a BSD-style
5    license that can be found in the LICENSE file.
6
7    We use C code to extract the wait status so that we can easily be
8    OS-independent.  */
9
10 #include <stdint.h>
11 #include <sys/wait.h>
12
13 extern _Bool Exited (uint32_t *w)
14   __asm__ ("syscall.Exited.N18_syscall.WaitStatus");
15
16 _Bool
17 Exited (uint32_t *w)
18 {
19   return WIFEXITED (*w) != 0;
20 }
21
22 extern _Bool Signaled (uint32_t *w)
23   __asm__ ("syscall.Signaled.N18_syscall.WaitStatus");
24
25 _Bool
26 Signaled (uint32_t *w)
27 {
28   return WIFSIGNALED (*w) != 0;
29 }
30
31 extern _Bool Stopped (uint32_t *w)
32   __asm__ ("syscall.Stopped.N18_syscall.WaitStatus");
33
34 _Bool
35 Stopped (uint32_t *w)
36 {
37   return WIFSTOPPED (*w) != 0;
38 }
39
40 extern _Bool Continued (uint32_t *w)
41   __asm__ ("syscall.Continued.N18_syscall.WaitStatus");
42
43 _Bool
44 Continued (uint32_t *w)
45 {
46   return WIFCONTINUED (*w) != 0;
47 }
48
49 extern _Bool CoreDump (uint32_t *w)
50   __asm__ ("syscall.CoreDump.N18_syscall.WaitStatus");
51
52 _Bool
53 CoreDump (uint32_t *w)
54 {
55   return WCOREDUMP (*w) != 0;
56 }
57
58 extern int ExitStatus (uint32_t *w)
59   __asm__ ("syscall.ExitStatus.N18_syscall.WaitStatus");
60
61 int
62 ExitStatus (uint32_t *w)
63 {
64   if (!WIFEXITED (*w))
65     return -1;
66   return WEXITSTATUS (*w);
67 }
68
69 extern int Signal (uint32_t *w)
70   __asm__ ("syscall.Signal.N18_syscall.WaitStatus");
71
72 int
73 Signal (uint32_t *w)
74 {
75   if (!WIFSIGNALED (*w))
76     return -1;
77   return WTERMSIG (*w);
78 }
79
80 extern int StopSignal (uint32_t *w)
81   __asm__ ("syscall.StopSignal.N18_syscall.WaitStatus");
82
83 int
84 StopSignal (uint32_t *w)
85 {
86   if (!WIFSTOPPED (*w))
87     return -1;
88   return WSTOPSIG (*w);
89 }
90
91 extern int TrapCause (uint32_t *w)
92   __asm__ ("syscall.TrapCause.N18_syscall.WaitStatus");
93
94 int
95 TrapCause (uint32_t *w __attribute__ ((unused)))
96 {
97 #ifndef __linux__
98   return -1;
99 #else
100   if (!WIFSTOPPED (*w) || WSTOPSIG (*w) != SIGTRAP)
101     return -1;
102   return *w >> 16;
103 #endif
104 }