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 @@
// holds a value of type syscall.Errno.
package unix // import "golang.org/x/sys/unix"
import "strings"
// ByteSliceFromString returns a NUL-terminated slice of bytes
// containing the text of s. If s contains a NUL byte at any
// location, it returns (nil, EINVAL).
func ByteSliceFromString(s string) ([]byte, error) {
for i := 0; i < len(s); i++ {
if s[i] == 0 {
return nil, EINVAL
}
if strings.IndexByte(s, 0) != -1 {
return nil, EINVAL
}
a := make([]byte, len(s)+1)
copy(a, s)
......
......@@ -12,7 +12,10 @@
package unix
import "unsafe"
import (
"strings"
"unsafe"
)
// SockaddrDatalink implements the Sockaddr interface for AF_LINK type sockets.
type SockaddrDatalink struct {
......@@ -134,14 +137,7 @@ func setattrlistTimes(path string, times []Timespec, flags int) error {
// Derive extattr namespace and attribute name
func xattrnamespace(fullattr string) (ns int, attr string, err error) {
s := -1
for idx, val := range fullattr {
if val == '.' {
s = idx
break
}
}
s := strings.IndexByte(fullattr, '.')
if s == -1 {
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