From eb474d2569e57b1a47c1d388dc2d9f75194a5e34 Mon Sep 17 00:00:00 2001 From: Maddie Zhan Date: Thu, 10 Sep 2020 16:57:12 +0800 Subject: [PATCH] Use golang.org/x/sys/unix provided ioctl functions --- go.mod | 2 +- go.sum | 4 ++-- serial_unix.go | 21 ++++++++------------- syscall_darwin.go | 9 --------- syscall_freebsd.go | 9 --------- syscall_linux.go | 9 --------- syscall_openbsd.go | 9 --------- zsyscall_darwin.go | 21 --------------------- zsyscall_freebsd.go | 21 --------------------- zsyscall_linux.go | 21 --------------------- zsyscall_openbsd.go | 21 --------------------- 11 files changed, 11 insertions(+), 136 deletions(-) delete mode 100644 syscall_darwin.go delete mode 100644 syscall_freebsd.go delete mode 100644 syscall_linux.go delete mode 100644 syscall_openbsd.go delete mode 100644 zsyscall_darwin.go delete mode 100644 zsyscall_freebsd.go delete mode 100644 zsyscall_linux.go delete mode 100644 zsyscall_openbsd.go diff --git a/go.mod b/go.mod index 2035b85..685d2bc 100644 --- a/go.mod +++ b/go.mod @@ -5,5 +5,5 @@ go 1.13 require ( github.com/creack/goselect v0.1.1 github.com/stretchr/testify v1.4.0 - golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 + golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 ) diff --git a/go.sum b/go.sum index b1c6e18..9f04ea9 100644 --- a/go.sum +++ b/go.sum @@ -7,8 +7,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 h1:ZBzSG/7F4eNKz2L3GE9o300RX0Az1Bw5HF7PDraD+qU= -golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 h1:W0lCpv29Hv0UaM1LXb9QlBHLNP8UFfcKjblhVCWftOM= +golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= diff --git a/serial_unix.go b/serial_unix.go index 2e72473..f9e887c 100644 --- a/serial_unix.go +++ b/serial_unix.go @@ -14,7 +14,6 @@ import ( "strings" "sync" "sync/atomic" - "unsafe" "go.bug.st/serial/unixutils" "golang.org/x/sys/unix" @@ -94,11 +93,11 @@ func (port *unixPort) Write(p []byte) (n int, err error) { } func (port *unixPort) ResetInputBuffer() error { - return ioctl(port.handle, ioctlTcflsh, unix.TCIFLUSH) + return unix.IoctlSetInt(port.handle, ioctlTcflsh, unix.TCIFLUSH) } func (port *unixPort) ResetOutputBuffer() error { - return ioctl(port.handle, ioctlTcflsh, unix.TCOFLUSH) + return unix.IoctlSetInt(port.handle, ioctlTcflsh, unix.TCOFLUSH) } func (port *unixPort) SetMode(mode *Mode) error { @@ -390,29 +389,25 @@ func setRawMode(settings *unix.Termios) { // native syscall wrapper functions func (port *unixPort) getTermSettings() (*unix.Termios, error) { - settings := &unix.Termios{} - err := ioctl(port.handle, ioctlTcgetattr, uintptr(unsafe.Pointer(settings))) - return settings, err + return unix.IoctlGetTermios(port.handle, ioctlTcgetattr) } func (port *unixPort) setTermSettings(settings *unix.Termios) error { - return ioctl(port.handle, ioctlTcsetattr, uintptr(unsafe.Pointer(settings))) + return unix.IoctlSetTermios(port.handle, ioctlTcsetattr, settings) } func (port *unixPort) getModemBitsStatus() (int, error) { - var status int - err := ioctl(port.handle, unix.TIOCMGET, uintptr(unsafe.Pointer(&status))) - return status, err + return unix.IoctlGetInt(port.handle, unix.TIOCMGET) } func (port *unixPort) setModemBitsStatus(status int) error { - return ioctl(port.handle, unix.TIOCMSET, uintptr(unsafe.Pointer(&status))) + return unix.IoctlSetPointerInt(port.handle, unix.TIOCMSET, status) } func (port *unixPort) acquireExclusiveAccess() error { - return ioctl(port.handle, unix.TIOCEXCL, 0) + return unix.IoctlSetInt(port.handle, unix.TIOCEXCL, 0) } func (port *unixPort) releaseExclusiveAccess() error { - return ioctl(port.handle, unix.TIOCNXCL, 0) + return unix.IoctlSetInt(port.handle, unix.TIOCNXCL, 0) } diff --git a/syscall_darwin.go b/syscall_darwin.go deleted file mode 100644 index 5ee0a2b..0000000 --- a/syscall_darwin.go +++ /dev/null @@ -1,9 +0,0 @@ -// -// Copyright 2014-2020 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -package serial - -//sys ioctl(fd int, req uint64, data uintptr) (err error) diff --git a/syscall_freebsd.go b/syscall_freebsd.go deleted file mode 100644 index 5ee0a2b..0000000 --- a/syscall_freebsd.go +++ /dev/null @@ -1,9 +0,0 @@ -// -// Copyright 2014-2020 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -package serial - -//sys ioctl(fd int, req uint64, data uintptr) (err error) diff --git a/syscall_linux.go b/syscall_linux.go deleted file mode 100644 index 5ee0a2b..0000000 --- a/syscall_linux.go +++ /dev/null @@ -1,9 +0,0 @@ -// -// Copyright 2014-2020 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -package serial - -//sys ioctl(fd int, req uint64, data uintptr) (err error) diff --git a/syscall_openbsd.go b/syscall_openbsd.go deleted file mode 100644 index 5ee0a2b..0000000 --- a/syscall_openbsd.go +++ /dev/null @@ -1,9 +0,0 @@ -// -// Copyright 2014-2020 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -package serial - -//sys ioctl(fd int, req uint64, data uintptr) (err error) diff --git a/zsyscall_darwin.go b/zsyscall_darwin.go deleted file mode 100644 index 9fd8772..0000000 --- a/zsyscall_darwin.go +++ /dev/null @@ -1,21 +0,0 @@ -// -// Copyright 2014-2020 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -// This file is machine generated by the command: -// mksyscall.pl serial_darwin.go -// The generated stub is modified to make it compile under the "serial" package - -package serial - -import "golang.org/x/sys/unix" - -func ioctl(fd int, req uint64, data uintptr) (err error) { - _, _, e1 := unix.Syscall(unix.SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(data)) - if e1 != 0 { - err = e1 - } - return -} diff --git a/zsyscall_freebsd.go b/zsyscall_freebsd.go deleted file mode 100644 index d35b1f3..0000000 --- a/zsyscall_freebsd.go +++ /dev/null @@ -1,21 +0,0 @@ -// -// Copyright 2014-2020 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -// This file is machine generated by the command: -// mksyscall.pl serial_freebsd.go -// The generated stub is modified to make it compile under the "serial" package - -package serial - -import "golang.org/x/sys/unix" - -func ioctl(fd int, req uint64, data uintptr) (err error) { - _, _, e1 := unix.Syscall(unix.SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(data)) - if e1 != 0 { - err = e1 - } - return -} diff --git a/zsyscall_linux.go b/zsyscall_linux.go deleted file mode 100644 index 1054f29..0000000 --- a/zsyscall_linux.go +++ /dev/null @@ -1,21 +0,0 @@ -// -// Copyright 2014-2020 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -// This file is machine generated by the command: -// mksyscall.pl serial_linux.go -// The generated stub is modified to make it compile under the "serial" package - -package serial - -import "golang.org/x/sys/unix" - -func ioctl(fd int, req uint64, data uintptr) (err error) { - _, _, e1 := unix.Syscall(unix.SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(data)) - if e1 != 0 { - err = e1 - } - return -} diff --git a/zsyscall_openbsd.go b/zsyscall_openbsd.go deleted file mode 100644 index 7c63d52..0000000 --- a/zsyscall_openbsd.go +++ /dev/null @@ -1,21 +0,0 @@ -// -// Copyright 2014-2020 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -// This file is machine generated by the command: -// mksyscall.pl serial_openbsd.go -// The generated stub is modified to make it compile under the "serial" package - -package serial - -import "syscall" - -func ioctl(fd int, req uint64, data uintptr) (err error) { - _, _, e1 := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(data)) - if e1 != 0 { - err = e1 - } - return -}