proc: append to ExtraFiles slice pointer
All checks were successful
Build / Create distribution (push) Successful in 1m30s
Test / Run NixOS test (push) Successful in 4m4s

This is useful for initialising extra files before command.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
Ophestra 2025-01-21 12:51:39 +09:00
parent dfcdc5ce20
commit 82029948e6
Signed by: cat
SSH Key Fingerprint: SHA256:gQ67O0enBZ7UdZypgtspB2FDM1g3GVw8nX0XSdcFw8Q

View File

@ -6,8 +6,12 @@ import (
)
func ExtraFile(cmd *exec.Cmd, f *os.File) (fd uintptr) {
return ExtraFileSlice(&cmd.ExtraFiles, f)
}
func ExtraFileSlice(extraFiles *[]*os.File, f *os.File) (fd uintptr) {
// ExtraFiles: If non-nil, entry i becomes file descriptor 3+i.
fd = uintptr(3 + len(cmd.ExtraFiles))
cmd.ExtraFiles = append(cmd.ExtraFiles, f)
fd = uintptr(3 + len(*extraFiles))
*extraFiles = append(*extraFiles, f)
return
}