Retro68/gcc/libgo/go/syscall/errstr.go

35 lines
783 B
Go
Raw Normal View History

2012-03-27 23:13:14 +00:00
// errstr.go -- Error strings.
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !linux
2012-03-27 23:13:14 +00:00
package syscall
2014-09-21 17:33:12 +00:00
//sysnb strerror_r(errnum int, buf []byte) (err Errno)
//strerror_r(errnum _C_int, buf *byte, buflen Size_t) _C_int
2012-03-27 23:13:14 +00:00
func Errstr(errnum int) string {
for len := 128; ; len *= 2 {
b := make([]byte, len)
2014-09-21 17:33:12 +00:00
errno := strerror_r(errnum, b)
if errno == 0 {
2012-03-27 23:13:14 +00:00
i := 0
for b[i] != 0 {
i++
}
2014-09-21 17:33:12 +00:00
// Lowercase first letter: Bad -> bad, but
// STREAM -> STREAM.
if i > 1 && 'A' <= b[0] && b[0] <= 'Z' && 'a' <= b[1] && b[1] <= 'z' {
b[0] += 'a' - 'A'
}
2012-03-27 23:13:14 +00:00
return string(b[:i])
}
2014-09-21 17:33:12 +00:00
if errno != ERANGE {
return "errstr failure"
2012-03-27 23:13:14 +00:00
}
}
}