-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathPosixShim.java
More file actions
110 lines (86 loc) · 3.88 KB
/
Copy pathPosixShim.java
File metadata and controls
110 lines (86 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package org.python.util;
import jnr.posix.util.Platform;
/**
* Created by isaiah on 6/14/16.
*/
public class PosixShim {
public interface WaitMacros {
boolean WIFEXITED(long status);
boolean WIFSIGNALED(long status);
int WTERMSIG(long status);
int WEXITSTATUS(long status);
int WSTOPSIG(long status);
boolean WIFSTOPPED(long status);
boolean WCOREDUMP(long status);
}
public static class BSDWaitMacros implements WaitMacros {
public final long _WSTOPPED = 0177;
// Only confirmed on Darwin
public final long WCOREFLAG = 0200;
public long _WSTATUS(long status) {
return status & _WSTOPPED;
}
public boolean WIFEXITED(long status) {
return _WSTATUS(status) == 0;
}
public boolean WIFSIGNALED(long status) {
return _WSTATUS(status) != _WSTOPPED && _WSTATUS(status) != 0;
}
public int WTERMSIG(long status) {
return (int)_WSTATUS(status);
}
public int WEXITSTATUS(long status) {
// not confirmed on all platforms
return (int)((status >>> 8) & 0xFF);
}
public int WSTOPSIG(long status) {
return (int)(status >>> 8);
}
public boolean WIFSTOPPED(long status) {
return _WSTATUS(status) == _WSTOPPED && WSTOPSIG(status) != 0x13;
}
public boolean WCOREDUMP(long status) {
return (status & WCOREFLAG) != 0;
}
}
public static class LinuxWaitMacros implements WaitMacros {
private int __WAIT_INT(long status) { return (int)status; }
private int __W_EXITCODE(int ret, int sig) { return (ret << 8) | sig; }
private int __W_STOPCODE(int sig) { return (sig << 8) | 0x7f; }
private static int __W_CONTINUED = 0xffff;
private static int __WCOREFLAG = 0x80;
/* If WIFEXITED(STATUS), the low-order 8 bits of the status. */
private int __WEXITSTATUS(long status) { return (int)((status & 0xff00) >> 8); }
/* If WIFSIGNALED(STATUS), the terminating signal. */
private int __WTERMSIG(long status) { return (int)(status & 0x7f); }
/* If WIFSTOPPED(STATUS), the signal that stopped the child. */
private int __WSTOPSIG(long status) { return __WEXITSTATUS(status); }
/* Nonzero if STATUS indicates normal termination. */
private boolean __WIFEXITED(long status) { return __WTERMSIG(status) == 0; }
/* Nonzero if STATUS indicates termination by a signal. */
private boolean __WIFSIGNALED(long status) {
return ((status & 0x7f) + 1) >> 1 > 0;
}
/* Nonzero if STATUS indicates the child is stopped. */
private boolean __WIFSTOPPED(long status) { return (status & 0xff) == 0x7f; }
/* Nonzero if STATUS indicates the child dumped core. */
private boolean __WCOREDUMP(long status) { return (status & __WCOREFLAG) != 0; }
/* Macros for constructing status values. */
public int WEXITSTATUS(long status) { return __WEXITSTATUS (__WAIT_INT (status)); }
public int WTERMSIG(long status) { return __WTERMSIG(__WAIT_INT(status)); }
public int WSTOPSIG(long status) { return __WSTOPSIG(__WAIT_INT(status)); }
public boolean WIFEXITED(long status) { return __WIFEXITED(__WAIT_INT(status)); }
public boolean WIFSIGNALED(long status) { return __WIFSIGNALED(__WAIT_INT(status)); }
public boolean WIFSTOPPED(long status) { return __WIFSTOPPED(__WAIT_INT(status)); }
public boolean WCOREDUMP(long status) { return __WCOREDUMP(__WAIT_INT(status)); }
}
public static final WaitMacros WAIT_MACROS;
static {
if (Platform.IS_BSD) {
WAIT_MACROS = new BSDWaitMacros();
} else {
// need other platforms
WAIT_MACROS = new LinuxWaitMacros();
}
}
}