chore(deps): Update sqlite dependencies
This commit is contained in:
893
vendor/modernc.org/libc/libc_linux.go
generated
vendored
893
vendor/modernc.org/libc/libc_linux.go
generated
vendored
@ -5,7 +5,6 @@
|
||||
package libc // import "modernc.org/libc"
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"os"
|
||||
@ -13,23 +12,20 @@ import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
guuid "github.com/google/uuid"
|
||||
"golang.org/x/sys/unix"
|
||||
"modernc.org/libc/errno"
|
||||
"modernc.org/libc/fcntl"
|
||||
"modernc.org/libc/fts"
|
||||
"modernc.org/libc/grp"
|
||||
gonetdb "modernc.org/libc/honnef.co/go/netdb"
|
||||
"modernc.org/libc/langinfo"
|
||||
"modernc.org/libc/limits"
|
||||
"modernc.org/libc/netdb"
|
||||
"modernc.org/libc/netinet/in"
|
||||
"modernc.org/libc/pwd"
|
||||
"modernc.org/libc/signal"
|
||||
"modernc.org/libc/stdio"
|
||||
"modernc.org/libc/sys/socket"
|
||||
@ -38,6 +34,7 @@ import (
|
||||
"modernc.org/libc/termios"
|
||||
ctime "modernc.org/libc/time"
|
||||
"modernc.org/libc/unistd"
|
||||
"modernc.org/libc/uuid/uuid"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -71,6 +68,7 @@ func newFile(t *TLS, fd int32) uintptr {
|
||||
if p == 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
file(p).setFd(fd)
|
||||
return p
|
||||
}
|
||||
@ -108,46 +106,6 @@ func Xgetrusage(t *TLS, who int32, usage uintptr) int32 {
|
||||
return 0
|
||||
}
|
||||
|
||||
// char *fgets(char *s, int size, FILE *stream);
|
||||
func Xfgets(t *TLS, s uintptr, size int32, stream uintptr) uintptr {
|
||||
fd := int((*stdio.FILE)(unsafe.Pointer(stream)).F_fileno)
|
||||
var b []byte
|
||||
buf := [1]byte{}
|
||||
for ; size > 0; size-- {
|
||||
n, err := unix.Read(fd, buf[:])
|
||||
if n != 0 {
|
||||
b = append(b, buf[0])
|
||||
if buf[0] == '\n' {
|
||||
b = append(b, 0)
|
||||
copy((*RawMem)(unsafe.Pointer(s))[:len(b):len(b)], b)
|
||||
return s
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
switch {
|
||||
case n == 0 && err == nil && len(b) == 0:
|
||||
return 0
|
||||
default:
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
// if err == nil {
|
||||
// panic("internal error")
|
||||
// }
|
||||
|
||||
// if len(b) != 0 {
|
||||
// b = append(b, 0)
|
||||
// copy((*RawMem)(unsafe.Pointer(s)[:len(b)]), b)
|
||||
// return s
|
||||
// }
|
||||
|
||||
// t.setErrno(err)
|
||||
}
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
// int lstat(const char *pathname, struct stat *statbuf);
|
||||
func Xlstat(t *TLS, pathname, statbuf uintptr) int32 {
|
||||
return Xlstat64(t, pathname, statbuf)
|
||||
@ -243,6 +201,18 @@ func Xopen64(t *TLS, pathname uintptr, flags int32, args uintptr) int32 {
|
||||
return int32(n)
|
||||
}
|
||||
|
||||
// int openat(int dirfd, const char *pathname, int flags, mode_t mode);
|
||||
func Xopenat(t *TLS, dirfd int32, pathname uintptr, flags int32, mode types.Mode_t) int32 {
|
||||
// From golang.org/x/sys/unix/zsyscall_linux.go
|
||||
fd, _, err := unix.Syscall6(unix.SYS_OPENAT, uintptr(dirfd), pathname, uintptr(flags), uintptr(mode), 0, 0)
|
||||
if err != 0 {
|
||||
t.setErrno(err)
|
||||
return -1
|
||||
}
|
||||
|
||||
return int32(fd)
|
||||
}
|
||||
|
||||
// off_t lseek(int fd, off_t offset, int whence);
|
||||
func Xlseek(t *TLS, fd int32, offset types.Off_t, whence int32) types.Off_t {
|
||||
return types.Off_t(Xlseek64(t, fd, offset, whence))
|
||||
@ -290,6 +260,8 @@ func Xsysconf(t *TLS, name int32) long {
|
||||
return -1
|
||||
case unistd.X_SC_GETGR_R_SIZE_MAX:
|
||||
return -1
|
||||
case unistd.X_SC_NPROCESSORS_ONLN:
|
||||
return long(runtime.NumCPU())
|
||||
}
|
||||
|
||||
panic(todo("", name))
|
||||
@ -390,6 +362,29 @@ func Xfchmod(t *TLS, fd int32, mode types.Mode_t) int32 {
|
||||
return 0
|
||||
}
|
||||
|
||||
// int fchmodat(int dirfd, const char *pathname, mode_t mode, int flags);
|
||||
func Xfchmodat(t *TLS, dirfd int32, pathname uintptr, mode types.Mode_t, flags int32) int32 {
|
||||
// From golang.org/x/sys/unix/syscall_linux.go
|
||||
// Linux fchmodat doesn't support the flags parameter. Mimick glibc's behavior
|
||||
// and check the flags. Otherwise the mode would be applied to the symlink
|
||||
// destination which is not what the user expects.
|
||||
if flags&^unix.AT_SYMLINK_NOFOLLOW != 0 {
|
||||
t.setErrno(unix.EINVAL)
|
||||
return -1
|
||||
} else if flags&unix.AT_SYMLINK_NOFOLLOW != 0 {
|
||||
t.setErrno(unix.EOPNOTSUPP)
|
||||
return -1
|
||||
}
|
||||
|
||||
// From golang.org/x/sys/unix/zsyscall_linux.go
|
||||
if _, _, err := unix.Syscall(unix.SYS_FCHMODAT, uintptr(dirfd), pathname, uintptr(mode)); err != 0 {
|
||||
t.setErrno(err)
|
||||
return -1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
// int fchown(int fd, uid_t owner, gid_t group);
|
||||
func Xfchown(t *TLS, fd int32, owner types.Uid_t, group types.Gid_t) int32 {
|
||||
if _, _, err := unix.Syscall(unix.SYS_FCHOWN, uintptr(fd), uintptr(owner), uintptr(group)); err != 0 {
|
||||
@ -689,281 +684,6 @@ func Xsystem(t *TLS, command uintptr) int32 {
|
||||
return 0
|
||||
}
|
||||
|
||||
var staticGetpwuid pwd.Passwd
|
||||
|
||||
func init() {
|
||||
atExit = append(atExit, func() { closePasswd(&staticGetpwuid) })
|
||||
}
|
||||
|
||||
func closePasswd(p *pwd.Passwd) {
|
||||
Xfree(nil, p.Fpw_name)
|
||||
Xfree(nil, p.Fpw_passwd)
|
||||
Xfree(nil, p.Fpw_gecos)
|
||||
Xfree(nil, p.Fpw_dir)
|
||||
Xfree(nil, p.Fpw_shell)
|
||||
*p = pwd.Passwd{}
|
||||
}
|
||||
|
||||
// struct passwd *getpwuid(uid_t uid);
|
||||
func Xgetpwuid(t *TLS, uid uint32) uintptr {
|
||||
f, err := os.Open("/etc/passwd")
|
||||
if err != nil {
|
||||
panic(todo("", err))
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
|
||||
sid := strconv.Itoa(int(uid))
|
||||
sc := bufio.NewScanner(f)
|
||||
for sc.Scan() {
|
||||
// eg. "root:x:0:0:root:/root:/bin/bash"
|
||||
a := strings.Split(sc.Text(), ":")
|
||||
if len(a) < 7 {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
if a[2] == sid {
|
||||
uid, err := strconv.Atoi(a[2])
|
||||
if err != nil {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
gid, err := strconv.Atoi(a[3])
|
||||
if err != nil {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
closePasswd(&staticGetpwuid)
|
||||
gecos := a[4]
|
||||
if strings.Contains(gecos, ",") {
|
||||
a := strings.Split(gecos, ",")
|
||||
gecos = a[0]
|
||||
}
|
||||
initPasswd(t, &staticGetpwuid, a[0], a[1], uint32(uid), uint32(gid), gecos, a[5], a[6])
|
||||
return uintptr(unsafe.Pointer(&staticGetpwuid))
|
||||
}
|
||||
}
|
||||
|
||||
if sc.Err() != nil {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
func initPasswd(t *TLS, p *pwd.Passwd, name, pwd string, uid, gid uint32, gecos, dir, shell string) {
|
||||
p.Fpw_name = cString(t, name)
|
||||
p.Fpw_passwd = cString(t, pwd)
|
||||
p.Fpw_uid = uid
|
||||
p.Fpw_gid = gid
|
||||
p.Fpw_gecos = cString(t, gecos)
|
||||
p.Fpw_dir = cString(t, dir)
|
||||
p.Fpw_shell = cString(t, shell)
|
||||
}
|
||||
|
||||
func initPasswd2(t *TLS, buf uintptr, buflen types.Size_t, p *pwd.Passwd, name, pwd string, uid, gid uint32, gecos, dir, shell string) bool {
|
||||
p.Fpw_name, buf, buflen = bufString(buf, buflen, name)
|
||||
if buf == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
p.Fpw_passwd, buf, buflen = bufString(buf, buflen, pwd)
|
||||
if buf == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
p.Fpw_uid = uid
|
||||
p.Fpw_gid = gid
|
||||
if buf == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
p.Fpw_gecos, buf, buflen = bufString(buf, buflen, gecos)
|
||||
if buf == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
p.Fpw_dir, buf, buflen = bufString(buf, buflen, dir)
|
||||
if buf == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
p.Fpw_shell, buf, buflen = bufString(buf, buflen, shell)
|
||||
if buf == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func bufString(buf uintptr, buflen types.Size_t, s string) (uintptr, uintptr, types.Size_t) {
|
||||
buf0 := buf
|
||||
rq := len(s) + 1
|
||||
if rq > int(buflen) {
|
||||
return 0, 0, 0
|
||||
}
|
||||
|
||||
copy((*RawMem)(unsafe.Pointer(buf))[:len(s):len(s)], s)
|
||||
buf += uintptr(len(s))
|
||||
*(*byte)(unsafe.Pointer(buf)) = 0
|
||||
return buf0, buf + 1, buflen - types.Size_t(rq)
|
||||
}
|
||||
|
||||
// int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf, size_t buflen, struct passwd **result);
|
||||
func Xgetpwuid_r(t *TLS, uid types.Uid_t, cpwd, buf uintptr, buflen types.Size_t, result uintptr) int32 {
|
||||
f, err := os.Open("/etc/passwd")
|
||||
if err != nil {
|
||||
panic(todo("", err))
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
|
||||
sid := strconv.Itoa(int(uid))
|
||||
sc := bufio.NewScanner(f)
|
||||
for sc.Scan() {
|
||||
// eg. "root:x:0:0:root:/root:/bin/bash"
|
||||
a := strings.Split(sc.Text(), ":")
|
||||
if len(a) < 7 {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
if a[2] == sid {
|
||||
uid, err := strconv.Atoi(a[2])
|
||||
if err != nil {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
gid, err := strconv.Atoi(a[3])
|
||||
if err != nil {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
gecos := a[4]
|
||||
if strings.Contains(gecos, ",") {
|
||||
a := strings.Split(gecos, ",")
|
||||
gecos = a[0]
|
||||
}
|
||||
var v pwd.Passwd
|
||||
if initPasswd2(t, buf, buflen, &v, a[0], a[1], uint32(uid), uint32(gid), gecos, a[5], a[6]) {
|
||||
*(*pwd.Passwd)(unsafe.Pointer(cpwd)) = v
|
||||
*(*uintptr)(unsafe.Pointer(result)) = cpwd
|
||||
return 0
|
||||
}
|
||||
|
||||
*(*uintptr)(unsafe.Pointer(result)) = 0
|
||||
return errno.ERANGE
|
||||
}
|
||||
}
|
||||
|
||||
if sc.Err() != nil {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
*(*uintptr)(unsafe.Pointer(result)) = 0
|
||||
return 0
|
||||
}
|
||||
|
||||
// struct passwd *getpwnam(const char *name);
|
||||
func Xgetpwnam(t *TLS, name uintptr) uintptr {
|
||||
f, err := os.Open("/etc/passwd")
|
||||
if err != nil {
|
||||
panic(todo("", err))
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
|
||||
sname := GoString(name)
|
||||
sc := bufio.NewScanner(f)
|
||||
for sc.Scan() {
|
||||
// eg. "root:x:0:0:root:/root:/bin/bash"
|
||||
a := strings.Split(sc.Text(), ":")
|
||||
if len(a) < 7 {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
if a[0] == sname {
|
||||
uid, err := strconv.Atoi(a[2])
|
||||
if err != nil {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
gid, err := strconv.Atoi(a[3])
|
||||
if err != nil {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
closePasswd(&staticGetpwnam)
|
||||
gecos := a[4]
|
||||
if strings.Contains(gecos, ",") {
|
||||
a := strings.Split(gecos, ",")
|
||||
gecos = a[0]
|
||||
}
|
||||
initPasswd(t, &staticGetpwnam, a[0], a[1], uint32(uid), uint32(gid), gecos, a[5], a[6])
|
||||
return uintptr(unsafe.Pointer(&staticGetpwnam))
|
||||
}
|
||||
}
|
||||
|
||||
if sc.Err() != nil {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
// int getpwnam_r(char *name, struct passwd *pwd, char *buf, size_t buflen, struct passwd **result);
|
||||
func Xgetpwnam_r(t *TLS, name, cpwd, buf uintptr, buflen types.Size_t, result uintptr) int32 {
|
||||
f, err := os.Open("/etc/passwd")
|
||||
if err != nil {
|
||||
panic(todo("", err))
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
|
||||
sname := GoString(name)
|
||||
sc := bufio.NewScanner(f)
|
||||
for sc.Scan() {
|
||||
// eg. "root:x:0:0:root:/root:/bin/bash"
|
||||
a := strings.Split(sc.Text(), ":")
|
||||
if len(a) < 7 {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
if a[0] == sname {
|
||||
uid, err := strconv.Atoi(a[2])
|
||||
if err != nil {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
gid, err := strconv.Atoi(a[3])
|
||||
if err != nil {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
gecos := a[4]
|
||||
if strings.Contains(gecos, ",") {
|
||||
a := strings.Split(gecos, ",")
|
||||
gecos = a[0]
|
||||
}
|
||||
var v pwd.Passwd
|
||||
if initPasswd2(t, buf, buflen, &v, a[0], a[1], uint32(uid), uint32(gid), gecos, a[5], a[6]) {
|
||||
*(*pwd.Passwd)(unsafe.Pointer(cpwd)) = v
|
||||
*(*uintptr)(unsafe.Pointer(result)) = cpwd
|
||||
return 0
|
||||
}
|
||||
|
||||
*(*uintptr)(unsafe.Pointer(result)) = 0
|
||||
return errno.ERANGE
|
||||
}
|
||||
}
|
||||
|
||||
if sc.Err() != nil {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
*(*uintptr)(unsafe.Pointer(result)) = 0
|
||||
return 0
|
||||
}
|
||||
|
||||
// int setvbuf(FILE *stream, char *buf, int mode, size_t size);
|
||||
func Xsetvbuf(t *TLS, stream, buf uintptr, mode int32, size types.Size_t) int32 {
|
||||
return 0 //TODO
|
||||
@ -999,292 +719,6 @@ func Xfileno(t *TLS, stream uintptr) int32 {
|
||||
return -1
|
||||
}
|
||||
|
||||
var staticGetpwnam pwd.Passwd
|
||||
|
||||
func init() {
|
||||
atExit = append(atExit, func() { closePasswd(&staticGetpwnam) })
|
||||
}
|
||||
|
||||
var staticGetgrnam grp.Group
|
||||
|
||||
func init() {
|
||||
atExit = append(atExit, func() { closeGroup(&staticGetgrnam) })
|
||||
}
|
||||
|
||||
// struct group *getgrnam(const char *name);
|
||||
func Xgetgrnam(t *TLS, name uintptr) uintptr {
|
||||
f, err := os.Open("/etc/group")
|
||||
if err != nil {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
|
||||
sname := GoString(name)
|
||||
sc := bufio.NewScanner(f)
|
||||
for sc.Scan() {
|
||||
// eg. "root:x:0:"
|
||||
a := strings.Split(sc.Text(), ":")
|
||||
if len(a) < 4 {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
if a[0] == sname {
|
||||
closeGroup(&staticGetgrnam)
|
||||
gid, err := strconv.Atoi(a[2])
|
||||
if err != nil {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
var names []string
|
||||
if a[3] != "" {
|
||||
names = strings.Split(a[3], ",")
|
||||
}
|
||||
initGroup(t, &staticGetgrnam, a[0], a[1], uint32(gid), names)
|
||||
return uintptr(unsafe.Pointer(&staticGetgrnam))
|
||||
}
|
||||
}
|
||||
|
||||
if sc.Err() != nil {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
// int getgrnam_r(const char *name, struct group *grp, char *buf, size_t buflen, struct group **result);
|
||||
func Xgetgrnam_r(t *TLS, name, pGrp, buf uintptr, buflen types.Size_t, result uintptr) int32 {
|
||||
f, err := os.Open("/etc/group")
|
||||
if err != nil {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
|
||||
sname := GoString(name)
|
||||
sc := bufio.NewScanner(f)
|
||||
for sc.Scan() {
|
||||
// eg. "root:x:0:"
|
||||
a := strings.Split(sc.Text(), ":")
|
||||
if len(a) < 4 {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
if a[0] == sname {
|
||||
gid, err := strconv.Atoi(a[2])
|
||||
if err != nil {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
var names []string
|
||||
if a[3] != "" {
|
||||
names = strings.Split(a[3], ",")
|
||||
}
|
||||
var x grp.Group
|
||||
if initGroup2(buf, buflen, &x, a[0], a[1], uint32(gid), names) {
|
||||
*(*grp.Group)(unsafe.Pointer(pGrp)) = x
|
||||
*(*uintptr)(unsafe.Pointer(result)) = pGrp
|
||||
return 0
|
||||
}
|
||||
|
||||
*(*uintptr)(unsafe.Pointer(result)) = 0
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
if sc.Err() != nil {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
*(*uintptr)(unsafe.Pointer(result)) = 0
|
||||
return 0
|
||||
}
|
||||
|
||||
func closeGroup(p *grp.Group) {
|
||||
Xfree(nil, p.Fgr_name)
|
||||
Xfree(nil, p.Fgr_passwd)
|
||||
if p := p.Fgr_mem; p != 0 {
|
||||
for {
|
||||
q := *(*uintptr)(unsafe.Pointer(p))
|
||||
if q == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
Xfree(nil, q)
|
||||
p += unsafe.Sizeof(uintptr(0))
|
||||
}
|
||||
}
|
||||
*p = grp.Group{}
|
||||
}
|
||||
|
||||
func initGroup(t *TLS, p *grp.Group, name, pwd string, gid uint32, names []string) {
|
||||
p.Fgr_name = cString(t, name)
|
||||
p.Fgr_passwd = cString(t, pwd)
|
||||
p.Fgr_gid = gid
|
||||
a := Xcalloc(t, 1, types.Size_t(unsafe.Sizeof(uintptr(0)))*types.Size_t((len(names)+1)))
|
||||
if a == 0 {
|
||||
panic("OOM")
|
||||
}
|
||||
|
||||
for p := a; len(names) != 0; p += unsafe.Sizeof(uintptr(0)) {
|
||||
*(*uintptr)(unsafe.Pointer(p)) = cString(t, names[0])
|
||||
names = names[1:]
|
||||
}
|
||||
p.Fgr_mem = a
|
||||
}
|
||||
|
||||
func initGroup2(buf uintptr, buflen types.Size_t, p *grp.Group, name, pwd string, gid uint32, names []string) bool {
|
||||
p.Fgr_name, buf, buflen = bufString(buf, buflen, name)
|
||||
if buf == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
p.Fgr_passwd, buf, buflen = bufString(buf, buflen, pwd)
|
||||
if buf == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
p.Fgr_gid = gid
|
||||
rq := unsafe.Sizeof(uintptr(0)) * uintptr(len(names)+1)
|
||||
if rq > uintptr(buflen) {
|
||||
return false
|
||||
}
|
||||
|
||||
a := buf
|
||||
buf += rq
|
||||
for ; len(names) != 0; buf += unsafe.Sizeof(uintptr(0)) {
|
||||
if len(names[0])+1 > int(buflen) {
|
||||
return false
|
||||
}
|
||||
|
||||
*(*uintptr)(unsafe.Pointer(buf)), buf, buflen = bufString(buf, buflen, names[0])
|
||||
names = names[1:]
|
||||
}
|
||||
*(*uintptr)(unsafe.Pointer(buf)) = 0
|
||||
p.Fgr_mem = a
|
||||
return true
|
||||
}
|
||||
|
||||
func init() {
|
||||
atExit = append(atExit, func() { closeGroup(&staticGetgrgid) })
|
||||
}
|
||||
|
||||
var staticGetgrgid grp.Group
|
||||
|
||||
// struct group *getgrgid(gid_t gid);
|
||||
func Xgetgrgid(t *TLS, gid uint32) uintptr {
|
||||
f, err := os.Open("/etc/group")
|
||||
if err != nil {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
|
||||
sid := strconv.Itoa(int(gid))
|
||||
sc := bufio.NewScanner(f)
|
||||
for sc.Scan() {
|
||||
// eg. "root:x:0:"
|
||||
a := strings.Split(sc.Text(), ":")
|
||||
if len(a) < 4 {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
if a[2] == sid {
|
||||
closeGroup(&staticGetgrgid)
|
||||
var names []string
|
||||
if a[3] != "" {
|
||||
names = strings.Split(a[3], ",")
|
||||
}
|
||||
initGroup(t, &staticGetgrgid, a[0], a[1], gid, names)
|
||||
return uintptr(unsafe.Pointer(&staticGetgrgid))
|
||||
}
|
||||
}
|
||||
|
||||
if sc.Err() != nil {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
// int getgrgid_r(gid_t gid, struct group *grp, char *buf, size_t buflen, struct group **result);
|
||||
func Xgetgrgid_r(t *TLS, gid uint32, pGrp, buf uintptr, buflen types.Size_t, result uintptr) int32 {
|
||||
f, err := os.Open("/etc/group")
|
||||
if err != nil {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
|
||||
sid := strconv.Itoa(int(gid))
|
||||
sc := bufio.NewScanner(f)
|
||||
for sc.Scan() {
|
||||
// eg. "root:x:0:"
|
||||
a := strings.Split(sc.Text(), ":")
|
||||
if len(a) < 4 {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
if a[2] == sid {
|
||||
var names []string
|
||||
if a[3] != "" {
|
||||
names = strings.Split(a[3], ",")
|
||||
}
|
||||
var x grp.Group
|
||||
if initGroup2(buf, buflen, &x, a[0], a[1], gid, names) {
|
||||
*(*grp.Group)(unsafe.Pointer(pGrp)) = x
|
||||
*(*uintptr)(unsafe.Pointer(result)) = pGrp
|
||||
return 0
|
||||
}
|
||||
|
||||
*(*uintptr)(unsafe.Pointer(result)) = 0
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
if sc.Err() != nil {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
*(*uintptr)(unsafe.Pointer(result)) = 0
|
||||
return 0
|
||||
}
|
||||
|
||||
// int mkstemps(char *template, int suffixlen);
|
||||
func Xmkstemps(t *TLS, template uintptr, suffixlen int32) int32 {
|
||||
return Xmkstemps64(t, template, suffixlen)
|
||||
}
|
||||
|
||||
// int mkstemps(char *template, int suffixlen);
|
||||
func Xmkstemps64(t *TLS, template uintptr, suffixlen int32) int32 {
|
||||
len := uintptr(Xstrlen(t, template))
|
||||
x := template + uintptr(len-6) - uintptr(suffixlen)
|
||||
for i := uintptr(0); i < 6; i++ {
|
||||
if *(*byte)(unsafe.Pointer(x + i)) != 'X' {
|
||||
t.setErrno(errno.EINVAL)
|
||||
return -1
|
||||
}
|
||||
}
|
||||
|
||||
fd, err := tempFile(template, x)
|
||||
if err != 0 {
|
||||
t.setErrno(err)
|
||||
return -1
|
||||
}
|
||||
|
||||
return int32(fd)
|
||||
}
|
||||
|
||||
// int mkstemp(char *template);
|
||||
func Xmkstemp(t *TLS, template uintptr) int32 {
|
||||
return Xmkstemp64(t, template)
|
||||
}
|
||||
|
||||
// int mkstemp(char *template);
|
||||
func Xmkstemp64(t *TLS, template uintptr) int32 {
|
||||
return Xmkstemps64(t, template, 0)
|
||||
}
|
||||
|
||||
func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscall.Errno) (r *fts.FTSENT) {
|
||||
var statp uintptr
|
||||
if stat != nil {
|
||||
@ -1497,7 +931,7 @@ func Xstrerror(t *TLS, errnum int32) uintptr {
|
||||
|
||||
// void *dlopen(const char *filename, int flags);
|
||||
func Xdlopen(t *TLS, filename uintptr, flags int32) uintptr {
|
||||
panic(todo(""))
|
||||
panic(todo("%q", GoString(filename)))
|
||||
}
|
||||
|
||||
// char *dlerror(void);
|
||||
@ -1725,16 +1159,6 @@ func Xferror(t *TLS, stream uintptr) int32 {
|
||||
return Bool32(file(stream).err())
|
||||
}
|
||||
|
||||
// int fgetc(FILE *stream);
|
||||
func Xfgetc(t *TLS, stream uintptr) int32 {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
// int getc(FILE *stream);
|
||||
func Xgetc(t *TLS, stream uintptr) int32 {
|
||||
return Xfgetc(t, stream)
|
||||
}
|
||||
|
||||
// int ungetc(int c, FILE *stream);
|
||||
func Xungetc(t *TLS, c int32, stream uintptr) int32 {
|
||||
panic(todo(""))
|
||||
@ -1745,11 +1169,6 @@ func Xfscanf(t *TLS, stream, format, va uintptr) int32 {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
// FILE *fdopen(int fd, const char *mode);
|
||||
func Xfdopen(t *TLS, fd int32, mode uintptr) uintptr {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
// int fputs(const char *s, FILE *stream);
|
||||
func Xfputs(t *TLS, s, stream uintptr) int32 {
|
||||
if _, _, err := unix.Syscall(unix.SYS_WRITE, uintptr(file(stream).fd()), s, uintptr(Xstrlen(t, s))); err != 0 {
|
||||
@ -1932,11 +1351,6 @@ func Xwritev(t *TLS, fd int32, iov uintptr, iovcnt int32) types.Ssize_t {
|
||||
return types.Ssize_t(n)
|
||||
}
|
||||
|
||||
// void endpwent(void);
|
||||
func Xendpwent(t *TLS) {
|
||||
// nop
|
||||
}
|
||||
|
||||
// int __isoc99_sscanf(const char *str, const char *format, ...);
|
||||
func X__isoc99_sscanf(t *TLS, str, format, va uintptr) int32 {
|
||||
r := Xsscanf(t, str, format, va)
|
||||
@ -1946,26 +1360,21 @@ func X__isoc99_sscanf(t *TLS, str, format, va uintptr) int32 {
|
||||
return r
|
||||
}
|
||||
|
||||
// int sched_yield(void);
|
||||
func Xsched_yield(t *TLS) {
|
||||
runtime.Gosched()
|
||||
}
|
||||
|
||||
var ctimeStaticBuf [32]byte
|
||||
|
||||
// char *ctime(const time_t *timep);
|
||||
func Xctime(t *TLS, timep uintptr) uintptr {
|
||||
return Xctime_r(t, timep, uintptr(unsafe.Pointer(&ctimeStaticBuf[0])))
|
||||
}
|
||||
|
||||
// char *ctime_r(const time_t *timep, char *buf);
|
||||
func Xctime_r(t *TLS, timep, buf uintptr) uintptr {
|
||||
ut := *(*unix.Time_t)(unsafe.Pointer(timep))
|
||||
tm := time.Unix(int64(ut), 0).Local()
|
||||
s := tm.Format(time.ANSIC) + "\n\x00"
|
||||
copy((*RawMem)(unsafe.Pointer(buf))[:26:26], s)
|
||||
return buf
|
||||
}
|
||||
// var ctimeStaticBuf [32]byte
|
||||
//
|
||||
// // char *ctime(const time_t *timep);
|
||||
// func Xctime(t *TLS, timep uintptr) uintptr {
|
||||
// return Xctime_r(t, timep, uintptr(unsafe.Pointer(&ctimeStaticBuf[0])))
|
||||
// }
|
||||
//
|
||||
// // char *ctime_r(const time_t *timep, char *buf);
|
||||
// func Xctime_r(t *TLS, timep, buf uintptr) uintptr {
|
||||
// ut := *(*unix.Time_t)(unsafe.Pointer(timep))
|
||||
// tm := time.Unix(int64(ut), 0).Local()
|
||||
// s := tm.Format(time.ANSIC) + "\n\x00"
|
||||
// copy((*RawMem)(unsafe.Pointer(buf))[:26:26], s)
|
||||
// return buf
|
||||
// }
|
||||
|
||||
// ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
|
||||
func Xpwrite(t *TLS, fd int32, buf uintptr, count types.Size_t, offset types.Off_t) types.Ssize_t {
|
||||
@ -1993,3 +1402,193 @@ func Xpwrite(t *TLS, fd int32, buf uintptr, count types.Size_t, offset types.Off
|
||||
}
|
||||
return types.Ssize_t(n)
|
||||
}
|
||||
|
||||
// int fstatfs(int fd, struct statfs *buf);
|
||||
func Xfstatfs(t *TLS, fd int32, buf uintptr) int32 {
|
||||
if err := unix.Fstatfs(int(fd), (*unix.Statfs_t)(unsafe.Pointer(buf))); err != nil {
|
||||
t.setErrno(err)
|
||||
return -1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
// ssize_t getrandom(void *buf, size_t buflen, unsigned int flags);
|
||||
func Xgetrandom(t *TLS, buf uintptr, buflen size_t, flags uint32) ssize_t {
|
||||
n, err := unix.Getrandom((*RawMem)(unsafe.Pointer(buf))[:buflen], int(flags))
|
||||
if err != nil {
|
||||
t.setErrno(err)
|
||||
return -1
|
||||
}
|
||||
|
||||
return ssize_t(n)
|
||||
}
|
||||
|
||||
// int posix_fadvise(int fd, off_t offset, off_t len, int advice);
|
||||
func Xposix_fadvise(t *TLS, fd int32, offset, len types.Off_t, advice int32) int32 {
|
||||
if err := unix.Fadvise(int(fd), int64(offset), int64(len), int(advice)); err != nil {
|
||||
return int32(err.(unix.Errno))
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
// int fgetc(FILE *stream);
|
||||
func Xfgetc(t *TLS, stream uintptr) int32 {
|
||||
fd := int((*stdio.FILE)(unsafe.Pointer(stream)).F_fileno)
|
||||
var buf [1]byte
|
||||
if n, _ := unix.Read(fd, buf[:]); n != 0 {
|
||||
return int32(buf[0])
|
||||
}
|
||||
|
||||
return stdio.EOF
|
||||
}
|
||||
|
||||
// void uuid_copy(uuid_t dst, uuid_t src);
|
||||
func Xuuid_copy(t *TLS, dst, src uintptr) {
|
||||
*(*uuid.Uuid_t)(unsafe.Pointer(dst)) = *(*uuid.Uuid_t)(unsafe.Pointer(src))
|
||||
}
|
||||
|
||||
// int uuid_parse( char *in, uuid_t uu);
|
||||
func Xuuid_parse(t *TLS, in uintptr, uu uintptr) int32 {
|
||||
r, err := guuid.Parse(GoString(in))
|
||||
if err != nil {
|
||||
return -1
|
||||
}
|
||||
|
||||
copy((*RawMem)(unsafe.Pointer(uu))[:unsafe.Sizeof(uuid.Uuid_t{})], r[:])
|
||||
return 0
|
||||
}
|
||||
|
||||
// int mkdirat(int dirfd, const char *pathname, mode_t mode);
|
||||
func Xmkdirat(t *TLS, dirfd int32, pathname uintptr, mode types.Mode_t) int32 {
|
||||
// From golang.org/x/sys/unix/zsyscall_linux.go
|
||||
if _, _, err := unix.Syscall(unix.SYS_MKDIRAT, uintptr(dirfd), pathname, uintptr(mode)); err != 0 {
|
||||
t.setErrno(err)
|
||||
return -1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
// int symlinkat(const char *target, int newdirfd, const char *linkpath);
|
||||
func Xsymlinkat(t *TLS, target uintptr, newdirfd int32, linkpath uintptr) int32 {
|
||||
// From golang.org/x/sys/unix/zsyscall_linux.go
|
||||
if _, _, err := unix.Syscall(unix.SYS_SYMLINKAT, target, uintptr(newdirfd), linkpath); err != 0 {
|
||||
t.setErrno(err)
|
||||
return -1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
// int utimensat(int dirfd, const char *pathname, const struct timespec times[2], int flags);
|
||||
func Xutimensat(t *TLS, dirfd int32, pathname, times uintptr, flags int32) int32 {
|
||||
// From golang.org/x/sys/unix/zsyscall_linux.go
|
||||
if _, _, err := unix.Syscall6(unix.SYS_UTIMENSAT, uintptr(dirfd), pathname, times, uintptr(flags), 0, 0); err != 0 {
|
||||
t.setErrno(err)
|
||||
return -1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
// int unlinkat(int dirfd, const char *pathname, int flags);
|
||||
func Xunlinkat(t *TLS, dirfd int32, pathname uintptr, flags int32) int32 {
|
||||
// From golang.org/x/sys/unix/zsyscall_linux.go
|
||||
if _, _, err := unix.Syscall(unix.SYS_UNLINKAT, uintptr(dirfd), pathname, uintptr(flags)); err != 0 {
|
||||
t.setErrno(err)
|
||||
return -1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
// int faccessat(int dirfd, const char *pathname, int mode, int flags);
|
||||
func Xfaccessat(t *TLS, dirfd int32, pathname uintptr, mode, flags int32) int32 {
|
||||
// From golang.org/x/sys/unix/zsyscall_linux.go
|
||||
if _, _, err := unix.Syscall(unix.SYS_FACCESSAT, uintptr(dirfd), pathname, uintptr(mode)); err != 0 {
|
||||
t.setErrno(err)
|
||||
return -1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
// int renameat2(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, unsigned int flags);
|
||||
func Xrenameat2(t *TLS, olddirfd int32, oldpath uintptr, newdirfd int32, newpath uintptr, flags int32) int32 {
|
||||
// From golang.org/x/sys/unix/zsyscall_linux.go
|
||||
if _, _, err := unix.Syscall6(unix.SYS_RENAMEAT2, uintptr(olddirfd), oldpath, uintptr(newdirfd), newpath, uintptr(flags), 0); err != 0 {
|
||||
t.setErrno(err)
|
||||
return -1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
// int mknodat(int dirfd, const char *pathname, mode_t mode, dev_t dev);
|
||||
func Xmknodat(t *TLS, dirfd int32, pathname uintptr, mode types.Mode_t, dev types.Dev_t) int32 {
|
||||
// From golang.org/x/sys/unix/zsyscall_linux.go
|
||||
if _, _, err := unix.Syscall6(unix.SYS_MKNODAT, uintptr(dirfd), pathname, uintptr(mode), uintptr(dev), 0, 0); err != 0 {
|
||||
t.setErrno(err)
|
||||
return -1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
// int fchownat(int dirfd, const char *pathname, uid_t owner, gid_t group, int flags);
|
||||
func Xfchownat(t *TLS, dirfd int32, pathname uintptr, uid types.Uid_t, gid types.Gid_t, flags int32) int32 {
|
||||
// From golang.org/x/sys/unix/zsyscall_linux.go
|
||||
if _, _, err := unix.Syscall6(unix.SYS_FCHOWNAT, uintptr(dirfd), pathname, uintptr(uid), uintptr(gid), uintptr(flags), 0); err != 0 {
|
||||
t.setErrno(err)
|
||||
return -1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
// int linkat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, int flags);
|
||||
func Xlinkat(t *TLS, olddirfd int32, oldpath uintptr, newdirfd int32, newpath uintptr, flags int32) int32 {
|
||||
// From golang.org/x/sys/unix/zsyscall_linux.go
|
||||
if _, _, err := unix.Syscall6(unix.SYS_LINKAT, uintptr(olddirfd), oldpath, uintptr(newdirfd), newpath, uintptr(flags), 0); err != 0 {
|
||||
t.setErrno(err)
|
||||
return -1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
// int pipe2(int pipefd[2], int flags);
|
||||
func Xpipe2(t *TLS, pipefd uintptr, flags int32) int32 {
|
||||
// From golang.org/x/sys/unix/zsyscall_linux.go
|
||||
if _, _, err := unix.Syscall(unix.SYS_PIPE2, pipefd, uintptr(flags), 0); err != 0 {
|
||||
t.setErrno(t)
|
||||
return -1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
// int dup3(int oldfd, int newfd, int flags);
|
||||
func Xdup3(t *TLS, oldfd int32, newfd int32, flags int32) int32 {
|
||||
// From golang.org/x/sys/unix/zsyscall_linux.go
|
||||
if _, _, err := unix.Syscall(unix.SYS_DUP3, uintptr(oldfd), uintptr(newfd), uintptr(flags)); err != 0 {
|
||||
t.setErrno(err)
|
||||
return -1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
// ssize_t readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz);
|
||||
func Xreadlinkat(t *TLS, dirfd int32, pathname, buf uintptr, bufsiz types.Size_t) types.Ssize_t {
|
||||
// From golang.org/x/sys/unix/zsyscall_linux.go
|
||||
n, _, err := unix.Syscall6(unix.SYS_READLINKAT, uintptr(dirfd), pathname, buf, uintptr(bufsiz), 0, 0)
|
||||
if err != 0 {
|
||||
t.setErrno(err)
|
||||
return -1
|
||||
}
|
||||
|
||||
return types.Ssize_t(n)
|
||||
}
|
||||
|
Reference in New Issue
Block a user