mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-01 22:57:29 -04:00
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: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
committed by
Tobias Klauser
parent
1e3c7779a7
commit
91ee8cde43
+4
-4
@@ -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 @@
|
|||||||
|
|
||||||
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 {
|
|||||||
// 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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user