github.com/aitjcize/Overlord@v0.0.0-20240314041920-104a804cf5e8/overlord/sysutils_posix.go (about) 1 // Copyright 2015 The Chromium OS Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package overlord 6 7 import ( 8 // #cgo LDFLAGS: -lc 9 // #include <unistd.h> 10 "C" 11 "errors" 12 ) 13 14 // Ttyname returns the TTY name of a given file descriptor. 15 func Ttyname(fd uintptr) (string, error) { 16 var ttyname *C.char 17 ttyname = C.ttyname(C.int(fd)) 18 if ttyname == nil { 19 return "", errors.New("ttyname returned NULL") 20 } 21 return C.GoString(ttyname), nil 22 }