errstr_linux.go 738 B

1234567891011121314151617181920212223242526272829
  1. // errstr_rtems.go -- RTEMS specific error strings.
  2. // Copyright 2010 The Go Authors. All rights reserved.
  3. // Use of this source code is governed by a BSD-style
  4. // license that can be found in the LICENSE file.
  5. package syscall
  6. import "unsafe"
  7. //sysnb strerror_r(errnum int, b []byte) (errstr *byte)
  8. //strerror_r(errnum _C_int, b *byte, len Size_t) *byte
  9. func Errstr(errnum int) string {
  10. a := make([]byte, 128)
  11. p := strerror_r(errnum, a)
  12. b := (*[1000]byte)(unsafe.Pointer(p))
  13. i := 0
  14. for b[i] != 0 {
  15. i++
  16. }
  17. // Lowercase first letter: Bad -> bad, but STREAM -> STREAM.
  18. if i > 1 && 'A' <= b[0] && b[0] <= 'Z' && 'a' <= b[1] && b[1] <= 'z' {
  19. c := b[0] + 'a' - 'A'
  20. return string(c) + string(b[1:i])
  21. }
  22. return string(b[:i])
  23. }