]> Cypherpunks repositories - gostls13.git/commitdiff
all: add internal/itoa package
authorJosh Bleecher Snyder <josharian@gmail.com>
Sun, 14 Mar 2021 00:52:16 +0000 (16:52 -0800)
committerJosh Bleecher Snyder <josharian@gmail.com>
Sun, 14 Mar 2021 17:56:50 +0000 (17:56 +0000)
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>
32 files changed:
src/go/build/deps_test.go
src/internal/itoa/itoa.go [new file with mode: 0644]
src/internal/itoa/itoa_test.go [new file with mode: 0644]
src/internal/poll/fd_io_plan9.go
src/internal/poll/strconv.go
src/net/dnsclient.go
src/net/dnsclient_unix.go
src/net/interface.go
src/net/interface_plan9.go
src/net/ip.go
src/net/ipsock_plan9.go
src/net/lookup_plan9.go
src/net/parse.go
src/net/tcpsock.go
src/net/tcpsockopt_plan9.go
src/net/udpsock.go
src/os/exec_plan9.go
src/os/exec_posix.go
src/os/executable_plan9.go
src/os/signal/signal_plan9_test.go
src/os/str.go
src/os/tempfile.go
src/syscall/dll_windows.go
src/syscall/exec_linux.go
src/syscall/exec_plan9.go
src/syscall/export_test.go [deleted file]
src/syscall/str.go [deleted file]
src/syscall/syscall_js.go
src/syscall/syscall_linux.go
src/syscall/syscall_test.go
src/syscall/syscall_unix.go
src/syscall/syscall_windows.go

