summaryrefslogtreecommitdiff
path: root/vendor/golang.org/x/sys/windows/syscall.go
diff options
context:
space:
mode:
authordependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>2020-12-09 09:17:32 +0000
committerDaniel J Walsh <dwalsh@redhat.com>2020-12-09 06:05:03 -0500
commit37fbf28d74927b959b36ceade7fde3402ea08e05 (patch)
treed053b6a2fd3e05946bbf71134d80efcb9a8a449c /vendor/golang.org/x/sys/windows/syscall.go
parentdd295f297b6dd51d22c64c75f4ef4f80f953bbde (diff)
downloadpodman-37fbf28d74927b959b36ceade7fde3402ea08e05.tar.gz
podman-37fbf28d74927b959b36ceade7fde3402ea08e05.tar.bz2
podman-37fbf28d74927b959b36ceade7fde3402ea08e05.zip
Bump k8s.io/apimachinery from 0.19.4 to 0.20.0
Bumps [k8s.io/apimachinery](https://github.com/kubernetes/apimachinery) from 0.19.4 to 0.20.0. - [Release notes](https://github.com/kubernetes/apimachinery/releases) - [Commits](https://github.com/kubernetes/apimachinery/compare/v0.19.4...v0.20.0) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'vendor/golang.org/x/sys/windows/syscall.go')
-rw-r--r--vendor/golang.org/x/sys/windows/syscall.go46
1 files changed, 42 insertions, 4 deletions
diff --git a/vendor/golang.org/x/sys/windows/syscall.go b/vendor/golang.org/x/sys/windows/syscall.go
index af828a91b..6122f557a 100644
--- a/vendor/golang.org/x/sys/windows/syscall.go
+++ b/vendor/golang.org/x/sys/windows/syscall.go
@@ -25,17 +25,20 @@
package windows // import "golang.org/x/sys/windows"
import (
+ "bytes"
+ "strings"
"syscall"
+ "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
// location, it returns (nil, syscall.EINVAL).
func ByteSliceFromString(s string) ([]byte, error) {
- for i := 0; i < len(s); i++ {
- if s[i] == 0 {
- return nil, syscall.EINVAL
- }
+ if strings.IndexByte(s, 0) != -1 {
+ return nil, syscall.EINVAL
}
a := make([]byte, len(s)+1)
copy(a, s)
@@ -53,6 +56,41 @@ 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.
// See mksyscall.pl.
var _zero uintptr