Skip to content

Commit f1b333f

Browse files
committed
Use Ioctl{SetPointerInt,GetInt} from golang.org/x/sys/unix on linux
Use unix.IoctlSetPointerInt and unix.IoctlGetInt instead of manually implementing them. This avoid the use of the `unsafe` package. Signed-off-by: Tobias Klauser <[email protected]>
1 parent f847fbb commit f1b333f

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

tc_linux.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package console
1919
import (
2020
"fmt"
2121
"os"
22-
"unsafe"
2322

2423
"golang.org/x/sys/unix"
2524
)
@@ -32,17 +31,13 @@ const (
3231
// unlockpt unlocks the slave pseudoterminal device corresponding to the master pseudoterminal referred to by f.
3332
// unlockpt should be called before opening the slave side of a pty.
3433
func unlockpt(f *os.File) error {
35-
var u int32
36-
if _, _, err := unix.Syscall(unix.SYS_IOCTL, f.Fd(), unix.TIOCSPTLCK, uintptr(unsafe.Pointer(&u))); err != 0 {
37-
return err
38-
}
39-
return nil
34+
return unix.IoctlSetPointerInt(int(f.Fd()), unix.TIOCSPTLCK, 0)
4035
}
4136

4237
// ptsname retrieves the name of the first available pts for the given master.
4338
func ptsname(f *os.File) (string, error) {
44-
var u uint32
45-
if _, _, err := unix.Syscall(unix.SYS_IOCTL, f.Fd(), unix.TIOCGPTN, uintptr(unsafe.Pointer(&u))); err != 0 {
39+
u, err := unix.IoctlGetInt(int(f.Fd()), unix.TIOCGPTN)
40+
if err != nil {
4641
return "", err
4742
}
4843
return fmt.Sprintf("/dev/pts/%d", u), nil

0 commit comments

Comments
 (0)