github.com/llvm-mirror/llgo@v0.0.0-20190322182713-bf6f0a60fce1/third_party/gofrontend/libgo/go/syscall/errstr.go (about) 1 // errstr.go -- Error strings. 2 3 // Copyright 2009 The Go Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file. 6 7 package syscall 8 9 //sysnb strerror_r(errnum int, buf []byte) (err Errno) 10 //strerror_r(errnum _C_int, buf *byte, buflen Size_t) _C_int 11 12 func Errstr(errnum int) string { 13 for len := 128; ; len *= 2 { 14 b := make([]byte, len) 15 errno := strerror_r(errnum, b) 16 if errno == 0 { 17 i := 0 18 for b[i] != 0 { 19 i++ 20 } 21 // Lowercase first letter: Bad -> bad, but 22 // STREAM -> STREAM. 23 if i > 1 && 'A' <= b[0] && b[0] <= 'Z' && 'a' <= b[1] && b[1] <= 'z' { 24 b[0] += 'a' - 'A' 25 } 26 return string(b[:i]) 27 } 28 if errno != ERANGE { 29 return "errstr failure" 30 } 31 } 32 }