patch os, syscall, io/fs: Errno, Stdin/out/err
This commit is contained in:
16
internal/lib/syscall/errors.go
Normal file
16
internal/lib/syscall/errors.go
Normal file
@@ -0,0 +1,16 @@
|
||||
// Copyright 2019 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package syscall
|
||||
|
||||
import "errors"
|
||||
|
||||
// from internal/oserror
|
||||
var (
|
||||
ErrInvalid = errors.New("invalid argument")
|
||||
ErrPermission = errors.New("permission denied")
|
||||
ErrExist = errors.New("file already exists")
|
||||
ErrNotExist = errors.New("file does not exist")
|
||||
ErrClosed = errors.New("file already closed")
|
||||
)
|
||||
59
internal/lib/syscall/syscall_unix.go
Normal file
59
internal/lib/syscall/syscall_unix.go
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package syscall
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/internal/lib/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
Stdin = 0
|
||||
Stdout = 1
|
||||
Stderr = 2
|
||||
)
|
||||
|
||||
type Errno uintptr
|
||||
|
||||
func (e Errno) Error() string {
|
||||
ret := c.Strerror(c.Int(e))
|
||||
return unsafe.String((*byte)(unsafe.Pointer(ret)), c.Strlen(ret))
|
||||
}
|
||||
|
||||
func (e Errno) Is(target error) bool {
|
||||
switch target {
|
||||
case ErrPermission:
|
||||
return e == EACCES || e == EPERM
|
||||
case ErrExist:
|
||||
return e == EEXIST || e == ENOTEMPTY
|
||||
case ErrNotExist:
|
||||
return e == ENOENT
|
||||
case errors.ErrUnsupported:
|
||||
return e == ENOSYS || e == ENOTSUP || e == EOPNOTSUPP
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (e Errno) Temporary() bool {
|
||||
return e == EINTR || e == EMFILE || e == ENFILE || e.Timeout()
|
||||
}
|
||||
|
||||
func (e Errno) Timeout() bool {
|
||||
return e == EAGAIN || e == EWOULDBLOCK || e == ETIMEDOUT
|
||||
}
|
||||
129
internal/lib/syscall/zerrors_darwin_arm64.go
Normal file
129
internal/lib/syscall/zerrors_darwin_arm64.go
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package syscall
|
||||
|
||||
// Errors
|
||||
const (
|
||||
E2BIG = Errno(0x7)
|
||||
EACCES = Errno(0xd)
|
||||
EADDRINUSE = Errno(0x30)
|
||||
EADDRNOTAVAIL = Errno(0x31)
|
||||
EAFNOSUPPORT = Errno(0x2f)
|
||||
EAGAIN = Errno(0x23)
|
||||
EALREADY = Errno(0x25)
|
||||
EAUTH = Errno(0x50)
|
||||
EBADARCH = Errno(0x56)
|
||||
EBADEXEC = Errno(0x55)
|
||||
EBADF = Errno(0x9)
|
||||
EBADMACHO = Errno(0x58)
|
||||
EBADMSG = Errno(0x5e)
|
||||
EBADRPC = Errno(0x48)
|
||||
EBUSY = Errno(0x10)
|
||||
ECANCELED = Errno(0x59)
|
||||
ECHILD = Errno(0xa)
|
||||
ECONNABORTED = Errno(0x35)
|
||||
ECONNREFUSED = Errno(0x3d)
|
||||
ECONNRESET = Errno(0x36)
|
||||
EDEADLK = Errno(0xb)
|
||||
EDESTADDRREQ = Errno(0x27)
|
||||
EDEVERR = Errno(0x53)
|
||||
EDOM = Errno(0x21)
|
||||
EDQUOT = Errno(0x45)
|
||||
EEXIST = Errno(0x11)
|
||||
EFAULT = Errno(0xe)
|
||||
EFBIG = Errno(0x1b)
|
||||
EFTYPE = Errno(0x4f)
|
||||
EHOSTDOWN = Errno(0x40)
|
||||
EHOSTUNREACH = Errno(0x41)
|
||||
EIDRM = Errno(0x5a)
|
||||
EILSEQ = Errno(0x5c)
|
||||
EINPROGRESS = Errno(0x24)
|
||||
EINTR = Errno(0x4)
|
||||
EINVAL = Errno(0x16)
|
||||
EIO = Errno(0x5)
|
||||
EISCONN = Errno(0x38)
|
||||
EISDIR = Errno(0x15)
|
||||
ELAST = Errno(0x6a)
|
||||
ELOOP = Errno(0x3e)
|
||||
EMFILE = Errno(0x18)
|
||||
EMLINK = Errno(0x1f)
|
||||
EMSGSIZE = Errno(0x28)
|
||||
EMULTIHOP = Errno(0x5f)
|
||||
ENAMETOOLONG = Errno(0x3f)
|
||||
ENEEDAUTH = Errno(0x51)
|
||||
ENETDOWN = Errno(0x32)
|
||||
ENETRESET = Errno(0x34)
|
||||
ENETUNREACH = Errno(0x33)
|
||||
ENFILE = Errno(0x17)
|
||||
ENOATTR = Errno(0x5d)
|
||||
ENOBUFS = Errno(0x37)
|
||||
ENODATA = Errno(0x60)
|
||||
ENODEV = Errno(0x13)
|
||||
ENOENT = Errno(0x2)
|
||||
ENOEXEC = Errno(0x8)
|
||||
ENOLCK = Errno(0x4d)
|
||||
ENOLINK = Errno(0x61)
|
||||
ENOMEM = Errno(0xc)
|
||||
ENOMSG = Errno(0x5b)
|
||||
ENOPOLICY = Errno(0x67)
|
||||
ENOPROTOOPT = Errno(0x2a)
|
||||
ENOSPC = Errno(0x1c)
|
||||
ENOSR = Errno(0x62)
|
||||
ENOSTR = Errno(0x63)
|
||||
ENOSYS = Errno(0x4e)
|
||||
ENOTBLK = Errno(0xf)
|
||||
ENOTCONN = Errno(0x39)
|
||||
ENOTDIR = Errno(0x14)
|
||||
ENOTEMPTY = Errno(0x42)
|
||||
ENOTRECOVERABLE = Errno(0x68)
|
||||
ENOTSOCK = Errno(0x26)
|
||||
ENOTSUP = Errno(0x2d)
|
||||
ENOTTY = Errno(0x19)
|
||||
ENXIO = Errno(0x6)
|
||||
EOPNOTSUPP = Errno(0x66)
|
||||
EOVERFLOW = Errno(0x54)
|
||||
EOWNERDEAD = Errno(0x69)
|
||||
EPERM = Errno(0x1)
|
||||
EPFNOSUPPORT = Errno(0x2e)
|
||||
EPIPE = Errno(0x20)
|
||||
EPROCLIM = Errno(0x43)
|
||||
EPROCUNAVAIL = Errno(0x4c)
|
||||
EPROGMISMATCH = Errno(0x4b)
|
||||
EPROGUNAVAIL = Errno(0x4a)
|
||||
EPROTO = Errno(0x64)
|
||||
EPROTONOSUPPORT = Errno(0x2b)
|
||||
EPROTOTYPE = Errno(0x29)
|
||||
EPWROFF = Errno(0x52)
|
||||
EQFULL = Errno(0x6a)
|
||||
ERANGE = Errno(0x22)
|
||||
EREMOTE = Errno(0x47)
|
||||
EROFS = Errno(0x1e)
|
||||
ERPCMISMATCH = Errno(0x49)
|
||||
ESHLIBVERS = Errno(0x57)
|
||||
ESHUTDOWN = Errno(0x3a)
|
||||
ESOCKTNOSUPPORT = Errno(0x2c)
|
||||
ESPIPE = Errno(0x1d)
|
||||
ESRCH = Errno(0x3)
|
||||
ESTALE = Errno(0x46)
|
||||
ETIME = Errno(0x65)
|
||||
ETIMEDOUT = Errno(0x3c)
|
||||
ETOOMANYREFS = Errno(0x3b)
|
||||
ETXTBSY = Errno(0x1a)
|
||||
EUSERS = Errno(0x44)
|
||||
EWOULDBLOCK = Errno(0x23)
|
||||
EXDEV = Errno(0x12)
|
||||
)
|
||||
Reference in New Issue
Block a user