Chore: use unix.ByteSliceToString transform cstring

This commit is contained in:
Dreamacro 2021-06-15 21:03:47 +08:00
parent b6ff08074c
commit c35cb24bda

View file

@ -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 {