github.com/endophage/docker@v1.4.2-0.20161027011718-242853499895/pkg/term/term_solaris.go (about)

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