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 package process
import ( import (
"bytes"
"encoding/binary" "encoding/binary"
"net" "net"
"path/filepath" "path/filepath"
"syscall" "syscall"
"unsafe" "unsafe"
"golang.org/x/sys/unix"
) )
const ( const (
@ -94,12 +95,8 @@ func getExecPathFromPID(pid uint32) (string, error) {
if errno != 0 { if errno != 0 {
return "", errno 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 { func readNativeUint32(b []byte) uint32 {