c++, coroutines: Simplify separation of the user function body and ramp.
[official-gcc.git] / libgo / go / syscall / errstr.go
blob02f228adc59dabfe7e7cf0f7b55c61b162dc2a11
1 // errstr.go -- Error strings.
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.
7 package syscall
9 import "internal/bytealg"
11 //extern go_strerror
12 func go_strerror(_C_int, *byte, Size_t) _C_int
14 func Errstr(errnum int) string {
15 for size := 128; ; size *= 2 {
16 b := make([]byte, size)
17 errno := go_strerror(_C_int(errnum), &b[0], Size_t(len(b)))
18 if errno == 0 {
19 i := bytealg.IndexByte(b, 0)
20 // Lowercase first letter: Bad -> bad, but
21 // STREAM -> STREAM.
22 if i > 1 && 'A' <= b[0] && b[0] <= 'Z' && 'a' <= b[1] && b[1] <= 'z' {
23 b[0] += 'a' - 'A'
25 return string(b[:i])
27 if Errno(errno) != ERANGE {
28 return "strerror_r failure"