errstr.go 799 B

1234567891011121314151617181920212223242526272829303132333435
  1. // errstr.go -- Error strings.
  2. // Copyright 2009 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. // +build !hurd
  6. // +build !linux
  7. package syscall
  8. //sysnb strerror_r(errnum int, buf []byte) (err Errno)
  9. //strerror_r(errnum _C_int, buf *byte, buflen Size_t) _C_int
  10. func Errstr(errnum int) string {
  11. for len := 128; ; len *= 2 {
  12. b := make([]byte, len)
  13. errno := strerror_r(errnum, b)
  14. if errno == 0 {
  15. i := 0
  16. for b[i] != 0 {
  17. i++
  18. }
  19. // Lowercase first letter: Bad -> bad, but
  20. // STREAM -> STREAM.
  21. if i > 1 && 'A' <= b[0] && b[0] <= 'Z' && 'a' <= b[1] && b[1] <= 'z' {
  22. b[0] += 'a' - 'A'
  23. }
  24. return string(b[:i])
  25. }
  26. if errno != ERANGE {
  27. return "errstr failure"
  28. }
  29. }
  30. }