mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-05 08:37:31 -04:00
unix: add GetsockoptString for Darwin, *BSD and Solaris
As suggested by Brad in CL 83275. From what I can tell getsockopt syscall on these OSes doesn't return ERANGE in any case, so these versions don't include the buffer growing. Change-Id: I667c3751021e26defec0a04761a689fa4b78c65d Reviewed-on: https://go-review.googlesource.com/84016 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
committed by
Tobias Klauser
parent
1d2aa6dbde
commit
d5840adf78
@@ -130,6 +130,18 @@ func Getsockname(fd int) (sa Sockaddr, err error) {
|
||||
return anyToSockaddr(&rsa)
|
||||
}
|
||||
|
||||
// GetsockoptString returns the string value of the socket option opt for the
|
||||
// socket associated with fd at the given socket level.
|
||||
func GetsockoptString(fd, level, opt int) (string, error) {
|
||||
buf := make([]byte, 256)
|
||||
vallen := _Socklen(len(buf))
|
||||
err := getsockopt(fd, level, opt, unsafe.Pointer(&buf[0]), &vallen)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(buf[:vallen-1]), nil
|
||||
}
|
||||
|
||||
const ImplementsGetwd = true
|
||||
|
||||
//sys Getcwd(buf []byte) (n int, err error)
|
||||
|
||||
Reference in New Issue
Block a user