1 Star 0 Fork 0

陈慧颖 / gooid

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
properties.go 759 Bytes
一键复制 编辑 原始数据 按行查看 历史
gooid 提交于 2018-11-20 23:05 . init gooid
package app
/*
#include <stdlib.h>
#include <sys/system_properties.h>
*/
import "C"
import (
"unsafe"
)
const (
PROP_NAME_MAX = C.PROP_NAME_MAX
PROP_VALUE_MAX = C.PROP_VALUE_MAX
)
func PropGet(k string) string {
var value [PROP_VALUE_MAX]C.char
key := C.CString(k)
defer C.free(unsafe.Pointer(key))
n := C.__system_property_get((*C.char)(key), &value[0])
if n > 0 {
return C.GoString(&value[0])
}
return ""
}
func PropVisit(cb func(k, v string)) {
var name [PROP_NAME_MAX]C.char
var value [PROP_VALUE_MAX]C.char
var pi *C.prop_info
for n := 0; ; n++ {
pi = C.__system_property_find_nth(C.uint(n))
if pi == nil {
break
}
C.__system_property_read(pi, &name[0], &value[0])
cb(C.GoString(&name[0]), C.GoString(&value[0]))
}
}
1
https://gitee.com/githubchy/gooid.git
git@gitee.com:githubchy/gooid.git
githubchy
gooid
gooid
2c72341a60e5

搜索帮助

14c37bed 8189591 565d56ea 8189591