index e05d0aac2e189a0b152db3898c5a2df0b2281dcd..63ef2428b14addeea5e3a706ca18212b56e57b9a 100644 (file)
@@ -83,6 +83,7 @@ var depsRules = `
        # RUNTIME is the core runtime group of packages, all of them very light-weight.
        internal/abi, internal/cpu, unsafe
        < internal/bytealg
+       < internal/itoa
        < internal/unsafeheader
        < runtime/internal/sys
        < runtime/internal/atomic
diff --git a/src/internal/itoa/itoa.go b/src/internal/itoa/itoa.go
new file mode 100644 (file)
index 0000000..c6062d9
--- /dev/null
@@ -0,0 +1,33 @@
+// Copyright 2021 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.
+
+// Simple conversions to avoid depending on strconv.
+
+package itoa
+
+// Itoa converts val to a decimal string.
+func Itoa(val int) string {
+       if val < 0 {
+               return "-" + Uitoa(uint(-val))
+       }
+       return Uitoa(uint(val))
+}
+
+// Uitoa converts val to a 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
+       i := len(buf) - 1
+       for val >= 10 {
+               q := val / 10
+               buf[i] = byte('0' + val - q*10)
+               i--
+               val = q
+       }
+       // val < 10
+       buf[i] = byte('0' + val)
+       return string(buf[i:])
+}
diff --git a/src/internal/itoa/itoa_test.go b/src/internal/itoa/itoa_test.go
new file mode 100644 (file)
index 0000000..71931c1
--- /dev/null
@@ -0,0 +1,40 @@
+// Copyright 2021 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 itoa_test
+
+import (
+       "fmt"
+       "internal/itoa"
+       "math"
+       "testing"
+)
+
+var (
+       minInt64  int64  = math.MinInt64
+       maxInt64  int64  = math.MaxInt64
+       maxUint64 uint64 = math.MaxUint64
+)
+
+func TestItoa(t *testing.T) {
+       tests := []int{int(minInt64), math.MinInt32, -999, -100, -1, 0, 1, 100, 999, math.MaxInt32, int(maxInt64)}
+       for _, tt := range tests {
+               got := itoa.Itoa(tt)
+               want := fmt.Sprint(tt)
+               if want != got {
+                       t.Fatalf("Itoa(%d) = %s, want %s", tt, got, want)
+               }
+       }
+}
+
+func TestUitoa(t *testing.T) {
+       tests := []uint{0, 1, 100, 999, math.MaxUint32, uint(maxUint64)}
+       for _, tt := range tests {
+               got := itoa.Uitoa(tt)
+               want := fmt.Sprint(tt)
+               if want != got {
+                       t.Fatalf("Uitoa(%d) = %s, want %s", tt, got, want)
+               }
+       }
+}
index 287d11bd8c29f6a0bc46225183a669b06c03275e..3205ac8513ee3966f08e2fe177bd0ba927bc057f 100644 (file)
@@ -5,6 +5,7 @@
 package poll
 
 import (
+       "internal/itoa"
        "runtime"
        "sync"
        "syscall"
@@ -71,7 +72,7 @@ func (aio *asyncIO) Cancel() {
        if aio.pid == -1 {
                return
        }
-       f, e := syscall.Open("/proc/"+itoa(aio.pid)+"/note", syscall.O_WRONLY)
+       f, e := syscall.Open("/proc/"+itoa.Itoa(aio.pid)+"/note", syscall.O_WRONLY)
        if e != nil {
                return
        }
index fd5e20f1f40c03d02e5fa5180f5db791d6d34c8e..c98332d3dac63713b4093e31dbcf477a9c3b7266 100644 (file)
@@ -5,36 +5,8 @@
 //go:build plan9
 // +build plan9
 
-// Simple conversions to avoid depending on strconv.
-
 package poll
 
-// Convert integer to decimal string
-func itoa(val int) string {
-       if val < 0 {
-               return "-" + uitoa(uint(-val))
-       }
-       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
-       i := len(buf) - 1
-       for val >= 10 {
-               q := val / 10
-               buf[i] = byte('0' + val - q*10)
-               i--
-               val = q
-       }
-       // val < 10
-       buf[i] = byte('0' + val)
-       return string(buf[i:])
-}
-
 // stringsHasSuffix is strings.HasSuffix. It reports whether s ends in
 // suffix.
 func stringsHasSuffix(s, suffix string) bool {
index e9c73845d78d7eee4bacc8645ec33685f70cc4cb..1bbe39650bbac2f7ec755d8de90c2ccae3845632 100644 (file)
@@ -5,6 +5,7 @@
 package net
 
 import (
+       "internal/itoa"
        "sort"
 
        "golang.org/x/net/dns/dnsmessage"
@@ -33,7 +34,7 @@ func reverseaddr(addr string) (arpa string, err error) {
                return "", &DNSError{Err: "unrecognized address", Name: addr}
        }
        if ip.To4() != nil {
-               return uitoa(uint(ip[15])) + "." + uitoa(uint(ip[14])) + "." + uitoa(uint(ip[13])) + "." + uitoa(uint(ip[12])) + ".in-addr.arpa.", nil
+               return itoa.Uitoa(uint(ip[15])) + "." + itoa.Uitoa(uint(ip[14])) + "." + itoa.Uitoa(uint(ip[13])) + "." + itoa.Uitoa(uint(ip[12])) + ".in-addr.arpa.", nil
        }
        // Must be IPv6
        buf := make([]byte, 0, len(ip)*4+len("ip6.arpa."))
index a3242ff3b2b9e1d18654cdea9784bf5f4347d94a..86f64335ea7ed011def16a3669b707a96c7e5ffb 100644 (file)
@@ -18,6 +18,7 @@ package net
 import (
        "context"
        "errors"
+       "internal/itoa"
        "io"
        "os"
        "sync"
@@ -510,7 +511,7 @@ func (o hostLookupOrder) String() string {
        if s, ok := lookupOrderName[o]; ok {
                return s
        }
-       return "hostLookupOrder=" + itoa(int(o)) + "??"
+       return "hostLookupOrder=" + itoa.Itoa(int(o)) + "??"
 }
 
 // goLookupHost is the native Go implementation of LookupHost.
index 914aaa010f3b98bb270f3455d4b39b454b8d71ca..0e5d3202c911ec1efe8d3b26b25300b9f5cfb1e0 100644 (file)
@@ -6,6 +6,7 @@ package net
 
 import (
        "errors"
+       "internal/itoa"
        "sync"
        "time"
 )
@@ -230,7 +231,7 @@ func (zc *ipv6ZoneCache) name(index int) string {
                zoneCache.RUnlock()
        }
        if !ok { // last resort
-               name = uitoa(uint(index))
+               name = itoa.Uitoa(uint(index))
        }
        return name
 }
index 31bbaca4675c2955acd9f4064b070c9c6827224a..957975c265549211e3a6c11bbd7b19bc730f79c5 100644 (file)
@@ -6,6 +6,7 @@ package net
 
 import (
        "errors"
+       "internal/itoa"
        "os"
 )
 
@@ -38,8 +39,8 @@ func interfaceTable(ifindex int) ([]Interface, error) {
 
 func readInterface(i int) (*Interface, error) {
        ifc := &Interface{
-               Index: i + 1,                        // Offset the index by one to suit the contract
-               Name:  netdir + "/ipifc/" + itoa(i), // Name is the full path to the interface path in plan9
+               Index: i + 1,                             // Offset the index by one to suit the contract
+               Name:  netdir + "/ipifc/" + itoa.Itoa(i), // Name is the full path to the interface path in plan9
        }
 
        ifcstat := ifc.Name + "/status"
index c00fe8ed3cc64f704572996e946ee37f332b5674..18e3f3a2f5f287b172bab54526a6a3e05c290f27 100644 (file)
 
 package net
 
-import "internal/bytealg"
+import (
+       "internal/bytealg"
+       "internal/itoa"
+)
 
 // IP address lengths (bytes).
 const (
@@ -531,7 +534,7 @@ func (n *IPNet) String() string {
        if l == -1 {
                return nn.String() + "/" + m.String()
        }
-       return nn.String() + "/" + uitoa(uint(l))
+       return nn.String() + "/" + itoa.Uitoa(uint(l))
 }
 
 // Parse IPv4 address (d.d.d.d).
index 7a4b7a6041cbf5948209c72087810e8dce4d8d0c..8e984d5e5f314d7cc1cb29697bdde4aec85cefd6 100644 (file)
@@ -7,6 +7,7 @@ package net
 import (
        "context"
        "internal/bytealg"
+       "internal/itoa"
        "io/fs"
        "os"
        "syscall"
@@ -336,9 +337,9 @@ func plan9LocalAddr(addr Addr) string {
                if port == 0 {
                        return ""
                }
-               return itoa(port)
+               return itoa.Itoa(port)
        }
-       return ip.String() + "!" + itoa(port)
+       return ip.String() + "!" + itoa.Itoa(port)
 }
 
 func hangupCtlWrite(ctx context.Context, proto string, ctl *os.File, msg string) error {
index 5fc23f098b7676d3b72dd8981eb3757ce0d94e5f..75c18b33ac06f0eca362200a8909b45bf3ab23c3 100644 (file)
@@ -8,6 +8,7 @@ import (
        "context"
        "errors"
        "internal/bytealg"
+       "internal/itoa"
        "io"
        "os"
 )
@@ -84,7 +85,7 @@ func queryCS1(ctx context.Context, net string, ip IP, port int) (clone, dest str
        if len(ip) != 0 && !ip.IsUnspecified() {
                ips = ip.String()
        }
-       lines, err := queryCS(ctx, net, ips, itoa(port))
+       lines, err := queryCS(ctx, net, ips, itoa.Itoa(port))
        if err != nil {
                return
        }
index cdb35bb826e0edf8f4c446816002fafec05f1b77..6c230ab63fa0c7906a5c80b95f0e2443be5d139f 100644 (file)
@@ -172,32 +172,6 @@ func xtoi2(s string, e byte) (byte, bool) {
        return byte(n), ok && ei == 2
 }
 
-// Convert integer to decimal string.
-func itoa(val int) string {
-       if val < 0 {
-               return "-" + uitoa(uint(-val))
-       }
-       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
-       i := len(buf) - 1
-       for val >= 10 {
-               q := val / 10
-               buf[i] = byte('0' + val - q*10)
-               i--
-               val = q
-       }
-       // val < 10
-       buf[i] = byte('0' + val)
-       return string(buf[i:])
-}
-
 // Convert i to a hexadecimal string. Leading zeros are not printed.
 func appendHex(dst []byte, i uint32) []byte {
        if i == 0 {
index 9a9b03a1e89069920bc6bd174e0331fd48013bb2..19a90143f34861be7efc3ddb6de3a102bef59391 100644 (file)
@@ -6,6 +6,7 @@ package net
 
 import (
        "context"
+       "internal/itoa"
        "io"
        "os"
        "syscall"
@@ -31,9 +32,9 @@ func (a *TCPAddr) String() string {
        }
        ip := ipEmptyString(a.IP)
        if a.Zone != "" {
-               return JoinHostPort(ip+"%"+a.Zone, itoa(a.Port))
+               return JoinHostPort(ip+"%"+a.Zone, itoa.Itoa(a.Port))
        }
-       return JoinHostPort(ip, itoa(a.Port))
+       return JoinHostPort(ip, itoa.Itoa(a.Port))
 }
 
 func (a *TCPAddr) isWildcard() bool {
index fb568718573a6255372bc02205df645585a053b3..264359dcf3daf15bd14c8d82eadafeffcf566dbb 100644 (file)
@@ -7,6 +7,7 @@
 package net
 
 import (
+       "internal/itoa"
        "syscall"
        "time"
 )
@@ -17,7 +18,7 @@ func setNoDelay(fd *netFD, noDelay bool) error {
 
 // Set keep alive period.
 func setKeepAlivePeriod(fd *netFD, d time.Duration) error {
-       cmd := "keepalive " + itoa(int(d/time.Millisecond))
+       cmd := "keepalive " + itoa.Itoa(int(d/time.Millisecond))
        _, e := fd.ctl.WriteAt([]byte(cmd), 0)
        return e
 }
index 571e099abd81c0e60fa5e51a1f79afe90a085b86..bcd0e2763eafe9ec2a0cc064ff332e590b12e46c 100644 (file)
@@ -6,6 +6,7 @@ package net
 
 import (
        "context"
+       "internal/itoa"
        "syscall"
 )
 
@@ -34,9 +35,9 @@ func (a *UDPAddr) String() string {
        }
        ip := ipEmptyString(a.IP)
        if a.Zone != "" {
-               return JoinHostPort(ip+"%"+a.Zone, itoa(a.Port))
+               return JoinHostPort(ip+"%"+a.Zone, itoa.Itoa(a.Port))
        }
-       return JoinHostPort(ip, itoa(a.Port))
+       return JoinHostPort(ip, itoa.Itoa(a.Port))
 }
 
 func (a *UDPAddr) isWildcard() bool {
index 85801539116a2912f85b225c20356cc0493d8853..cc84f976696290ef79b4dfd138ac53ed62c7debe 100644 (file)
@@ -5,6 +5,7 @@
 package os
 
 import (
+       "internal/itoa"
        "runtime"
        "syscall"
        "time"
@@ -40,7 +41,7 @@ func startProcess(name string, argv []string, attr *ProcAttr) (p *Process, err e
 }
 
 func (p *Process) writeProcFile(file string, data string) error {
-       f, e := OpenFile("/proc/"+itoa(p.Pid)+"/"+file, O_WRONLY, 0)
+       f, e := OpenFile("/proc/"+itoa.Itoa(p.Pid)+"/"+file, O_WRONLY, 0)
        if e != nil {
                return e
        }
index 443d4e0218b41cd8251b6a9a14043fe7d9444763..e8736f7c54eaab44bd1d1a812c1d7112077ac48a 100644 (file)
@@ -8,6 +8,7 @@
 package os
 
 import (
+       "internal/itoa"
        "internal/syscall/execenv"
        "runtime"
        "syscall"
@@ -107,14 +108,14 @@ func (p *ProcessState) String() string {
                if runtime.GOOS == "windows" && uint(code) >= 1<<16 { // windows uses large hex numbers
                        res = "exit status " + uitox(uint(code))
                } else { // unix systems use small decimal integers
-                       res = "exit status " + itoa(code) // unix
+                       res = "exit status " + itoa.Itoa(code) // unix
                }
        case status.Signaled():
                res = "signal: " + status.Signal().String()
        case status.Stopped():
                res = "stop signal: " + status.StopSignal().String()
                if status.StopSignal() == syscall.SIGTRAP && status.TrapCause() != 0 {
-                       res += " (trap " + itoa(status.TrapCause()) + ")"
+                       res += " (trap " + itoa.Itoa(status.TrapCause()) + ")"
                }
        case status.Continued():
                res = "continued"
index 105c03f0c1a6bd192c3c81876bff41b646e95795..ad7a4410dcdd03747b656befb5a12c5016535d49 100644 (file)
@@ -7,10 +7,13 @@
 
 package os
 
-import "syscall"
+import (
+       "internal/itoa"
+       "syscall"
+)
 
 func executable() (string, error) {
-       fn := "/proc/" + itoa(Getpid()) + "/text"
+       fn := "/proc/" + itoa.Itoa(Getpid()) + "/text"
        f, err := Open(fn)
        if err != nil {
                return "", err
index 10bfdc3ff10a8bd8570335aaac5f802836a73576..8357199aa4ad64749d70a48eb9b48a2ac41c7f65 100644 (file)
@@ -5,6 +5,7 @@
 package signal
 
 import (
+       "internal/itoa"
        "os"
        "runtime"
        "syscall"
@@ -155,23 +156,8 @@ func TestStop(t *testing.T) {
        }
 }
 
-func itoa(val int) string {
-       if val < 0 {
-               return "-" + itoa(-val)
-       }
-       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:])
-}
-
 func postNote(pid int, note string) error {
-       f, err := os.OpenFile("/proc/"+itoa(pid)+"/note", os.O_WRONLY, 0)
+       f, err := os.OpenFile("/proc/"+itoa.Itoa(pid)+"/note", os.O_WRONLY, 0)
        if err != nil {
                return err
        }
index 9bfcc15aa82b88b232baf30902e5f9c4a0715877..35643e0d2f1bfa98da184063a52b2e2877f56295 100644 (file)
@@ -6,32 +6,6 @@
 
 package os
 
-// itoa converts val (an int) to a decimal string.
-func itoa(val int) string {
-       if val < 0 {
-               return "-" + uitoa(uint(-val))
-       }
-       return uitoa(uint(val))
-}
-
-// uitoa converts val (a uint) to a 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
-       i := len(buf) - 1
-       for val >= 10 {
-               q := val / 10
-               buf[i] = byte('0' + val - q*10)
-               i--
-               val = q
-       }
-       // val < 10
-       buf[i] = byte('0' + val)
-       return string(buf[i:])
-}
-
 // itox converts val (an int) to a hexdecimal string.
 func itox(val int) string {
        if val < 0 {
index 1ad44f1163fa58b90eca41cf9b49d55270cd60da..5b681fcebfea1799decbbd709a6ca6ee304215ef 100644 (file)
@@ -4,7 +4,10 @@
 
 package os
 
-import "errors"
+import (
+       "errors"
+       "internal/itoa"
+)
 
 // fastrand provided by runtime.
 // We generate random temporary file names so that there's a good
@@ -13,7 +16,7 @@ import "errors"
 func fastrand() uint32
 
 func nextRandom() string {
-       return uitoa(uint(fastrand()))
+       return itoa.Uitoa(uint(fastrand()))
 }
 
 // CreateTemp creates a new temporary file in the directory dir,
index d99da000896f74bd17e3f1dfe23bfe8564f84352..16210ca5b58a53d1cd26bec6374b3b17818feb7f 100644 (file)
@@ -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)) + ".")
        }
 }
 
index 6353da40489790fcff81f3e4de32f6410ce9cb31..deb8aa38b704929ad95cc56969f894e3faec9c09 100644 (file)
@@ -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
                }
index 12c4237f69e4e7ed6a8d05257b594c84d276a477..c469fe1812632a9a0d120c4ea4721531ac4ed3f9 100644 (file)
@@ -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 (file)
index 55c09e6..0000000
+++ /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 (file)
index 2ddf04b..0000000
+++ /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:])
-}
index c17c6fcdcf356b0d63886af69e90e55bb45f1493..ed70d622842da2c45106474f14ca0a95388eb442 100644 (file)
@@ -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{}
index 3041f6f8fceda79c0fe34474617361c0d126d8b7..24e051dcbdb7a9c45008a25297293fc0c11d64b4 100644 (file)
 
 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
index 5390f8aace996bbe364c39fa7891371925d143bb..b2b9463b0ffaaef154fdc56c90e64728a6c3fad1 100644 (file)
@@ -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) {
index 40fc8b8a3028050de38b5952a3ce3d4c782a4857..5b405b99b4f23744bb35f308ab1b8b015d3994ee 100644 (file)
@@ -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) {
index 65af6637aefaaff37ff64bae890e5e22a104ba39..f9f78bd2b30efec6aa27aa1dd85cd2038af06ff8 100644 (file)
@@ -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 {