mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-02 15:17:31 -04:00
unix: use strconv.Itoa instead of local implementation
This was originally copied over from package syscall where it was replaced by internal/itoa in CL 301549. For golang.org/x/sys/unix we may import strconv, so use strconv.Itoa instead. Change-Id: Iac125fbd0f64c385f9f0c02d4a7af762364b67aa Reviewed-on: https://go-review.googlesource.com/c/sys/+/425304 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
committed by
Tobias Klauser
parent
2c41d75977
commit
d48e67d002
@@ -1,10 +0,0 @@
|
|||||||
// Copyright 2015 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.
|
|
||||||
|
|
||||||
//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
|
|
||||||
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
|
|
||||||
|
|
||||||
package unix
|
|
||||||
|
|
||||||
var Itoa = itoa
|
|
||||||
-27
@@ -1,27 +0,0 @@
|
|||||||
// 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.
|
|
||||||
|
|
||||||
//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
|
|
||||||
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
|
|
||||||
|
|
||||||
package unix
|
|
||||||
|
|
||||||
func itoa(val int) string { // do it here rather than with fmt to avoid dependency
|
|
||||||
if val < 0 {
|
|
||||||
return "-" + uitoa(uint(-val))
|
|
||||||
}
|
|
||||||
return uitoa(uint(val))
|
|
||||||
}
|
|
||||||
|
|
||||||
func uitoa(val uint) string {
|
|
||||||
var buf [32]byte // big enough for int64
|
|
||||||
i := len(buf) - 1
|
|
||||||
for val >= 10 {
|
|
||||||
buf[i] = byte(val%10 + '0')
|
|
||||||
i--
|
|
||||||
val /= 10
|
|
||||||
}
|
|
||||||
buf[i] = byte(val + '0')
|
|
||||||
return string(buf[i:])
|
|
||||||
}
|
|
||||||
@@ -13,6 +13,7 @@ package unix
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"strconv"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
@@ -233,7 +234,7 @@ func Futimesat(dirfd int, path string, tv []Timeval) error {
|
|||||||
func Futimes(fd int, tv []Timeval) (err error) {
|
func Futimes(fd int, tv []Timeval) (err error) {
|
||||||
// Believe it or not, this is the best we can do on Linux
|
// Believe it or not, this is the best we can do on Linux
|
||||||
// (and is what glibc does).
|
// (and is what glibc does).
|
||||||
return Utimes("/proc/self/fd/"+itoa(fd), tv)
|
return Utimes("/proc/self/fd/"+strconv.Itoa(fd), tv)
|
||||||
}
|
}
|
||||||
|
|
||||||
const ImplementsGetwd = true
|
const ImplementsGetwd = true
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
package unix_test
|
package unix_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
@@ -34,22 +33,6 @@ func TestEnv(t *testing.T) {
|
|||||||
testSetGetenv(t, "TESTENV", "")
|
testSetGetenv(t, "TESTENV", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestItoa(t *testing.T) {
|
|
||||||
// Make most negative integer: 0x8000...
|
|
||||||
i := 1
|
|
||||||
for i<<1 != 0 {
|
|
||||||
i <<= 1
|
|
||||||
}
|
|
||||||
if i >= 0 {
|
|
||||||
t.Fatal("bad math")
|
|
||||||
}
|
|
||||||
s := unix.Itoa(i)
|
|
||||||
f := fmt.Sprint(i)
|
|
||||||
if s != f {
|
|
||||||
t.Fatalf("itoa(%d) = %s, want %s", i, s, f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestUname(t *testing.T) {
|
func TestUname(t *testing.T) {
|
||||||
var utsname unix.Utsname
|
var utsname unix.Utsname
|
||||||
err := unix.Uname(&utsname)
|
err := unix.Uname(&utsname)
|
||||||
|
|||||||
Reference in New Issue
Block a user