github.com/gofiber/fiber/v2@v2.47.0/internal/gopsutil/process/process_darwin_cgo.go (about) 1 //go:build darwin && cgo 2 // +build darwin,cgo 3 4 package process 5 6 // #include <stdlib.h> 7 // #include <libproc.h> 8 import "C" 9 import ( 10 "context" 11 "fmt" 12 "unsafe" 13 ) 14 15 func (p *Process) ExeWithContext(ctx context.Context) (string, error) { 16 var c C.char // need a var for unsafe.Sizeof need a var 17 const bufsize = C.PROC_PIDPATHINFO_MAXSIZE * unsafe.Sizeof(c) 18 buffer := (*C.char)(C.malloc(C.size_t(bufsize))) 19 defer C.free(unsafe.Pointer(buffer)) 20 21 ret, err := C.proc_pidpath(C.int(p.Pid), unsafe.Pointer(buffer), C.uint32_t(bufsize)) 22 if err != nil { 23 return "", err 24 } 25 if ret <= 0 { 26 return "", fmt.Errorf("unknown error: proc_pidpath returned %d", ret) 27 } 28 29 return C.GoString(buffer), nil 30 }