mirror of
https://github.com/strongdm/comply
synced 2024-08-29 18:43:32 +00:00
34 lines
964 B
Go
34 lines
964 B
Go
|
// Copyright 2013 The Go Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a BSD-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
|
package readline
|
||
|
|
||
|
import (
|
||
|
"syscall"
|
||
|
"unsafe"
|
||
|
)
|
||
|
|
||
|
// These constants are declared here, rather than importing
|
||
|
// them from the syscall package as some syscall packages, even
|
||
|
// on linux, for example gccgo, do not declare them.
|
||
|
const ioctlReadTermios = 0x5401 // syscall.TCGETS
|
||
|
const ioctlWriteTermios = 0x5402 // syscall.TCSETS
|
||
|
|
||
|
func getTermios(fd int) (*Termios, error) {
|
||
|
termios := new(Termios)
|
||
|
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), ioctlReadTermios, uintptr(unsafe.Pointer(termios)), 0, 0, 0)
|
||
|
if err != 0 {
|
||
|
return nil, err
|
||
|
}
|
||
|
return termios, nil
|
||
|
}
|
||
|
|
||
|
func setTermios(fd int, termios *Termios) error {
|
||
|
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), ioctlWriteTermios, uintptr(unsafe.Pointer(termios)), 0, 0, 0)
|
||
|
if err != 0 {
|
||
|
return err
|
||
|
}
|
||
|
return nil
|
||
|
}
|