File tree Expand file tree Collapse file tree 2 files changed +37
-3
lines changed Expand file tree Collapse file tree 2 files changed +37
-3
lines changed Original file line number Diff line number Diff line change
1
+ // This file contains Darwin (MacOS) specific calls.
2
+
3
+ // +build darwin
4
+
5
+ package cmd
6
+
7
+ // Unfortunatelly MacOS don't have the DUP3() system call, which is forced
8
+ // by Linux ARM64 not having the DUP2() anymore. With that, we need to
9
+ // repeat the other code and func declarations that are the same.
10
+
11
+ // FIXME: there MUST be some better way to do that... only dupFD2() should be
12
+ // here.
13
+
14
+ import "syscall"
15
+
16
+ var (
17
+ sysStdout = syscall .Stdout
18
+ sysStderr = syscall .Stderr
19
+ )
20
+
21
+ func closeFD (fd int ) error {
22
+ return syscall .Close (fd )
23
+ }
24
+
25
+ func dupFD (fd int ) (int , error ) {
26
+ return syscall .Dup (fd )
27
+ }
28
+
29
+ // From what I've seen, darwin is the only OS without DUP3() support
30
+ func dupFD2 (newFD , oldFD int ) error {
31
+ return syscall .Dup2 (newFD , oldFD )
32
+ }
Original file line number Diff line number Diff line change 1
1
// This file contains Linux specific calls.
2
2
3
- // +build !windows
3
+ // +build !windows,!darwin
4
4
5
5
package cmd
6
6
7
7
// Since we're using some system calls that are platform-specific, we need
8
8
// to make sure we have a small layer of compatibility for Unix-like and
9
9
// Windows operating systems. For now, this file is still valid for BSDs
10
- // (MacOS included).
10
+ // (MacOS NOT included)
11
11
12
12
import "syscall"
13
13
@@ -27,6 +27,8 @@ func dupFD(fd int) (int, error) {
27
27
return syscall .Dup (fd )
28
28
}
29
29
30
+ // Dup2() is not supported in Linux arm64, so we need to change it.
31
+ // Dup3() is available in all Linux arches and BSD* variants, but not darwin.
30
32
func dupFD2 (newFD , oldFD int ) error {
31
- return syscall .Dup2 (newFD , oldFD )
33
+ return syscall .Dup3 (newFD , oldFD , 0 )
32
34
}
You can’t perform that action at this time.
0 commit comments