str.go 481 B

1234567891011121314151617181920
  1. // Copyright 2009 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package unix
  5. func itoa(val int) string { // do it here rather than with fmt to avoid dependency
  6. if val < 0 {
  7. return "-" + itoa(-val)
  8. }
  9. var buf [32]byte // big enough for int64
  10. i := len(buf) - 1
  11. for val >= 10 {
  12. buf[i] = byte(val%10 + '0')
  13. i--
  14. val /= 10
  15. }
  16. buf[i] = byte(val + '0')
  17. return string(buf[i:])
  18. }