tc_openbsd_cgo.go 1.3 KB

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