Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

27 rader
611 B

  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. // +build darwin dragonfly freebsd linux netbsd openbsd solaris
  5. package unix
  6. func itoa(val int) string { // do it here rather than with fmt to avoid dependency
  7. if val < 0 {
  8. return "-" + uitoa(uint(-val))
  9. }
  10. return uitoa(uint(val))
  11. }
  12. func uitoa(val uint) string {
  13. var buf [32]byte // big enough for int64
  14. i := len(buf) - 1
  15. for val >= 10 {
  16. buf[i] = byte(val%10 + '0')
  17. i--
  18. val /= 10
  19. }
  20. buf[i] = byte(val + '0')
  21. return string(buf[i:])
  22. }