Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -0700 | [diff] [blame] | 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 | |
David K. Bainbridge | c415efe | 2021-08-19 13:05:21 +0000 | [diff] [blame] | 5 | //go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris |
Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -0700 | [diff] [blame] | 6 | // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris |
| 7 | |
| 8 | package unix |
| 9 | |
| 10 | func itoa(val int) string { // do it here rather than with fmt to avoid dependency |
| 11 | if val < 0 { |
| 12 | return "-" + uitoa(uint(-val)) |
| 13 | } |
| 14 | return uitoa(uint(val)) |
| 15 | } |
| 16 | |
| 17 | func uitoa(val uint) string { |
| 18 | var buf [32]byte // big enough for int64 |
| 19 | i := len(buf) - 1 |
| 20 | for val >= 10 { |
| 21 | buf[i] = byte(val%10 + '0') |
| 22 | i-- |
| 23 | val /= 10 |
| 24 | } |
| 25 | buf[i] = byte(val + '0') |
| 26 | return string(buf[i:]) |
| 27 | } |