Skip to content

Commit eb474d2

Browse files
maddiecmaglie
authored andcommitted
Use golang.org/x/sys/unix provided ioctl functions
1 parent 578b2ec commit eb474d2

11 files changed

+11
-136
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ go 1.13
55
require (
66
github.com/creack/goselect v0.1.1
77
github.com/stretchr/testify v1.4.0
8-
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9
8+
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009
99
)

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
77
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
88
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
99
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
10-
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 h1:ZBzSG/7F4eNKz2L3GE9o300RX0Az1Bw5HF7PDraD+qU=
11-
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
10+
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 h1:W0lCpv29Hv0UaM1LXb9QlBHLNP8UFfcKjblhVCWftOM=
11+
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1212
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
1313
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1414
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=

serial_unix.go

+8-13
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"strings"
1515
"sync"
1616
"sync/atomic"
17-
"unsafe"
1817

1918
"go.bug.st/serial/unixutils"
2019
"golang.org/x/sys/unix"
@@ -94,11 +93,11 @@ func (port *unixPort) Write(p []byte) (n int, err error) {
9493
}
9594

9695
func (port *unixPort) ResetInputBuffer() error {
97-
return ioctl(port.handle, ioctlTcflsh, unix.TCIFLUSH)
96+
return unix.IoctlSetInt(port.handle, ioctlTcflsh, unix.TCIFLUSH)
9897
}
9998

10099
func (port *unixPort) ResetOutputBuffer() error {
101-
return ioctl(port.handle, ioctlTcflsh, unix.TCOFLUSH)
100+
return unix.IoctlSetInt(port.handle, ioctlTcflsh, unix.TCOFLUSH)
102101
}
103102

104103
func (port *unixPort) SetMode(mode *Mode) error {
@@ -390,29 +389,25 @@ func setRawMode(settings *unix.Termios) {
390389
// native syscall wrapper functions
391390

392391
func (port *unixPort) getTermSettings() (*unix.Termios, error) {
393-
settings := &unix.Termios{}
394-
err := ioctl(port.handle, ioctlTcgetattr, uintptr(unsafe.Pointer(settings)))
395-
return settings, err
392+
return unix.IoctlGetTermios(port.handle, ioctlTcgetattr)
396393
}
397394

398395
func (port *unixPort) setTermSettings(settings *unix.Termios) error {
399-
return ioctl(port.handle, ioctlTcsetattr, uintptr(unsafe.Pointer(settings)))
396+
return unix.IoctlSetTermios(port.handle, ioctlTcsetattr, settings)
400397
}
401398

402399
func (port *unixPort) getModemBitsStatus() (int, error) {
403-
var status int
404-
err := ioctl(port.handle, unix.TIOCMGET, uintptr(unsafe.Pointer(&status)))
405-
return status, err
400+
return unix.IoctlGetInt(port.handle, unix.TIOCMGET)
406401
}
407402

408403
func (port *unixPort) setModemBitsStatus(status int) error {
409-
return ioctl(port.handle, unix.TIOCMSET, uintptr(unsafe.Pointer(&status)))
404+
return unix.IoctlSetPointerInt(port.handle, unix.TIOCMSET, status)
410405
}
411406

412407
func (port *unixPort) acquireExclusiveAccess() error {
413-
return ioctl(port.handle, unix.TIOCEXCL, 0)
408+
return unix.IoctlSetInt(port.handle, unix.TIOCEXCL, 0)
414409
}
415410

416411
func (port *unixPort) releaseExclusiveAccess() error {
417-
return ioctl(port.handle, unix.TIOCNXCL, 0)
412+
return unix.IoctlSetInt(port.handle, unix.TIOCNXCL, 0)
418413
}

syscall_darwin.go

-9
This file was deleted.

syscall_freebsd.go

-9
This file was deleted.

syscall_linux.go

-9
This file was deleted.

syscall_openbsd.go

-9
This file was deleted.

zsyscall_darwin.go

-21
This file was deleted.

zsyscall_freebsd.go

-21
This file was deleted.

zsyscall_linux.go

-21
This file was deleted.

zsyscall_openbsd.go

-21
This file was deleted.

0 commit comments

Comments
 (0)