示例#1
0
文件: term.go 项目: krockot/goterm
// Returns the name of the terminal's tty device and an error if
// the terminal's fd is not a tty.
func (t *Terminal) Name() (string, os.Error) {
	cs := C.ttyname(C.int(t.Fd()))
	if cs == nil {
		return "", os.NewError("Not a tty")
	}
	return C.GoString(cs), nil
}
示例#2
0
// Gets the name of a terminal.
//
// char *ttyname(int fd);
func TTYname(fd int) (string, error) {
	name, errno := C.ttyname(C.int(fd))
	if errno != nil {
		return "", errno
	}
	return C.GoString(name), nil
}
示例#3
0
文件: term.go 项目: krockot/goterm
// Opens an available pseudo-terminal and returns Terminal controllers for the master and
// slave.  Also returns an Error, if any.
func OpenPty(attr *Attributes, size *WindowSize) (*Terminal, *Terminal, os.Error) {
	cattr := makeCAttributes(attr)
	csize := makeCWindowSize(size)

	// see Go sources @src/pkg/syscall/exec.go for ForkLock info
	syscall.ForkLock.RLock()
	result := C.goterm_openpty(&cattr, &csize)
	if result.result < 0 {
		syscall.ForkLock.RUnlock()
		return nil, nil, os.NewError("Unable to open pty.")
	}
	syscall.CloseOnExec(int(result.master))
	syscall.CloseOnExec(int(result.slave))
	syscall.ForkLock.RUnlock()

	master := &Terminal{os.NewFile(int(result.master), C.GoString(C.ttyname(result.master)))}
	slave := &Terminal{os.NewFile(int(result.slave), C.GoString(C.ttyname(result.slave)))}
	return master, slave, nil
}