github.com/jiasir/docker@v1.3.3-0.20170609024000-252e610103e7/pkg/term/winsize_solaris_cgo.go (about) 1 // +build solaris,cgo 2 3 package term 4 5 import ( 6 "unsafe" 7 8 "golang.org/x/sys/unix" 9 ) 10 11 /* 12 #include <unistd.h> 13 #include <stropts.h> 14 #include <termios.h> 15 16 // Small wrapper to get rid of variadic args of ioctl() 17 int my_ioctl(int fd, int cmd, struct winsize *ws) { 18 return ioctl(fd, cmd, ws); 19 } 20 */ 21 import "C" 22 23 // GetWinsize returns the window size based on the specified file descriptor. 24 func GetWinsize(fd uintptr) (*Winsize, error) { 25 ws := &Winsize{} 26 ret, err := C.my_ioctl(C.int(fd), C.int(unix.TIOCGWINSZ), (*C.struct_winsize)(unsafe.Pointer(ws))) 27 // Skip retval = 0 28 if ret == 0 { 29 return ws, nil 30 } 31 return ws, err 32 } 33 34 // SetWinsize tries to set the specified window size for the specified file descriptor. 35 func SetWinsize(fd uintptr, ws *Winsize) error { 36 ret, err := C.my_ioctl(C.int(fd), C.int(unix.TIOCSWINSZ), (*C.struct_winsize)(unsafe.Pointer(ws))) 37 // Skip retval = 0 38 if ret == 0 { 39 return nil 40 } 41 return err 42 }