2011-06-14 09:20:34 -06:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2014-12-31 13:18:59 -07:00
|
|
|
// Simple converions to avoid depending on strconv.
|
build: add build comments to core packages
The go/build package already recognizes
system-specific file names like
mycode_darwin.go
mycode_darwin_386.go
mycode_386.s
However, it is also common to write files that
apply to multiple architectures, so a recent CL added
to go/build the ability to process comments
listing a set of conditions for building. For example:
// +build darwin freebsd openbsd/386
says that this file should be compiled only on
OS X, FreeBSD, or 32-bit x86 OpenBSD systems.
These conventions are not yet documented
(hence this long CL description).
This CL adds build comments to the multi-system
files in the core library, a step toward making it
possible to use go/build to build them.
With this change go/build can handle crypto/rand,
exec, net, path/filepath, os/user, and time.
os and syscall need additional adjustments.
R=golang-dev, r, gri, r, gustavo
CC=golang-dev
https://golang.org/cl/5011046
2011-09-15 14:48:57 -06:00
|
|
|
|
2011-06-14 09:20:34 -06:00
|
|
|
package os
|
|
|
|
|
2014-12-31 13:18:59 -07:00
|
|
|
// Convert integer to decimal string
|
|
|
|
func itoa(val int) string {
|
2011-06-14 09:20:34 -06:00
|
|
|
if val < 0 {
|
2014-12-31 13:18:59 -07:00
|
|
|
return "-" + uitoa(uint(-val))
|
2011-06-14 09:20:34 -06:00
|
|
|
}
|
2014-12-31 13:18:59 -07:00
|
|
|
return uitoa(uint(val))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert unsigned integer to decimal string
|
|
|
|
func uitoa(val uint) string {
|
|
|
|
if val == 0 { // avoid string allocation
|
|
|
|
return "0"
|
|
|
|
}
|
|
|
|
var buf [20]byte // big enough for 64bit value base 10
|
2011-06-14 09:20:34 -06:00
|
|
|
i := len(buf) - 1
|
|
|
|
for val >= 10 {
|
2014-12-31 13:18:59 -07:00
|
|
|
q := val / 10
|
|
|
|
buf[i] = byte('0' + val - q*10)
|
2011-06-14 09:20:34 -06:00
|
|
|
i--
|
2014-12-31 13:18:59 -07:00
|
|
|
val = q
|
2011-06-14 09:20:34 -06:00
|
|
|
}
|
2014-12-31 13:18:59 -07:00
|
|
|
// val < 10
|
|
|
|
buf[i] = byte('0' + val)
|
2011-06-14 09:20:34 -06:00
|
|
|
return string(buf[i:])
|
|
|
|
}
|