-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
util: fix dup2() usage for Linux and Darwin
We must create a new Darwin specific file to handle the lack of DUP2() in Linux ARM64 systems and also the lack of DUP3() in Darwin. In other words: Linux ARM64 must use DUP3() while Darwin must use DUP2(). Other BSDs have DUP3(), allowing us to use the same Linux file for them. Signed-off-by: Bruno Meneguele <[email protected]>
- Loading branch information
Showing
2 changed files
with
37 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// This file contains Darwin (MacOS) specific calls. | ||
|
||
// +build darwin | ||
|
||
package cmd | ||
|
||
// Unfortunatelly MacOS don't have the DUP3() system call, which is forced | ||
// by Linux ARM64 not having the DUP2() anymore. With that, we need to | ||
// repeat the other code and func declarations that are the same. | ||
|
||
// FIXME: there MUST be some better way to do that... only dupFD2() should be | ||
// here. | ||
|
||
import "syscall" | ||
|
||
var ( | ||
sysStdout = syscall.Stdout | ||
sysStderr = syscall.Stderr | ||
) | ||
|
||
func closeFD(fd int) error { | ||
return syscall.Close(fd) | ||
} | ||
|
||
func dupFD(fd int) (int, error) { | ||
return syscall.Dup(fd) | ||
} | ||
|
||
// From what I've seen, darwin is the only OS without DUP3() support | ||
func dupFD2(newFD, oldFD int) error { | ||
return syscall.Dup2(newFD, oldFD) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters