Mercurial > yakumo_izuru > aya
comparison vendor/golang.org/x/sys/unix/syscall.go @ 68:4b79810863f6 draft
Ready to release 0.6.0
Signed-off-by: Izuru Yakumo <yakumo.izuru@chaotic.ninja>
author | yakumo.izuru |
---|---|
date | Wed, 13 Sep 2023 10:49:50 +0000 |
parents | 787b5ee0289d |
children |
comparison
equal
deleted
inserted
replaced
67:4edfa07d5fe0 | 68:4b79810863f6 |
---|---|
27 | 27 |
28 import ( | 28 import ( |
29 "bytes" | 29 "bytes" |
30 "strings" | 30 "strings" |
31 "unsafe" | 31 "unsafe" |
32 | |
33 "golang.org/x/sys/internal/unsafeheader" | |
34 ) | 32 ) |
35 | 33 |
36 // ByteSliceFromString returns a NUL-terminated slice of bytes | 34 // ByteSliceFromString returns a NUL-terminated slice of bytes |
37 // containing the text of s. If s contains a NUL byte at any | 35 // containing the text of s. If s contains a NUL byte at any |
38 // location, it returns (nil, EINVAL). | 36 // location, it returns (nil, EINVAL). |
80 n := 0 | 78 n := 0 |
81 for ptr := unsafe.Pointer(p); *(*byte)(ptr) != 0; n++ { | 79 for ptr := unsafe.Pointer(p); *(*byte)(ptr) != 0; n++ { |
82 ptr = unsafe.Pointer(uintptr(ptr) + 1) | 80 ptr = unsafe.Pointer(uintptr(ptr) + 1) |
83 } | 81 } |
84 | 82 |
85 var s []byte | 83 return string(unsafe.Slice(p, n)) |
86 h := (*unsafeheader.Slice)(unsafe.Pointer(&s)) | |
87 h.Data = unsafe.Pointer(p) | |
88 h.Len = n | |
89 h.Cap = n | |
90 | |
91 return string(s) | |
92 } | 84 } |
93 | 85 |
94 // Single-word zero for use when we need a valid pointer to 0 bytes. | 86 // Single-word zero for use when we need a valid pointer to 0 bytes. |
95 var _zero uintptr | 87 var _zero uintptr |