-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathutil.go
30 lines (24 loc) · 795 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package dpdk
/*
#cgo CFLAGS: -m64 -pthread -O3 -march=native -I/usr/local/include/dpdk
#cgo LDFLAGS: -L/usr/local/lib -ldpdk -lz -lrt -lm -ldl -lfuse
#include <rte_config.h>
#include <rte_malloc.h>
#include <rte_errno.h>
*/
import "C"
import "unsafe"
func GetCArray(n uint) *unsafe.Pointer {
var p *unsafe.Pointer
arr := C.rte_malloc((*C.char)(nil), C.size_t(n)*C.size_t(unsafe.Sizeof(p)), C.unsigned(0))
return (*unsafe.Pointer)(arr)
}
func SliceFromCArray(arr *unsafe.Pointer, n uint) []unsafe.Pointer {
return (*[1 << 30](unsafe.Pointer))(unsafe.Pointer(arr))[:n:n]
}
func ElemFromCArray(arr *unsafe.Pointer, n uint) unsafe.Pointer {
return (*[1 << 30](unsafe.Pointer))(unsafe.Pointer(arr))[n]
}
func StrError(errno int) string {
return C.GoString(C.rte_strerror(C.int(errno)))
}