diff --git a/pty_darwin.go b/pty_darwin.go index 0f2bd58..4f4d5ca 100644 --- a/pty_darwin.go +++ b/pty_darwin.go @@ -52,11 +52,9 @@ func ptsname(f *os.File) (string, error) { } func grantpt(f *os.File) error { - var u _C_int - return ioctl(f.Fd(), syscall.TIOCPTYGRANT, uintptr(unsafe.Pointer(&u))) + return ioctl(f.Fd(), syscall.TIOCPTYGRANT, 0) } func unlockpt(f *os.File) error { - var u _C_int - return ioctl(f.Fd(), syscall.TIOCPTYUNLK, uintptr(unsafe.Pointer(&u))) + return ioctl(f.Fd(), syscall.TIOCPTYUNLK, 0) } diff --git a/pty_freebsd.go b/pty_freebsd.go index 17abe28..b341bab 100644 --- a/pty_freebsd.go +++ b/pty_freebsd.go @@ -7,10 +7,6 @@ import ( "unsafe" ) -const ( - SPECNAMELEN = 63 /* max length of devicename */ -) - func posix_openpt(oflag int) (fd int, err error) { r0, _, e1 := syscall.Syscall(syscall.SYS_POSIX_OPENPT, uintptr(oflag), 0, 0) fd = int(r0) @@ -21,7 +17,7 @@ func posix_openpt(oflag int) (fd int, err error) { } func open() (pty, tty *os.File, err error) { - fd, err := posix_openpt(syscall.O_RDWR) + fd, err := posix_openpt(syscall.O_RDWR | syscall.O_CLOEXEC) if err != nil { return nil, nil, err } @@ -40,9 +36,8 @@ func open() (pty, tty *os.File, err error) { } func isptmaster(fd uintptr) (bool, error) { - var result int - err := ioctl(fd, syscall.TIOCPTMASTER, uintptr(unsafe.Pointer(&result))) - return (result == 0), err + err := ioctl(fd, syscall.TIOCPTMASTER, 0) + return err == nil, err } var ( @@ -59,7 +54,7 @@ func ptsname(f *os.File) (string, error) { return "", syscall.EINVAL } - const n = SPECNAMELEN + 1 + const n = _C_SPECNAMELEN + 1 var ( buf = make([]byte, n) arg = fiodgnameArg{Len: n, Buf: (*byte)(unsafe.Pointer(&buf[0]))} diff --git a/pty_linux.go b/pty_linux.go index a1278b8..6e5a042 100644 --- a/pty_linux.go +++ b/pty_linux.go @@ -46,5 +46,6 @@ func ptsname(f *os.File) (string, error) { func unlockpt(f *os.File) error { var u _C_int + // use TIOCSPTLCK with a zero valued arg to clear the slave pty lock return ioctl(f.Fd(), ioctl_TIOCSPTLCK, uintptr(unsafe.Pointer(&u))) } diff --git a/types_freebsd.go b/types_freebsd.go index 7e0cfe8..ce3eb95 100644 --- a/types_freebsd.go +++ b/types_freebsd.go @@ -2,7 +2,14 @@ package pty -// #include +/* +#include +#include +*/ import "C" +const ( + _C_SPECNAMELEN = C.SPECNAMELEN /* max length of devicename */ +) + type fiodgnameArg C.struct_fiodgname_arg diff --git a/ztypes_arm.go b/ztypes_arm.go new file mode 100644 index 0000000..ff0b8fd --- /dev/null +++ b/ztypes_arm.go @@ -0,0 +1,9 @@ +// Created by cgo -godefs - DO NOT EDIT +// cgo -godefs types.go + +package pty + +type ( + _C_int int32 + _C_uint uint32 +) diff --git a/ztypes_freebsd_386.go b/ztypes_freebsd_386.go index a7894a6..d997537 100644 --- a/ztypes_freebsd_386.go +++ b/ztypes_freebsd_386.go @@ -3,6 +3,10 @@ package pty +const ( + _C_SPECNAMELEN = 0x3f +) + type fiodgnameArg struct { Len int32 Buf *byte diff --git a/ztypes_freebsd_amd64.go b/ztypes_freebsd_amd64.go index 9d07d3f..5fa102f 100644 --- a/ztypes_freebsd_amd64.go +++ b/ztypes_freebsd_amd64.go @@ -3,6 +3,10 @@ package pty +const ( + _C_SPECNAMELEN = 0x3f +) + type fiodgnameArg struct { Len int32 Pad_cgo_0 [4]byte diff --git a/ztypes_freebsd_arm.go b/ztypes_freebsd_arm.go new file mode 100644 index 0000000..d997537 --- /dev/null +++ b/ztypes_freebsd_arm.go @@ -0,0 +1,13 @@ +// Created by cgo -godefs - DO NOT EDIT +// cgo -godefs types_freebsd.go + +package pty + +const ( + _C_SPECNAMELEN = 0x3f +) + +type fiodgnameArg struct { + Len int32 + Buf *byte +}