本文整理汇总了Golang中syscall.StringBytePtr函数的典型用法代码示例。如果您正苦于以下问题:Golang StringBytePtr函数的具体用法?Golang StringBytePtr怎么用?Golang StringBytePtr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了StringBytePtr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: setxattr
func setxattr(path string, name string, value *byte, size int) (err error) {
_, _, e1 := syscall.Syscall6(syscall.SYS_SETXATTR,
uintptr(unsafe.Pointer(syscall.StringBytePtr(path))),
uintptr(unsafe.Pointer(syscall.StringBytePtr(name))),
uintptr(unsafe.Pointer(value)), uintptr(size), 0, 0)
return e1
}
示例2: fight
func fight(w1 string, w2 string, rounds int) result {
r := result{}
f2w.Call(
uintptr(unsafe.Pointer(syscall.StringBytePtr(w1))),
uintptr(unsafe.Pointer(syscall.StringBytePtr(w2))),
uintptr(currentConfig.Mars.Coresize),
uintptr(currentConfig.Mars.Cycles),
uintptr(currentConfig.Mars.Maxprocess),
uintptr(rounds),
uintptr(currentConfig.Mars.Maxwarriorlen),
uintptr(currentConfig.Mars.FixedPos),
uintptr(unsafe.Pointer(&r.Win)),
uintptr(unsafe.Pointer(&r.Lose)),
uintptr(unsafe.Pointer(&r.Equal)))
fightMetrics++
roundsMetrics += rounds
if r.Equal+r.Lose+r.Win != rounds {
return result{0, 0, 0}
}
return r
}
示例3: Removexattr
func Removexattr(path string, attr string) (errno int) {
pathbs := syscall.StringBytePtr(path)
attrbs := syscall.StringBytePtr(attr)
_, _, errNo := syscall.Syscall(
syscall.SYS_REMOVEXATTR,
uintptr(unsafe.Pointer(pathbs)),
uintptr(unsafe.Pointer(attrbs)), 0)
return int(errNo)
}
示例4: readdirnames
func (file *File) readdirnames(n int) (names []string, err error) {
if elen == 0 {
var dummy syscall.Dirent
elen = (int(unsafe.Offsetof(dummy.Name)) +
libc_pathconf(syscall.StringBytePtr(file.name), syscall.PC_NAME_MAX) +
1)
}
if file.dirinfo == nil {
file.dirinfo = new(dirInfo)
file.dirinfo.buf = make([]byte, elen)
p := syscall.StringBytePtr(file.name)
syscall.Entersyscall()
r := libc_opendir(p)
syscall.Exitsyscall()
file.dirinfo.dir = r
}
entry_dirent := (*syscall.Dirent)(unsafe.Pointer(&file.dirinfo.buf[0]))
size := n
if size <= 0 {
size = 100
n = -1
}
names = make([]string, 0, size) // Empty with room to grow.
dir := file.dirinfo.dir
if dir == nil {
return names, NewSyscallError("opendir", syscall.GetErrno())
}
for n != 0 {
var result *syscall.Dirent
pr := &result
syscall.Entersyscall()
i := libc_readdir_r(dir, entry_dirent, pr)
syscall.Exitsyscall()
if i != 0 {
return names, NewSyscallError("readdir_r", i)
}
if result == nil {
break // EOF
}
var name = string(result.Name[0:clen(result.Name[0:])])
if name == "." || name == ".." { // Useless names
continue
}
names = append(names, name)
n--
}
if n >= 0 && len(names) == 0 {
return names, io.EOF
}
return names, nil
}
示例5: removexattr
// int removexattr(const char *path, const char *name, int options);
func removexattr(path string, name string) (e error) {
_, _, e1 := syscall.Syscall(syscall.SYS_REMOVEXATTR,
uintptr(unsafe.Pointer(syscall.StringBytePtr(path))),
uintptr(unsafe.Pointer(syscall.StringBytePtr(name))),
0)
if e1 != noError {
e = e1
}
return
}
示例6: getxattr
func getxattr(path string, attr string, dest []byte) (sz int, errno int) {
pathBs := syscall.StringBytePtr(path)
attrBs := syscall.StringBytePtr(attr)
size, _, errNo := syscall.Syscall6(
syscall.SYS_GETXATTR,
uintptr(unsafe.Pointer(pathBs)),
uintptr(unsafe.Pointer(attrBs)),
uintptr(unsafe.Pointer(&dest[0])),
uintptr(len(dest)),
0, 0)
return int(size), int(errNo)
}
示例7: getxattr
// ssize_t getxattr(const char *path, const char *name, void *value, size_t size, u_int32_t position, int options);
func getxattr(path string, name string, value *byte, size int) (resSize int, e error) {
r0, _, e1 := syscall.Syscall6(syscall.SYS_GETXATTR,
uintptr(unsafe.Pointer(syscall.StringBytePtr(path))),
uintptr(unsafe.Pointer(syscall.StringBytePtr(name))),
uintptr(unsafe.Pointer(value)),
uintptr(size), 0, 0)
resSize = int(r0)
if e1 != noError {
e = e1
}
return
}
示例8: getxattr
func getxattr(path string, name string, value *byte, size int) (int, error) {
if r0, _, e1 := syscall.Syscall6(syscall.SYS_GETXATTR,
uintptr(unsafe.Pointer(syscall.StringBytePtr(path))),
uintptr(unsafe.Pointer(syscall.StringBytePtr(name))),
uintptr(unsafe.Pointer(value)), uintptr(size), 0, 0); e1 != syscall.Errno(0) {
if e1 == syscall.ENODATA {
return 0, e1
}
return -1, e1
} else {
return int(r0), nil
}
}
示例9: Setxattr
func Setxattr(path string, attr string, data []byte, flags int) (errno int) {
pathbs := syscall.StringBytePtr(path)
attrbs := syscall.StringBytePtr(attr)
_, _, errNo := syscall.Syscall6(
syscall.SYS_SETXATTR,
uintptr(unsafe.Pointer(pathbs)),
uintptr(unsafe.Pointer(attrbs)),
uintptr(unsafe.Pointer(&data[0])),
uintptr(len(data)),
uintptr(flags), 0)
return int(errNo)
}
示例10: Linkat
func Linkat(fd1 int, n1 string, fd2 int, n2 string) int {
b1 := syscall.StringBytePtr(n1)
b2 := syscall.StringBytePtr(n2)
_, _, errNo := syscall.Syscall6(
syscall.SYS_LINKAT,
uintptr(fd1),
uintptr(unsafe.Pointer(b1)),
uintptr(fd2),
uintptr(unsafe.Pointer(b2)),
0, 0)
return int(errNo)
}
示例11: main
func main() {
if len(os.Args) != 2 {
fmt.Printf("Usage: gogo file.go\n")
return
}
var r0 uintptr
var e1 uintptr
var e int
var fd uint64
var errno uint64
r0, _, e1 = syscall.Syscall(syscall.SYS_OPEN, uintptr(unsafe.Pointer(syscall.StringBytePtr(os.Args[1]))), 0, 0)
e = int(e1)
fd = uint64(r0)
if e == 0 {
ScannerTest(fd)
errno = libgogo.FileClose(fd)
if errno != 0 {
libgogo.ExitError("Error closing file", errno)
}
} else {
fmt.Printf("Error opening file %s.\n", os.Args[1])
}
}
示例12: WglGetProcAddress
func WglGetProcAddress(szProc string) uintptr {
ret, _, _ := procwglGetProcAddress.Call(
uintptr(unsafe.Pointer(syscall.StringBytePtr(szProc))),
)
return ret
}
示例13: Open
// Open opens an asynchronous communications port.
func Open(name string, options ...func(*Term) error) (*Term, error) {
fd, e := syscall.Open(name, syscall.O_NOCTTY|syscall.O_CLOEXEC|syscall.O_NDELAY|syscall.O_RDWR, 0666)
if e != nil {
return nil, &os.PathError{"open", name, e}
}
modules := [2]string{"ptem", "ldterm"}
for _, mod := range modules {
err := unix.IoctlSetInt(fd, C.I_PUSH, int(uintptr(unsafe.Pointer(syscall.StringBytePtr(mod)))))
if err != nil {
return nil, err
}
}
t := Term{name: name, fd: fd}
termios.Tcgetattr(uintptr(t.fd), &t.orig)
if err := termios.Tcgetattr(uintptr(t.fd), &t.orig); err != nil {
return nil, err
}
if err := t.SetOption(options...); err != nil {
return nil, err
}
return &t, syscall.SetNonblock(t.fd, false)
}
示例14: lookupUser
func lookupUser(username string) (*User, error) {
var pwd syscall.Passwd
var result *syscall.Passwd
p := syscall.StringBytePtr(username)
buf := alloc(userBuffer)
defer buf.free()
err := retryWithBuffer(buf, func() syscall.Errno {
syscall.Entersyscall()
rv := libc_getpwnam_r(p,
&pwd,
buf.ptr,
buf.size,
&result)
syscall.Exitsyscall()
if rv != 0 {
return syscall.GetErrno()
}
return 0
})
if err != nil {
return nil, fmt.Errorf("user: lookup username %s: %v", username, err)
}
if result == nil {
return nil, UnknownUserError(username)
}
return buildUser(&pwd), err
}
示例15: lookupGroup
func lookupGroup(groupname string) (*Group, error) {
var grp syscall.Group
var result *syscall.Group
buf := alloc(groupBuffer)
defer buf.free()
p := syscall.StringBytePtr(groupname)
err := retryWithBuffer(buf, func() syscall.Errno {
syscall.Entersyscall()
rv := libc_getgrnam_r(p,
&grp,
buf.ptr,
buf.size,
&result)
syscall.Exitsyscall()
if rv != 0 {
return syscall.GetErrno()
}
return 0
})
if err != nil {
return nil, fmt.Errorf("user: lookup groupname %s: %v", groupname, err)
}
if result == nil {
return nil, UnknownGroupError(groupname)
}
return buildGroup(&grp), nil
}