2013-12-05 Richard Biener <rguenther@suse.de>
[official-gcc.git] / libgo / go / syscall / errstr_nor.go
blob796561adda08a5fd34fe808f616fbcb4ce9a8b20
1 // errstr.go -- Error strings when there is no strerror_r.
3 // Copyright 2011 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 (
10 "sync"
11 "unsafe"
14 //sysnb strerror(errnum int) (buf *byte)
15 //strerror(errnum _C_int) *byte
17 var errstr_lock sync.Mutex
19 func Errstr(errno int) string {
20 errstr_lock.Lock()
22 bp := strerror(errno)
23 b := (*[1000]byte)(unsafe.Pointer(bp))
24 i := 0
25 for b[i] != 0 {
26 i++
29 // Lowercase first letter: Bad -> bad, but STREAM -> STREAM.
30 var s string
31 if i > 1 && 'A' <= b[0] && b[0] <= 'Z' && 'a' <= b[1] && b[1] <= 'z' {
32 c := b[0] + 'a' - 'A'
33 s = string(c) + string(b[1:i])
34 } else {
35 s = string(b[:i])
38 errstr_lock.Unlock()
40 return s