diff options
Diffstat (limited to 'libgo/go/net/cgo_unix.go')
-rw-r--r-- | libgo/go/net/cgo_unix.go | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/libgo/go/net/cgo_unix.go b/libgo/go/net/cgo_unix.go index b8090181293..d088eabc2b5 100644 --- a/libgo/go/net/cgo_unix.go +++ b/libgo/go/net/cgo_unix.go @@ -24,6 +24,17 @@ func libc_getaddrinfo(node *byte, service *byte, hints *syscall.Addrinfo, res ** func libc_freeaddrinfo(res *syscall.Addrinfo) __asm__ ("freeaddrinfo") func libc_gai_strerror(errcode int) *byte __asm__ ("gai_strerror") +// bytePtrToString takes a NUL-terminated array of bytes and convert +// it to a Go string. +func bytePtrToString(p *byte) string { + a := (*[10000]byte)(unsafe.Pointer(p)) + i := 0 + for a[i] != 0 { + i++ + } + return string(a[:i]) +} + func cgoLookupHost(name string) (addrs []string, err os.Error, completed bool) { ip, err, completed := cgoLookupIP(name) for _, p := range ip { @@ -99,13 +110,13 @@ func cgoLookupIPCNAME(name string) (addrs []IP, cname string, err os.Error, comp } else if gerrno == syscall.EAI_SYSTEM { str = syscall.Errstr(syscall.GetErrno()) } else { - str = syscall.BytePtrToString(libc_gai_strerror(gerrno)) + str = bytePtrToString(libc_gai_strerror(gerrno)) } return nil, "", &DNSError{Error: str, Name: name}, true } defer libc_freeaddrinfo(res) if res != nil { - cname = syscall.BytePtrToString((*byte)(unsafe.Pointer(res.Ai_canonname))) + cname = bytePtrToString((*byte)(unsafe.Pointer(res.Ai_canonname))) if cname == "" { cname = name } |