diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-12-09 08:12:16 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-09 08:12:16 -0500 |
commit | 247260081a5cdc4065009bcd1080c987974327e5 (patch) | |
tree | 278f2fb67adb161afb39e3fcbc1105abfa532deb /vendor/golang.org/x/sys/unix/syscall.go | |
parent | 3aad9024b6d59bb9f73e7da07c25ba3e1b52954a (diff) | |
parent | 37fbf28d74927b959b36ceade7fde3402ea08e05 (diff) | |
download | podman-247260081a5cdc4065009bcd1080c987974327e5.tar.gz podman-247260081a5cdc4065009bcd1080c987974327e5.tar.bz2 podman-247260081a5cdc4065009bcd1080c987974327e5.zip |
Merge pull request #8656 from containers/dependabot/go_modules/k8s.io/apimachinery-0.20.0
Bump k8s.io/apimachinery from 0.19.4 to 0.20.0
Diffstat (limited to 'vendor/golang.org/x/sys/unix/syscall.go')
-rw-r--r-- | vendor/golang.org/x/sys/unix/syscall.go | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/vendor/golang.org/x/sys/unix/syscall.go b/vendor/golang.org/x/sys/unix/syscall.go index fd4ee8ebe..ab75ef9cc 100644 --- a/vendor/golang.org/x/sys/unix/syscall.go +++ b/vendor/golang.org/x/sys/unix/syscall.go @@ -24,7 +24,13 @@ // holds a value of type syscall.Errno. package unix // import "golang.org/x/sys/unix" -import "strings" +import ( + "bytes" + "strings" + "unsafe" + + "golang.org/x/sys/internal/unsafeheader" +) // ByteSliceFromString returns a NUL-terminated slice of bytes // containing the text of s. If s contains a NUL byte at any @@ -49,5 +55,40 @@ func BytePtrFromString(s string) (*byte, error) { return &a[0], nil } +// ByteSliceToString returns a string form of the text represented by the slice s, with a terminating NUL and any +// bytes after the NUL removed. +func ByteSliceToString(s []byte) string { + if i := bytes.IndexByte(s, 0); i != -1 { + s = s[:i] + } + return string(s) +} + +// BytePtrToString takes a pointer to a sequence of text and returns the corresponding string. +// If the pointer is nil, it returns the empty string. It assumes that the text sequence is terminated +// at a zero byte; if the zero byte is not present, the program may crash. +func BytePtrToString(p *byte) string { + if p == nil { + return "" + } + if *p == 0 { + return "" + } + + // Find NUL terminator. + n := 0 + for ptr := unsafe.Pointer(p); *(*byte)(ptr) != 0; n++ { + ptr = unsafe.Pointer(uintptr(ptr) + 1) + } + + var s []byte + h := (*unsafeheader.Slice)(unsafe.Pointer(&s)) + h.Data = unsafe.Pointer(p) + h.Len = n + h.Cap = n + + return string(s) +} + // Single-word zero for use when we need a valid pointer to 0 bytes. var _zero uintptr |