1// Copyright 2022 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
5package unix
6
7import (
8	"internal/abi"
9	"unsafe"
10)
11
12//go:cgo_import_dynamic libc_grantpt grantpt "/usr/lib/libSystem.B.dylib"
13func libc_grantpt_trampoline()
14
15func Grantpt(fd int) error {
16	_, _, errno := syscall_syscall6(abi.FuncPCABI0(libc_grantpt_trampoline), uintptr(fd), 0, 0, 0, 0, 0)
17	if errno != 0 {
18		return errno
19	}
20	return nil
21}
22
23//go:cgo_import_dynamic libc_unlockpt unlockpt "/usr/lib/libSystem.B.dylib"
24func libc_unlockpt_trampoline()
25
26func Unlockpt(fd int) error {
27	_, _, errno := syscall_syscall6(abi.FuncPCABI0(libc_unlockpt_trampoline), uintptr(fd), 0, 0, 0, 0, 0)
28	if errno != 0 {
29		return errno
30	}
31	return nil
32}
33
34//go:cgo_import_dynamic libc_ptsname_r ptsname_r "/usr/lib/libSystem.B.dylib"
35func libc_ptsname_r_trampoline()
36
37func Ptsname(fd int) (string, error) {
38	buf := make([]byte, 256)
39	_, _, errno := syscall_syscall6(abi.FuncPCABI0(libc_ptsname_r_trampoline),
40		uintptr(fd),
41		uintptr(unsafe.Pointer(&buf[0])),
42		uintptr(len(buf)-1),
43		0, 0, 0)
44	if errno != 0 {
45		return "", errno
46	}
47	for i, c := range buf {
48		if c == 0 {
49			buf = buf[:i]
50			break
51		}
52	}
53	return string(buf), nil
54}
55
56//go:cgo_import_dynamic libc_posix_openpt posix_openpt "/usr/lib/libSystem.B.dylib"
57func libc_posix_openpt_trampoline()
58
59func PosixOpenpt(flag int) (fd int, err error) {
60	ufd, _, errno := syscall_syscall6(abi.FuncPCABI0(libc_posix_openpt_trampoline), uintptr(flag), 0, 0, 0, 0, 0)
61	if errno != 0 {
62		return -1, errno
63	}
64	return int(ufd), nil
65}
66