func open() (pty, tty *os.File, err error) {
	p, err := os.OpenFile("/dev/ptmx", os.O_RDWR, 0)
	if err != nil {
		return nil, nil, err
	}
	defer func() {
		if err != nil {
			_ = p.Close()  
		}
	}()
	sname, err := ptsname(p)
	if err != nil {
		return nil, nil, err
	}
	if err := grantpt(p); err != nil {
		return nil, nil, err
	}
	if err := unlockpt(p); err != nil {
		return nil, nil, err
	}
	t, err := os.OpenFile(sname, os.O_RDWR, 0)
	if err != nil {
		return nil, nil, err
	}
	return p, t, nil
}
same code as pty_darwin.go
package pty
import (
	"errors"
	"os"
	"strings"
	"syscall"
	"unsafe"
)