1// Copyright 2013 The Go Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style 3// license that can be found in the LICENSE file. 4 5package readline 6 7import ( 8 "syscall" 9 "unsafe" 10) 11 12// These constants are declared here, rather than importing 13// them from the syscall package as some syscall packages, even 14// on linux, for example gccgo, do not declare them. 15const ioctlReadTermios = 0x5401 // syscall.TCGETS 16const ioctlWriteTermios = 0x5402 // syscall.TCSETS 17 18func getTermios(fd int) (*Termios, error) { 19 termios := new(Termios) 20 _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), ioctlReadTermios, uintptr(unsafe.Pointer(termios)), 0, 0, 0) 21 if err != 0 { 22 return nil, err 23 } 24 return termios, nil 25} 26 27func setTermios(fd int, termios *Termios) error { 28 _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), ioctlWriteTermios, uintptr(unsafe.Pointer(termios)), 0, 0, 0) 29 if err != 0 { 30 return err 31 } 32 return nil 33} 34