From d48e67d0026122f55f22f0df396e7a51d2b20fb9 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 24 Aug 2022 14:23:53 +0200 Subject: [PATCH] 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 Reviewed-by: Ian Lance Taylor Run-TryBot: Tobias Klauser Reviewed-by: Heschi Kreinick --- unix/export_test.go | 10 ---------- unix/str.go | 27 --------------------------- unix/syscall_linux.go | 3 ++- unix/syscall_test.go | 17 ----------------- 4 files changed, 2 insertions(+), 55 deletions(-) delete mode 100644 unix/export_test.go delete mode 100644 unix/str.go diff --git a/unix/export_test.go b/unix/export_test.go deleted file mode 100644 index a2bf67dee..000000000 --- a/unix/export_test.go +++ /dev/null @@ -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 diff --git a/unix/str.go b/unix/str.go deleted file mode 100644 index 8ba89ed86..000000000 --- a/unix/str.go +++ /dev/null @@ -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:]) -} diff --git a/unix/syscall_linux.go b/unix/syscall_linux.go index ecb0f27fb..eecb58d74 100644 --- a/unix/syscall_linux.go +++ b/unix/syscall_linux.go @@ -13,6 +13,7 @@ package unix import ( "encoding/binary" + "strconv" "syscall" "time" "unsafe" @@ -233,7 +234,7 @@ func Futimesat(dirfd int, path string, tv []Timeval) error { func Futimes(fd int, tv []Timeval) (err error) { // Believe it or not, this is the best we can do on Linux // (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 diff --git a/unix/syscall_test.go b/unix/syscall_test.go index 7f80134a2..bc2a08837 100644 --- a/unix/syscall_test.go +++ b/unix/syscall_test.go @@ -8,7 +8,6 @@ package unix_test import ( - "fmt" "testing" "golang.org/x/sys/unix" @@ -34,22 +33,6 @@ func TestEnv(t *testing.T) { 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) { var utsname unix.Utsname err := unix.Uname(&utsname)