2013-12-05 Richard Biener <rguenther@suse.de>
[official-gcc.git] / libgo / go / syscall / wait.c
blob8c3b53fa4567750d9d8a8b672ed49e0995b5390b
1 /* wait.c -- functions for getting wait status values.
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.
7 We use C code to extract the wait status so that we can easily be
8 OS-independent. */
10 #include <stdint.h>
11 #include <sys/wait.h>
13 #include "runtime.h"
15 extern _Bool Exited (uint32_t *w)
16 __asm__ (GOSYM_PREFIX "syscall.Exited.N18_syscall.WaitStatus");
18 _Bool
19 Exited (uint32_t *w)
21 return WIFEXITED (*w) != 0;
24 extern _Bool Signaled (uint32_t *w)
25 __asm__ (GOSYM_PREFIX "syscall.Signaled.N18_syscall.WaitStatus");
27 _Bool
28 Signaled (uint32_t *w)
30 return WIFSIGNALED (*w) != 0;
33 extern _Bool Stopped (uint32_t *w)
34 __asm__ (GOSYM_PREFIX "syscall.Stopped.N18_syscall.WaitStatus");
36 _Bool
37 Stopped (uint32_t *w)
39 return WIFSTOPPED (*w) != 0;
42 extern _Bool Continued (uint32_t *w)
43 __asm__ (GOSYM_PREFIX "syscall.Continued.N18_syscall.WaitStatus");
45 _Bool
46 Continued (uint32_t *w)
48 return WIFCONTINUED (*w) != 0;
51 extern _Bool CoreDump (uint32_t *w)
52 __asm__ (GOSYM_PREFIX "syscall.CoreDump.N18_syscall.WaitStatus");
54 _Bool
55 CoreDump (uint32_t *w)
57 return WCOREDUMP (*w) != 0;
60 extern int ExitStatus (uint32_t *w)
61 __asm__ (GOSYM_PREFIX "syscall.ExitStatus.N18_syscall.WaitStatus");
63 int
64 ExitStatus (uint32_t *w)
66 if (!WIFEXITED (*w))
67 return -1;
68 return WEXITSTATUS (*w);
71 extern int Signal (uint32_t *w)
72 __asm__ (GOSYM_PREFIX "syscall.Signal.N18_syscall.WaitStatus");
74 int
75 Signal (uint32_t *w)
77 if (!WIFSIGNALED (*w))
78 return -1;
79 return WTERMSIG (*w);
82 extern int StopSignal (uint32_t *w)
83 __asm__ (GOSYM_PREFIX "syscall.StopSignal.N18_syscall.WaitStatus");
85 int
86 StopSignal (uint32_t *w)
88 if (!WIFSTOPPED (*w))
89 return -1;
90 return WSTOPSIG (*w);
93 extern int TrapCause (uint32_t *w)
94 __asm__ (GOSYM_PREFIX "syscall.TrapCause.N18_syscall.WaitStatus");
96 int
97 TrapCause (uint32_t *w __attribute__ ((unused)))
99 #ifndef __linux__
100 return -1;
101 #else
102 if (!WIFSTOPPED (*w) || WSTOPSIG (*w) != SIGTRAP)
103 return -1;
104 return *w >> 16;
105 #endif