File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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 11// This file contains Linux specific calls.
22
3- // +build !windows
3+ // +build !windows,!darwin
44
55package cmd
66
77// Since we're using some system calls that are platform-specific, we need
88// to make sure we have a small layer of compatibility for Unix-like and
99// Windows operating systems. For now, this file is still valid for BSDs
10- // (MacOS included).
10+ // (MacOS NOT included)
1111
1212import "syscall"
1313
@@ -27,6 +27,8 @@ func dupFD(fd int) (int, error) {
2727 return syscall .Dup (fd )
2828}
2929
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.
3032func dupFD2 (newFD , oldFD int ) error {
31- return syscall .Dup2 (newFD , oldFD )
33+ return syscall .Dup3 (newFD , oldFD , 0 )
3234}
You can’t perform that action at this time.
0 commit comments