aboutsummaryrefslogtreecommitdiff
path: root/src/syscall
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2021-03-13 16:52:16 -0800
committerJosh Bleecher Snyder <josharian@gmail.com>2021-03-14 17:56:50 +0000
commit061a6903a232cb868780b1e724a75bf92a728489 (patch)
treee8dc88c37a5e79e1aa138dffbeb70439543ee54c /src/syscall
parent88b8a1608987d494f3f29618e7524e61712c31ba (diff)
downloadgo-061a6903a232cb868780b1e724a75bf92a728489.tar.gz
go-061a6903a232cb868780b1e724a75bf92a728489.zip
all: add internal/itoa package
This replaces five implementations scattered across low level packages. (And I plan to use it in a sixth soon.) Three of the five were byte-for-byte identical. Change-Id: I3bbbeeac63723a487986c912b604e10ad1e042f4 Reviewed-on: https://go-review.googlesource.com/c/go/+/301549 Trust: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Diffstat (limited to 'src/syscall')
-rw-r--r--src/syscall/dll_windows.go3
-rw-r--r--src/syscall/exec_linux.go9
-rw-r--r--src/syscall/exec_plan9.go3
-rw-r--r--src/syscall/export_test.go7
-rw-r--r--src/syscall/str.go24
-rw-r--r--src/syscall/syscall_js.go5
-rw-r--r--src/syscall/syscall_linux.go7
-rw-r--r--src/syscall/syscall_test.go17
-rw-r--r--src/syscall/syscall_unix.go5
-rw-r--r--src/syscall/syscall_windows.go5
10 files changed, 23 insertions, 62 deletions
diff --git a/src/syscall/dll_windows.go b/src/syscall/dll_windows.go
index d99da00089..16210ca5b5 100644
--- a/src/syscall/dll_windows.go
+++ b/src/syscall/dll_windows.go
@@ -5,6 +5,7 @@
package syscall
import (
+ "internal/itoa"
"internal/syscall/windows/sysdll"
"sync"
"sync/atomic"
@@ -215,7 +216,7 @@ func (p *Proc) Call(a ...uintptr) (r1, r2 uintptr, lastErr error) {
case 18:
return Syscall18(p.Addr(), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15], a[16], a[17])
default:
- panic("Call " + p.Name + " with too many arguments " + itoa(len(a)) + ".")
+ panic("Call " + p.Name + " with too many arguments " + itoa.Itoa(len(a)) + ".")
}
}
diff --git a/src/syscall/exec_linux.go b/src/syscall/exec_linux.go
index 6353da4048..deb8aa38b7 100644
--- a/src/syscall/exec_linux.go
+++ b/src/syscall/exec_linux.go
@@ -8,6 +8,7 @@
package syscall
import (
+ "internal/itoa"
"runtime"
"unsafe"
)
@@ -568,7 +569,7 @@ func forkExecPipe(p []int) (err error) {
func formatIDMappings(idMap []SysProcIDMap) []byte {
var data []byte
for _, im := range idMap {
- data = append(data, []byte(itoa(im.ContainerID)+" "+itoa(im.HostID)+" "+itoa(im.Size)+"\n")...)
+ data = append(data, []byte(itoa.Itoa(im.ContainerID)+" "+itoa.Itoa(im.HostID)+" "+itoa.Itoa(im.Size)+"\n")...)
}
return data
}
@@ -597,7 +598,7 @@ func writeIDMappings(path string, idMap []SysProcIDMap) error {
// This is needed since kernel 3.19, because you can't write gid_map without
// disabling setgroups() system call.
func writeSetgroups(pid int, enable bool) error {
- sgf := "/proc/" + itoa(pid) + "/setgroups"
+ sgf := "/proc/" + itoa.Itoa(pid) + "/setgroups"
fd, err := Open(sgf, O_RDWR, 0)
if err != nil {
return err
@@ -622,7 +623,7 @@ func writeSetgroups(pid int, enable bool) error {
// for a process and it is called from the parent process.
func writeUidGidMappings(pid int, sys *SysProcAttr) error {
if sys.UidMappings != nil {
- uidf := "/proc/" + itoa(pid) + "/uid_map"
+ uidf := "/proc/" + itoa.Itoa(pid) + "/uid_map"
if err := writeIDMappings(uidf, sys.UidMappings); err != nil {
return err
}
@@ -633,7 +634,7 @@ func writeUidGidMappings(pid int, sys *SysProcAttr) error {
if err := writeSetgroups(pid, sys.GidMappingsEnableSetgroups); err != nil && err != ENOENT {
return err
}
- gidf := "/proc/" + itoa(pid) + "/gid_map"
+ gidf := "/proc/" + itoa.Itoa(pid) + "/gid_map"
if err := writeIDMappings(gidf, sys.GidMappings); err != nil {
return err
}
diff --git a/src/syscall/exec_plan9.go b/src/syscall/exec_plan9.go
index 12c4237f69..c469fe1812 100644
--- a/src/syscall/exec_plan9.go
+++ b/src/syscall/exec_plan9.go
@@ -7,6 +7,7 @@
package syscall
import (
+ "internal/itoa"
"runtime"
"sync"
"unsafe"
@@ -320,7 +321,7 @@ func cexecPipe(p []int) error {
return e
}
- fd, e := Open("#d/"+itoa(p[1]), O_RDWR|O_CLOEXEC)
+ fd, e := Open("#d/"+itoa.Itoa(p[1]), O_RDWR|O_CLOEXEC)
if e != nil {
Close(p[0])
Close(p[1])
diff --git a/src/syscall/export_test.go b/src/syscall/export_test.go
deleted file mode 100644
index 55c09e667e..0000000000
--- a/src/syscall/export_test.go
+++ /dev/null
@@ -1,7 +0,0 @@
-// Copyright 2014 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.
-
-package syscall
-
-var Itoa = itoa
diff --git a/src/syscall/str.go b/src/syscall/str.go
deleted file mode 100644
index 2ddf04b227..0000000000
--- a/src/syscall/str.go
+++ /dev/null
@@ -1,24 +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.
-
-package syscall
-
-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/src/syscall/syscall_js.go b/src/syscall/syscall_js.go
index c17c6fcdcf..ed70d62284 100644
--- a/src/syscall/syscall_js.go
+++ b/src/syscall/syscall_js.go
@@ -8,6 +8,7 @@
package syscall
import (
+ "internal/itoa"
"internal/oserror"
"sync"
"unsafe"
@@ -60,7 +61,7 @@ func (e Errno) Error() string {
return s
}
}
- return "errno " + itoa(int(e))
+ return "errno " + itoa.Itoa(int(e))
}
func (e Errno) Is(target error) bool {
@@ -106,7 +107,7 @@ func (s Signal) String() string {
return str
}
}
- return "signal " + itoa(int(s))
+ return "signal " + itoa.Itoa(int(s))
}
var signals = [...]string{}
diff --git a/src/syscall/syscall_linux.go b/src/syscall/syscall_linux.go
index 3041f6f8fc..24e051dcbd 100644
--- a/src/syscall/syscall_linux.go
+++ b/src/syscall/syscall_linux.go
@@ -11,7 +11,10 @@
package syscall
-import "unsafe"
+import (
+ "internal/itoa"
+ "unsafe"
+)
func rawSyscallNoError(trap, a1, a2, a3 uintptr) (r1, r2 uintptr)
@@ -225,7 +228,7 @@ func Futimesat(dirfd int, path string, 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
// (and is what glibc does).
- return Utimes("/proc/self/fd/"+itoa(fd), tv)
+ return Utimes("/proc/self/fd/"+itoa.Itoa(fd), tv)
}
const ImplementsGetwd = true
diff --git a/src/syscall/syscall_test.go b/src/syscall/syscall_test.go
index 5390f8aace..b2b9463b0f 100644
--- a/src/syscall/syscall_test.go
+++ b/src/syscall/syscall_test.go
@@ -5,7 +5,6 @@
package syscall_test
import (
- "fmt"
"internal/testenv"
"os"
"runtime"
@@ -33,22 +32,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 := syscall.Itoa(i)
- f := fmt.Sprint(i)
- if s != f {
- t.Fatalf("itoa(%d) = %s, want %s", i, s, f)
- }
-}
-
// Check that permuting child process fds doesn't interfere with
// reporting of fork/exec status. See Issue 14979.
func TestExecErrPermutedFds(t *testing.T) {
diff --git a/src/syscall/syscall_unix.go b/src/syscall/syscall_unix.go
index 40fc8b8a30..5b405b99b4 100644
--- a/src/syscall/syscall_unix.go
+++ b/src/syscall/syscall_unix.go
@@ -8,6 +8,7 @@
package syscall
import (
+ "internal/itoa"
"internal/oserror"
"internal/race"
"internal/unsafeheader"
@@ -121,7 +122,7 @@ func (e Errno) Error() string {
return s
}
}
- return "errno " + itoa(int(e))
+ return "errno " + itoa.Itoa(int(e))
}
func (e Errno) Is(target error) bool {
@@ -181,7 +182,7 @@ func (s Signal) String() string {
return str
}
}
- return "signal " + itoa(int(s))
+ return "signal " + itoa.Itoa(int(s))
}
func Read(fd int, p []byte) (n int, err error) {
diff --git a/src/syscall/syscall_windows.go b/src/syscall/syscall_windows.go
index 65af6637ae..f9f78bd2b3 100644
--- a/src/syscall/syscall_windows.go
+++ b/src/syscall/syscall_windows.go
@@ -8,6 +8,7 @@ package syscall
import (
errorspkg "errors"
+ "internal/itoa"
"internal/oserror"
"internal/race"
"internal/unsafeheader"
@@ -132,7 +133,7 @@ func (e Errno) Error() string {
if err != nil {
n, err = formatMessage(flags, 0, uint32(e), 0, b, nil)
if err != nil {
- return "winapi error #" + itoa(int(e))
+ return "winapi error #" + itoa.Itoa(int(e))
}
}
// trim terminating \r and \n
@@ -1152,7 +1153,7 @@ func (s Signal) String() string {
return str
}
}
- return "signal " + itoa(int(s))
+ return "signal " + itoa.Itoa(int(s))
}
func LoadCreateSymbolicLink() error {