Skip to content

Commit

Permalink
Call ioctl using Syscall, convert pointers in call
Browse files Browse the repository at this point in the history
Replace `syscall.Syscall6` function calls where `syscall.SYS_IOCTL` is
passed with `syscall.Syscall` and convert `unsafe.Pointer` to `uintptr`
in argument list.
  • Loading branch information
niten94 committed Dec 7, 2024
1 parent 450b22f commit 466971d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
20 changes: 10 additions & 10 deletions tscreen_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (t *tScreen) termioInit() error {
var e error
var newtios termiosPrivate
var fd uintptr
var tios uintptr
var tios unsafe.Pointer
var ioc uintptr
t.tiosp = &termiosPrivate{}

Expand All @@ -40,10 +40,10 @@ func (t *tScreen) termioInit() error {
goto failed
}

tios = uintptr(unsafe.Pointer(t.tiosp))
tios = unsafe.Pointer(t.tiosp)
ioc = uintptr(syscall.TIOCGETA)
fd = uintptr(t.out.(*os.File).Fd())
if _, _, e1 := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioc, tios, 0, 0, 0); e1 != 0 {
if _, _, e1 := syscall.Syscall(syscall.SYS_IOCTL, fd, ioc, uintptr(tios)); e1 != 0 {
e = e1
goto failed
}
Expand All @@ -58,10 +58,10 @@ func (t *tScreen) termioInit() error {
newtios.Cflag &^= syscall.CSIZE | syscall.PARENB
newtios.Cflag |= syscall.CS8

tios = uintptr(unsafe.Pointer(&newtios))
tios = unsafe.Pointer(&newtios)

ioc = uintptr(syscall.TIOCSETA)
if _, _, e1 := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioc, tios, 0, 0, 0); e1 != 0 {
if _, _, e1 := syscall.Syscall(syscall.SYS_IOCTL, fd, ioc, uintptr(tios)); e1 != 0 {
e = e1
goto failed
}
Expand Down Expand Up @@ -93,8 +93,8 @@ func (t *tScreen) termioFini() {
if t.out != nil {
fd := uintptr(t.out.(*os.File).Fd())
ioc := uintptr(syscall.TIOCSETAF)
tios := uintptr(unsafe.Pointer(t.tiosp))
syscall.Syscall6(syscall.SYS_IOCTL, fd, ioc, tios, 0, 0, 0)
tios := unsafe.Pointer(t.tiosp)
syscall.Syscall(syscall.SYS_IOCTL, fd, ioc, uintptr(tios))
t.out.(*os.File).Close()
}
if t.in != nil {
Expand All @@ -106,10 +106,10 @@ func (t *tScreen) getWinSize() (int, int, error) {

fd := uintptr(t.out.(*os.File).Fd())
dim := [4]uint16{}
dimp := uintptr(unsafe.Pointer(&dim))
dimp := unsafe.Pointer(&dim)
ioc := uintptr(syscall.TIOCGWINSZ)
if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL,
fd, ioc, dimp, 0, 0, 0); err != 0 {
if _, _, err := syscall.Syscall(syscall.SYS_IOCTL,
fd, ioc, uintptr(dimp)); err != 0 {
return -1, -1, err
}
return int(dim[1]), int(dim[0]), nil
Expand Down
20 changes: 10 additions & 10 deletions tscreen_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (t *tScreen) termioInit() error {
var e error
var newtios termiosPrivate
var fd uintptr
var tios uintptr
var tios unsafe.Pointer
var ioc uintptr
t.tiosp = &termiosPrivate{}

Expand All @@ -60,10 +60,10 @@ func (t *tScreen) termioInit() error {
goto failed
}

tios = uintptr(unsafe.Pointer(t.tiosp))
tios = unsafe.Pointer(t.tiosp)
ioc = uintptr(syscall.TIOCGETA)
fd = uintptr(t.out.(*poller.FD).Sysfd())
if _, _, e1 := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioc, tios, 0, 0, 0); e1 != 0 {
if _, _, e1 := syscall.Syscall(syscall.SYS_IOCTL, fd, ioc, uintptr(tios)); e1 != 0 {
e = e1
goto failed
}
Expand All @@ -78,10 +78,10 @@ func (t *tScreen) termioInit() error {
newtios.Cflag &^= syscall.CSIZE | syscall.PARENB
newtios.Cflag |= syscall.CS8

tios = uintptr(unsafe.Pointer(&newtios))
tios = unsafe.Pointer(&newtios)

ioc = uintptr(syscall.TIOCSETA)
if _, _, e1 := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioc, tios, 0, 0, 0); e1 != 0 {
if _, _, e1 := syscall.Syscall(syscall.SYS_IOCTL, fd, ioc, uintptr(tios)); e1 != 0 {
e = e1
goto failed
}
Expand Down Expand Up @@ -113,8 +113,8 @@ func (t *tScreen) termioFini() {
if t.out != nil {
fd := uintptr(t.out.(*poller.FD).Sysfd())
ioc := uintptr(syscall.TIOCSETAF)
tios := uintptr(unsafe.Pointer(t.tiosp))
syscall.Syscall6(syscall.SYS_IOCTL, fd, ioc, tios, 0, 0, 0)
tios := unsafe.Pointer(t.tiosp)
syscall.Syscall(syscall.SYS_IOCTL, fd, ioc, uintptr(tios))
t.out.(*poller.FD).Close()
}

Expand All @@ -127,10 +127,10 @@ func (t *tScreen) getWinSize() (int, int, error) {

fd := uintptr(t.out.(*poller.FD).Sysfd())
dim := [4]uint16{}
dimp := uintptr(unsafe.Pointer(&dim))
dimp := unsafe.Pointer(&dim)
ioc := uintptr(syscall.TIOCGWINSZ)
if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL,
fd, ioc, dimp, 0, 0, 0); err != 0 {
if _, _, err := syscall.Syscall(syscall.SYS_IOCTL,
fd, ioc, uintptr(dimp)); err != 0 {
return -1, -1, err
}
return int(dim[1]), int(dim[0]), nil
Expand Down

0 comments on commit 466971d

Please sign in to comment.