| 1 |
// Copyright 2017 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 |
|
| 5 |
// Package testpty is a simple pseudo-terminal package for Unix systems, |
| 6 |
// implemented by calling C functions via cgo. |
| 7 |
package testpty |
| 8 |
|
| 9 |
import ( |
| 10 |
"errors" |
| 11 |
"fmt" |
| 12 |
"os" |
| 13 |
) |
| 14 |
|
| 15 |
type PtyError struct { |
| 16 |
FuncName string |
| 17 |
ErrorString string |
| 18 |
Errno error |
| 19 |
} |
| 20 |
|
| 21 |
func ptyError(name string, err error) *PtyError { |
| 22 |
return &PtyError{name, err.Error(), err} |
| 23 |
} |
| 24 |
|
| 25 |
func (e *PtyError) Error() string { |
| 26 |
return fmt.Sprintf("%s: %s", e.FuncName, e.ErrorString) |
| 27 |
} |
| 28 |
|
| 29 |
func (e *PtyError) Unwrap() error { return e.Errno } |
| 30 |
|
| 31 |
var ErrNotSupported = errors.New("testpty.Open not implemented on this platform") |
| 32 |
|
| 33 |
// Open returns a control pty and the name of the linked process tty. |
| 34 |
// |
| 35 |
// If Open is not implemented on this platform, it returns ErrNotSupported. |
| 36 |
func Open() (pty *os.File, processTTY string, err error) { |
| 37 |
return open() |
| 38 |
} |