mirror of
				https://gitea.com/Lydanne/buildx.git
				synced 2025-11-01 00:23:56 +08:00 
			
		
		
		
	Use golang.org/x/sys/execabs
Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
		
							
								
								
									
										49
									
								
								vendor/golang.org/x/sys/plan9/syscall.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										49
									
								
								vendor/golang.org/x/sys/plan9/syscall.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -24,16 +24,20 @@ | ||||
| // holds a value of type syscall.ErrorString. | ||||
| package plan9 // import "golang.org/x/sys/plan9" | ||||
|  | ||||
| import "unsafe" | ||||
| 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 | ||||
| // 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) | ||||
| @@ -51,6 +55,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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Tibor Vass
					Tibor Vass