Skip to content

Commit

Permalink
Merge pull request #51 from kolyshkin/fix-bi
Browse files Browse the repository at this point in the history
Fix ptsname() for big-endian architectures (again)
  • Loading branch information
crosbymichael authored Apr 8, 2021
2 parents 68336a7 + 073d165 commit 65c9061
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tc_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package console
import (
"fmt"
"os"
"unsafe"

"golang.org/x/sys/unix"
)
Expand All @@ -31,13 +32,19 @@ const (
// unlockpt unlocks the slave pseudoterminal device corresponding to the master pseudoterminal referred to by f.
// unlockpt should be called before opening the slave side of a pty.
func unlockpt(f *os.File) error {
return unix.IoctlSetPointerInt(int(f.Fd()), unix.TIOCSPTLCK, 0)
var u int32
// XXX do not use unix.IoctlSetPointerInt here, see commit dbd69c59b81.
if _, _, err := unix.Syscall(unix.SYS_IOCTL, f.Fd(), unix.TIOCSPTLCK, uintptr(unsafe.Pointer(&u))); err != 0 {
return err
}
return nil
}

// ptsname retrieves the name of the first available pts for the given master.
func ptsname(f *os.File) (string, error) {
u, err := unix.IoctlGetInt(int(f.Fd()), unix.TIOCGPTN)
if err != nil {
var u uint32
// XXX do not use unix.IoctlGetInt here, see commit dbd69c59b81.
if _, _, err := unix.Syscall(unix.SYS_IOCTL, f.Fd(), unix.TIOCGPTN, uintptr(unsafe.Pointer(&u))); err != 0 {
return "", err
}
return fmt.Sprintf("/dev/pts/%d", u), nil
Expand Down

0 comments on commit 65c9061

Please sign in to comment.