Commit 91ee8cde authored by Tobias Klauser's avatar Tobias Klauser Committed by Tobias Klauser

unix: use strings.IndexByte instead of for loops

Change-Id: I8d91f4f959b03f71a8f2effdf7f1c6d1308f2217
Reviewed-on: https://go-review.googlesource.com/102135
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 1e3c7779
...@@ -24,14 +24,14 @@ ...@@ -24,14 +24,14 @@
// holds a value of type syscall.Errno. // holds a value of type syscall.Errno.
package unix // import "golang.org/x/sys/unix" package unix // import "golang.org/x/sys/unix"
import "strings"
// ByteSliceFromString returns a NUL-terminated slice of bytes // ByteSliceFromString returns a NUL-terminated slice of bytes
// containing the text of s. If s contains a NUL byte at any // containing the text of s. If s contains a NUL byte at any
// location, it returns (nil, EINVAL). // location, it returns (nil, EINVAL).
func ByteSliceFromString(s string) ([]byte, error) { func ByteSliceFromString(s string) ([]byte, error) {
for i := 0; i < len(s); i++ { if strings.IndexByte(s, 0) != -1 {
if s[i] == 0 { return nil, EINVAL
return nil, EINVAL
}
} }
a := make([]byte, len(s)+1) a := make([]byte, len(s)+1)
copy(a, s) copy(a, s)
......
...@@ -12,7 +12,10 @@ ...@@ -12,7 +12,10 @@
package unix package unix
import "unsafe" import (
"strings"
"unsafe"
)
// SockaddrDatalink implements the Sockaddr interface for AF_LINK type sockets. // SockaddrDatalink implements the Sockaddr interface for AF_LINK type sockets.
type SockaddrDatalink struct { type SockaddrDatalink struct {
...@@ -134,14 +137,7 @@ func setattrlistTimes(path string, times []Timespec, flags int) error { ...@@ -134,14 +137,7 @@ func setattrlistTimes(path string, times []Timespec, flags int) error {
// Derive extattr namespace and attribute name // Derive extattr namespace and attribute name
func xattrnamespace(fullattr string) (ns int, attr string, err error) { func xattrnamespace(fullattr string) (ns int, attr string, err error) {
s := -1 s := strings.IndexByte(fullattr, '.')
for idx, val := range fullattr {
if val == '.' {
s = idx
break
}
}
if s == -1 { if s == -1 {
return -1, "", ENOATTR return -1, "", ENOATTR
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment