c/syscall: zerrors

This commit is contained in:
xushiwei
2024-07-18 15:45:54 +08:00
parent 3da3c8ecd8
commit f2dafa7544
37 changed files with 49148 additions and 36 deletions

View File

@@ -8,8 +8,6 @@ import (
)
func main() {
fmt.Println("os.Environ:", os.Environ())
ls := "ls"
args := []string{ls, "-l"}
if runtime.GOOS == "windows" {

View File

@@ -19,3 +19,9 @@ package syscall
const (
LLGoPackage = "decl"
)
type Errno = uintptr
// A Signal is a number describing a process signal.
// It implements the os.Signal interface.
type Signal = int

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,148 @@
// mkerrors_windows.sh -m32
// Code generated by the command above; DO NOT EDIT.
package syscall
// Go names for Windows errors.
const (
ENOENT Errno = ERROR_FILE_NOT_FOUND
ENOTDIR Errno = ERROR_PATH_NOT_FOUND
)
// Windows reserves errors >= 1<<29 for application use.
const APPLICATION_ERROR = 1 << 29
// Invented values to support what package os and others expects.
const (
E2BIG Errno = APPLICATION_ERROR + iota
EACCES
EADDRINUSE
EADDRNOTAVAIL
EADV
EAFNOSUPPORT
EAGAIN
EALREADY
EBADE
EBADF
EBADFD
EBADMSG
EBADR
EBADRQC
EBADSLT
EBFONT
EBUSY
ECANCELED
ECHILD
ECHRNG
ECOMM
ECONNABORTED
ECONNREFUSED
ECONNRESET
EDEADLK
EDEADLOCK
EDESTADDRREQ
EDOM
EDOTDOT
EDQUOT
EEXIST
EFAULT
EFBIG
EHOSTDOWN
EHOSTUNREACH
EIDRM
EILSEQ
EINPROGRESS
EINTR
EINVAL
EIO
EISCONN
EISDIR
EISNAM
EKEYEXPIRED
EKEYREJECTED
EKEYREVOKED
EL2HLT
EL2NSYNC
EL3HLT
EL3RST
ELIBACC
ELIBBAD
ELIBEXEC
ELIBMAX
ELIBSCN
ELNRNG
ELOOP
EMEDIUMTYPE
EMFILE
EMLINK
EMSGSIZE
EMULTIHOP
ENAMETOOLONG
ENAVAIL
ENETDOWN
ENETRESET
ENETUNREACH
ENFILE
ENOANO
ENOBUFS
ENOCSI
ENODATA
ENODEV
ENOEXEC
ENOKEY
ENOLCK
ENOLINK
ENOMEDIUM
ENOMEM
ENOMSG
ENONET
ENOPKG
ENOPROTOOPT
ENOSPC
ENOSR
ENOSTR
ENOSYS
ENOTBLK
ENOTCONN
ENOTEMPTY
ENOTNAM
ENOTRECOVERABLE
ENOTSOCK
ENOTSUP
ENOTTY
ENOTUNIQ
ENXIO
EOPNOTSUPP
EOVERFLOW
EOWNERDEAD
EPERM
EPFNOSUPPORT
EPIPE
EPROTO
EPROTONOSUPPORT
EPROTOTYPE
ERANGE
EREMCHG
EREMOTE
EREMOTEIO
ERESTART
EROFS
ESHUTDOWN
ESOCKTNOSUPPORT
ESPIPE
ESRCH
ESRMNT
ESTALE
ESTRPIPE
ETIME
ETIMEDOUT
ETOOMANYREFS
ETXTBSY
EUCLEAN
EUNATCH
EUSERS
EWOULDBLOCK
EXDEV
EXFULL
EWINDOWS
)

View File

@@ -9,8 +9,11 @@
package syscall
import (
"errors"
"runtime"
"sync"
"syscall"
"unsafe"
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/c/os"
@@ -106,13 +109,10 @@ type ProcAttr struct {
Sys *SysProcAttr
}
/* TODO(xsw):
var zeroProcAttr ProcAttr
var zeroSysProcAttr SysProcAttr
*/
func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error) {
/* TODO(xsw):
var p [2]int
var n int
var err1 Errno
@@ -127,45 +127,30 @@ func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error)
}
// Convert args to C form.
argv0p, err := BytePtrFromString(argv0)
if err != nil {
return 0, err
}
argvp, err := SlicePtrFromStrings(argv)
if err != nil {
return 0, err
}
envvp, err := SlicePtrFromStrings(attr.Env)
if err != nil {
return 0, err
}
argv0p := c.AllocaCStr(argv0)
argvp := c.AllocaCStrs(argv, true)
envvp := c.AllocaCStrs(attr.Env, true)
if (runtime.GOOS == "freebsd" || runtime.GOOS == "dragonfly") && len(argv) > 0 && len(argv[0]) > len(argv0) {
argvp[0] = argv0p
*argvp = argv0p
}
var chroot *byte
var chroot *c.Char
if sys.Chroot != "" {
chroot, err = BytePtrFromString(sys.Chroot)
if err != nil {
return 0, err
chroot = c.AllocaCStr(sys.Chroot)
}
}
var dir *byte
var dir *c.Char
if attr.Dir != "" {
dir, err = BytePtrFromString(attr.Dir)
if err != nil {
return 0, err
}
dir = c.AllocaCStr(attr.Dir)
}
// Both Setctty and Foreground use the Ctty field,
// but they give it slightly different meanings.
if sys.Setctty && sys.Foreground {
return 0, errorspkg.New("both Setctty and Foreground set in SysProcAttr")
return 0, errors.New("both Setctty and Foreground set in SysProcAttr")
}
if sys.Setctty && sys.Ctty >= len(attr.Files) {
return 0, errorspkg.New("Setctty set but Ctty not valid in child")
return 0, errors.New("Setctty set but Ctty not valid in child")
}
acquireForkLock()
@@ -214,8 +199,6 @@ func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error)
// Read got EOF, so pipe closed on exec, so exec succeeded.
return pid, nil
*/
panic("todo: syscall.forkExec")
}
// Combination of fork and exec, careful to be thread safe.

View File

@@ -82,7 +82,7 @@ func Kill(pid int, signum Signal) (err error) {
if ret == 0 {
return nil
}
return Errno(os.Errno)
return Errno(ret)
}
func Open(path string, mode int, perm uint32) (fd int, err error) {
@@ -114,7 +114,7 @@ func Close(fd int) (err error) {
if ret == 0 {
return nil
}
return Errno(os.Errno)
return Errno(ret)
}
type Stat_t = syscall.Stat_t
@@ -124,7 +124,7 @@ func Lstat(path string, stat *Stat_t) (err error) {
if ret == 0 {
return nil
}
return Errno(os.Errno)
return Errno(ret)
}
func Stat(path string, stat *Stat_t) (err error) {
@@ -132,5 +132,19 @@ func Stat(path string, stat *Stat_t) (err error) {
if ret == 0 {
return nil
}
return Errno(os.Errno)
return Errno(ret)
}
func Pipe(p []int) (err error) {
if len(p) != 2 {
return EINVAL
}
var q [2]c.Int
ret := os.Pipe(&q)
if ret == 0 {
p[0] = int(q[0])
p[1] = int(q[1])
return nil
}
return Errno(ret)
}