From c35cb24bdacf66cd65af508f48323a647882ef08 Mon Sep 17 00:00:00 2001 From: Dreamacro <8615343+Dreamacro@users.noreply.github.com> Date: Tue, 15 Jun 2021 21:03:47 +0800 Subject: [PATCH] Chore: use unix.ByteSliceToString transform cstring --- component/process/process_darwin.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/component/process/process_darwin.go b/component/process/process_darwin.go index 5157b209..7e4baf74 100644 --- a/component/process/process_darwin.go +++ b/component/process/process_darwin.go @@ -1,12 +1,13 @@ package process import ( - "bytes" "encoding/binary" "net" "path/filepath" "syscall" "unsafe" + + "golang.org/x/sys/unix" ) const ( @@ -94,12 +95,8 @@ func getExecPathFromPID(pid uint32) (string, error) { if errno != 0 { return "", errno } - firstZero := bytes.IndexByte(buf, 0) - if firstZero <= 0 { - return "", nil - } - return filepath.Base(string(buf[:firstZero])), nil + return filepath.Base(unix.ByteSliceToString(buf)), nil } func readNativeUint32(b []byte) uint32 {