tc_openbsd_cgo.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //go:build openbsd && cgo
  2. // +build openbsd,cgo
  3. /*
  4. Copyright The containerd Authors.
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. */
  15. package console
  16. import (
  17. "os"
  18. "golang.org/x/sys/unix"
  19. )
  20. //#include <stdlib.h>
  21. import "C"
  22. const (
  23. cmdTcGet = unix.TIOCGETA
  24. cmdTcSet = unix.TIOCSETA
  25. )
  26. // ptsname retrieves the name of the first available pts for the given master.
  27. func ptsname(f *os.File) (string, error) {
  28. ptspath, err := C.ptsname(C.int(f.Fd()))
  29. if err != nil {
  30. return "", err
  31. }
  32. return C.GoString(ptspath), nil
  33. }
  34. // unlockpt unlocks the slave pseudoterminal device corresponding to the master pseudoterminal referred to by f.
  35. // unlockpt should be called before opening the slave side of a pty.
  36. func unlockpt(f *os.File) error {
  37. if _, err := C.grantpt(C.int(f.Fd())); err != nil {
  38. return err
  39. }
  40. return nil
  41. }