github.com/criyle/go-sandbox@v0.10.3/pkg/forkexec/sandbox_load_darwin.go (about) 1 package forkexec 2 3 import ( 4 "errors" 5 "os" 6 "syscall" 7 "unsafe" 8 ) 9 10 func goString(b *byte) string { 11 l := 0 12 sb := (*[1 << 20]byte)(unsafe.Pointer(b)) 13 for sb[l] > 0 { 14 l++ 15 } 16 return string(sb[: l-1 : l-1]) 17 } 18 19 // SandboxLoadProfile loads profile by sandbox_init 20 func SandboxLoadProfile(profile string) (err error) { 21 var errBuf *byte 22 p, err := syscall.BytePtrFromString(profile) 23 if err != nil { 24 return 25 } 26 if err := SandboxInit(p, 0, &errBuf); err != nil { 27 defer SandboxFreeError(errBuf) 28 if errBuf != nil { 29 s := goString(errBuf) 30 return os.NewSyscallError("sandbox_init", errors.New(s)) 31 } 32 return os.NewSyscallError("sandbox_init", err) 33 } 34 return 35 }