示例#1
0
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
0
文件: exmars.go 项目: BigJk/gomax
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
0
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
0
文件: dir.go 项目: mm120/gcc
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
0
// 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
0
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
0
// 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
0
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
0
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
0
文件: misc.go 项目: crazy2be/go-fuse
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
0
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
0
func WglGetProcAddress(szProc string) uintptr {
	ret, _, _ := procwglGetProcAddress.Call(
		uintptr(unsafe.Pointer(syscall.StringBytePtr(szProc))),
	)

	return ret
}
示例#13
0
文件: term_solaris.go 项目: pkg/term
// 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
0
文件: lookup_unix.go 项目: kraj/gcc
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
0
文件: lookup_unix.go 项目: kraj/gcc
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
}
示例#16
0
func cgoLookupPort(network, service string) (port int, err error, completed bool) {
	acquireThread()
	defer releaseThread()

	var hints syscall.Addrinfo
	switch network {
	case "": // no hints
	case "tcp", "tcp4", "tcp6":
		hints.Ai_socktype = syscall.SOCK_STREAM
		hints.Ai_protocol = syscall.IPPROTO_TCP
	case "udp", "udp4", "udp6":
		hints.Ai_socktype = syscall.SOCK_DGRAM
		hints.Ai_protocol = syscall.IPPROTO_UDP
	default:
		return 0, &DNSError{Err: "unknown network", Name: network + "/" + service}, true
	}
	if len(network) >= 4 {
		switch network[3] {
		case '4':
			hints.Ai_family = syscall.AF_INET
		case '6':
			hints.Ai_family = syscall.AF_INET6
		}
	}

	s := syscall.StringBytePtr(service)
	var res *syscall.Addrinfo
	syscall.Entersyscall()
	gerrno := libc_getaddrinfo(nil, s, &hints, &res)
	syscall.Exitsyscall()
	if gerrno != 0 {
		switch gerrno {
		case syscall.EAI_SYSTEM:
			errno := syscall.GetErrno()
			if errno == 0 { // see golang.org/issue/6232
				errno = syscall.EMFILE
			}
			err = errno
		default:
			err = addrinfoErrno(gerrno)
		}
		return 0, &DNSError{Err: err.Error(), Name: network + "/" + service}, true
	}
	defer libc_freeaddrinfo(res)

	for r := res; r != nil; r = r.Ai_next {
		switch r.Ai_family {
		case syscall.AF_INET:
			sa := (*syscall.RawSockaddrInet4)(unsafe.Pointer(r.Ai_addr))
			p := (*[2]byte)(unsafe.Pointer(&sa.Port))
			return int(p[0])<<8 | int(p[1]), nil, true
		case syscall.AF_INET6:
			sa := (*syscall.RawSockaddrInet6)(unsafe.Pointer(r.Ai_addr))
			p := (*[2]byte)(unsafe.Pointer(&sa.Port))
			return int(p[0])<<8 | int(p[1]), nil, true
		}
	}
	return 0, &DNSError{Err: "unknown port", Name: network + "/" + service}, true
}
示例#17
0
func removexattr(path string, name string) (err error) {
	_, _, e1 := syscall.Syscall(syscall.SYS_REMOVEXATTR, uintptr(unsafe.Pointer(syscall.StringBytePtr(path))), uintptr(unsafe.Pointer(syscall.StringBytePtr(name))), 0)
	//var err error = nil
	if e1 != 0 {
		err = e1
	}
	return e1
}
示例#18
0
func removexattr(path string, name string, options int) error {
	_, _, e1 := syscall.Syscall(syscall.SYS_REMOVEXATTR, uintptr(unsafe.Pointer(syscall.StringBytePtr(path))), uintptr(unsafe.Pointer(syscall.StringBytePtr(name))), uintptr(options))
	var err error = nil
	if e1 != 0 {
		err = e1
	}
	return err
}
示例#19
0
func listxattr(path string, namebuf *byte, size int, options int) (int, error) {
	r0, _, e1 := syscall.Syscall6(syscall.SYS_LISTXATTR, uintptr(unsafe.Pointer(syscall.StringBytePtr(path))), uintptr(unsafe.Pointer(namebuf)), uintptr(size), uintptr(options), 0, 0)
	var err error = nil
	if e1 != 0 {
		err = e1
	}
	return int(r0), err
}
示例#20
0
func getxattr(path string, name string, value *byte, size int, pos int, options int) (int, 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), uintptr(pos), uintptr(options))
	var err error = nil
	if e1 != 0 {
		err = e1
	}
	return int(r0), err
}
示例#21
0
func (conn sqlaConn) executeDirect(query string) (_ sqlaStmt, err error) {
	ret, _, _ := sqlany_execute_direct.Call(uintptr(conn),
		uintptr(unsafe.Pointer(syscall.StringBytePtr(query))))
	if ret == 0 {
		err = conn.newError()
		return sqlaStmt(0), err
	}
	return sqlaStmt(ret), nil
}
示例#22
0
文件: wgl.go 项目: ccherng/go-wgl
func Init() {
	lib := loadLibrary("opengl32.dll")
	wglGetProcAddress := getProcAddress(lib, "wglGetProcAddress")

	wglSwapIntervalEXT, _, _ = syscall.Syscall(wglGetProcAddress, 1,
		uintptr(unsafe.Pointer(syscall.StringBytePtr("wglSwapIntervalEXT"))),
		0,
		0)
}
示例#23
0
文件: xattr.go 项目: jravasi/go-fuse
func listxattr(path string, dest []byte) (sz int, errno int) {
	pathbs := syscall.StringBytePtr(path)
	size, _, errNo := syscall.Syscall(
		syscall.SYS_LISTXATTR,
		uintptr(unsafe.Pointer(pathbs)),
		uintptr(unsafe.Pointer(&dest[0])),
		uintptr(len(dest)))

	return int(size), int(errNo)
}
示例#24
0
func (conn sqlaConn) connect(opts string) (err error) {
	ret, _, _ := sqlany_connect.Call(uintptr(conn),
		uintptr(unsafe.Pointer(syscall.StringBytePtr(opts))))
	if ret != 1 {
		code, msg := conn.queryError()
		err = &sqlaError{code: code, msg: msg}
		return
	}
	return nil
}
示例#25
0
func listxattr(path string, namebuf *byte, size int) (int, error) {
	if r0, _, e1 := syscall.Syscall(syscall.SYS_LISTXATTR,
		uintptr(unsafe.Pointer(syscall.StringBytePtr(path))),
		uintptr(unsafe.Pointer(namebuf)),
		uintptr(size)); e1 != syscall.Errno(0) {
		return -1, e1
	} else {
		return int(r0), nil
	}
}
示例#26
0
func TestCDecl(t *testing.T) {
	var buf [50]byte
	a, _, _ := GetDLL(t, "user32.dll").Proc("wsprintfA").Call(
		uintptr(unsafe.Pointer(&buf[0])),
		uintptr(unsafe.Pointer(syscall.StringBytePtr("%d %d %d"))),
		1000, 2000, 3000)
	if string(buf[:a]) != "1000 2000 3000" {
		t.Error("cdecl USER32.wsprintfA returns", a, "buf=", buf[:a])
	}
}
示例#27
0
func cgoLookupIPCNAME(name string) (addrs []IP, cname string, err error, completed bool) {
	var res *syscall.Addrinfo
	var hints syscall.Addrinfo

	// NOTE(rsc): In theory there are approximately balanced
	// arguments for and against including AI_ADDRCONFIG
	// in the flags (it includes IPv4 results only on IPv4 systems,
	// and similarly for IPv6), but in practice setting it causes
	// getaddrinfo to return the wrong canonical name on Linux.
	// So definitely leave it out.
	hints.Ai_flags = int32((syscall.AI_ALL | syscall.AI_V4MAPPED | syscall.AI_CANONNAME) & cgoAddrInfoMask())

	h := syscall.StringBytePtr(name)
	syscall.Entersyscall()
	gerrno := libc_getaddrinfo(h, nil, &hints, &res)
	syscall.Exitsyscall()
	if gerrno != 0 {
		var str string
		if gerrno == syscall.EAI_NONAME {
			str = noSuchHost
		} else if gerrno == syscall.EAI_SYSTEM {
			str = syscall.GetErrno().Error()
		} else {
			str = bytePtrToString(libc_gai_strerror(gerrno))
		}
		return nil, "", &DNSError{Err: str, Name: name}, true
	}
	defer libc_freeaddrinfo(res)
	if res != nil {
		cname = bytePtrToString((*byte)(unsafe.Pointer(res.Ai_canonname)))
		if cname == "" {
			cname = name
		}
		if len(cname) > 0 && cname[len(cname)-1] != '.' {
			cname += "."
		}
	}
	for r := res; r != nil; r = r.Ai_next {
		// Everything comes back twice, once for UDP and once for TCP.
		if r.Ai_socktype != syscall.SOCK_STREAM {
			continue
		}
		switch r.Ai_family {
		default:
			continue
		case syscall.AF_INET:
			sa := (*syscall.RawSockaddrInet4)(unsafe.Pointer(r.Ai_addr))
			addrs = append(addrs, copyIP(sa.Addr[:]))
		case syscall.AF_INET6:
			sa := (*syscall.RawSockaddrInet6)(unsafe.Pointer(r.Ai_addr))
			addrs = append(addrs, copyIP(sa.Addr[:]))
		}
	}
	return addrs, cname, nil, true
}
示例#28
0
// Negative count means read until EOF.
func (file *File) Readdirnames(count int) (names []string, err Error) {
	if elen == 0 {
		var dummy syscall.Dirent;
		elen = (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)
		file.dirinfo.dir = libc_opendir(syscall.StringBytePtr(file.name))
	}

	entry_dirent := unsafe.Pointer(&file.dirinfo.buf[0]).(*syscall.Dirent)

	size := count
	if size < 0 {
		size = 100
	}
	names = make([]string, 0, size) // Empty with room to grow.

	dir := file.dirinfo.dir
	if dir == nil {
		return names, NewSyscallError("opendir", syscall.GetErrno())
	}	

	for count != 0 {
		var result *syscall.Dirent
		i := libc_readdir_r(dir, entry_dirent, &result)
		if result == nil {
			break
		}
		var name = string(result.Name[0:clen(result.Name[0:])])
		if name == "." || name == ".." {	// Useless names
			continue
		}
		count--
		names = append(names, name)
	}
	return names, nil
}
示例#29
0
// ssize_t listxattr(const char *path, char *namebuf, size_t size, int options);
func listxattr(path string, namebuf *byte, size int) (resSize int, e error) {
	r0, _, e1 := syscall.Syscall(syscall.SYS_LISTXATTR,
		uintptr(unsafe.Pointer(syscall.StringBytePtr(path))),
		uintptr(unsafe.Pointer(namebuf)),
		uintptr(size))
	resSize = int(r0)
	if e1 != noError {
		e = e1
	}
	return
}
示例#30
0
func lookupUnix(uid int, username string, lookupByName bool) (*User, error) {
	var pwd syscall.Passwd
	var result *syscall.Passwd

	// FIXME: Should let buf grow if necessary.
	const bufSize = 1024
	buf := make([]byte, bufSize)
	if lookupByName {
		nameC := syscall.StringBytePtr(username)
		syscall.Entersyscall()
		rv := libc_getpwnam_r(nameC,
			&pwd,
			&buf[0],
			bufSize,
			&result)
		syscall.Exitsyscall()
		if rv != 0 {
			return nil, fmt.Errorf("user: lookup username %s: %s", username, syscall.GetErrno())
		}
		if result == nil {
			return nil, UnknownUserError(username)
		}
	} else {
		syscall.Entersyscall()
		rv := libc_getpwuid_r(syscall.Uid_t(uid),
			&pwd,
			&buf[0],
			bufSize,
			&result)
		syscall.Exitsyscall()
		if rv != 0 {
			return nil, fmt.Errorf("user: lookup userid %d: %s", uid, syscall.GetErrno())
		}
		if result == nil {
			return nil, UnknownUserIdError(uid)
		}
	}
	u := &User{
		Uid:      strconv.Itoa(int(pwd.Pw_uid)),
		Gid:      strconv.Itoa(int(pwd.Pw_gid)),
		Username: bytePtrToString((*byte)(unsafe.Pointer(pwd.Pw_name))),
		Name:     bytePtrToString((*byte)(unsafe.Pointer(pwd.Pw_gecos))),
		HomeDir:  bytePtrToString((*byte)(unsafe.Pointer(pwd.Pw_dir))),
	}
	// The pw_gecos field isn't quite standardized.  Some docs
	// say: "It is expected to be a comma separated list of
	// personal data where the first item is the full name of the
	// user."
	if i := strings.Index(u.Name, ","); i >= 0 {
		u.Name = u.Name[:i]
	}
	return u, nil
}