library: c/syscall
This commit is contained in:
@@ -664,8 +664,6 @@ func canSkipToBuild(pkgPath string) bool {
|
||||
switch pkgPath {
|
||||
case "unsafe":
|
||||
return true
|
||||
case "internal/oserror":
|
||||
return false
|
||||
default:
|
||||
return strings.HasPrefix(pkgPath, "internal/") ||
|
||||
strings.HasPrefix(pkgPath, "runtime/internal/")
|
||||
@@ -679,6 +677,7 @@ var hasAltPkg = map[string]none{
|
||||
"fmt": {},
|
||||
"internal/abi": {},
|
||||
"internal/bytealg": {},
|
||||
"internal/oserror": {},
|
||||
"internal/reflectlite": {},
|
||||
//"io": {},
|
||||
//"io/fs": {},
|
||||
|
||||
@@ -2,11 +2,14 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package syscall
|
||||
// Package oserror defines errors values used in the os package.
|
||||
//
|
||||
// These types are defined here to permit the syscall package to reference them.
|
||||
package oserror
|
||||
|
||||
// llgo:skipall
|
||||
import "errors"
|
||||
|
||||
// from internal/oserror
|
||||
var (
|
||||
ErrInvalid = errors.New("invalid argument")
|
||||
ErrPermission = errors.New("permission denied")
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
package os
|
||||
|
||||
import "syscall"
|
||||
|
||||
// Stat returns the FileInfo structure describing file.
|
||||
// If there is an error, it will be of type *PathError.
|
||||
func (f *File) Stat() (FileInfo, error) {
|
||||
@@ -26,7 +28,6 @@ func (f *File) Stat() (FileInfo, error) {
|
||||
|
||||
// statNolog stats a file with no test logging.
|
||||
func statNolog(name string) (FileInfo, error) {
|
||||
/* TODO(xsw):
|
||||
var fs fileStat
|
||||
err := ignoringEINTR(func() error {
|
||||
return syscall.Stat(name, &fs.sys)
|
||||
@@ -36,13 +37,10 @@ func statNolog(name string) (FileInfo, error) {
|
||||
}
|
||||
fillFileStatFromSys(&fs, name)
|
||||
return &fs, nil
|
||||
*/
|
||||
panic("todo: os.statNolog")
|
||||
}
|
||||
|
||||
// lstatNolog lstats a file with no test logging.
|
||||
func lstatNolog(name string) (FileInfo, error) {
|
||||
/* TODO(xsw):
|
||||
var fs fileStat
|
||||
err := ignoringEINTR(func() error {
|
||||
return syscall.Lstat(name, &fs.sys)
|
||||
@@ -52,6 +50,4 @@ func lstatNolog(name string) (FileInfo, error) {
|
||||
}
|
||||
fillFileStatFromSys(&fs, name)
|
||||
return &fs, nil
|
||||
*/
|
||||
panic("todo: os.lstatNolog")
|
||||
}
|
||||
|
||||
@@ -22,8 +22,12 @@ import (
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/os"
|
||||
"github.com/goplus/llgo/c/syscall"
|
||||
)
|
||||
|
||||
type Timespec syscall.Timespec
|
||||
type Timeval syscall.Timeval
|
||||
|
||||
// Unix returns the time stored in ts as seconds plus nanoseconds.
|
||||
func (ts *Timespec) Unix() (sec int64, nsec int64) {
|
||||
return int64(ts.Sec), int64(ts.Nsec)
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/internal/lib/internal/oserror"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -28,11 +29,11 @@ func (e Errno) Error() string {
|
||||
|
||||
func (e Errno) Is(target error) bool {
|
||||
switch target {
|
||||
case ErrPermission:
|
||||
case oserror.ErrPermission:
|
||||
return e == EACCES || e == EPERM
|
||||
case ErrExist:
|
||||
case oserror.ErrExist:
|
||||
return e == EEXIST || e == ENOTEMPTY
|
||||
case ErrNotExist:
|
||||
case oserror.ErrNotExist:
|
||||
return e == ENOENT
|
||||
case errors.ErrUnsupported:
|
||||
return e == ENOSYS || e == ENOTSUP || e == EOPNOTSUPP
|
||||
|
||||
@@ -1021,6 +1021,36 @@ func unixTime(sec int64, nsec int32) Time {
|
||||
return Time{uint64(nsec), sec + unixToInternal, Local}
|
||||
}
|
||||
|
||||
// Unix returns the local Time corresponding to the given Unix time,
|
||||
// sec seconds and nsec nanoseconds since January 1, 1970 UTC.
|
||||
// It is valid to pass nsec outside the range [0, 999999999].
|
||||
// Not all sec values have a corresponding time value. One such
|
||||
// value is 1<<63-1 (the largest int64 value).
|
||||
func Unix(sec int64, nsec int64) Time {
|
||||
if nsec < 0 || nsec >= 1e9 {
|
||||
n := nsec / 1e9
|
||||
sec += n
|
||||
nsec -= n * 1e9
|
||||
if nsec < 0 {
|
||||
nsec += 1e9
|
||||
sec--
|
||||
}
|
||||
}
|
||||
return unixTime(sec, int32(nsec))
|
||||
}
|
||||
|
||||
// UnixMilli returns the local Time corresponding to the given Unix time,
|
||||
// msec milliseconds since January 1, 1970 UTC.
|
||||
func UnixMilli(msec int64) Time {
|
||||
return Unix(msec/1e3, (msec%1e3)*1e6)
|
||||
}
|
||||
|
||||
// UnixMicro returns the local Time corresponding to the given Unix time,
|
||||
// usec microseconds since January 1, 1970 UTC.
|
||||
func UnixMicro(usec int64) Time {
|
||||
return Unix(usec/1e6, (usec%1e6)*1e3)
|
||||
}
|
||||
|
||||
func isLeap(year int) bool {
|
||||
return year%4 == 0 && (year%100 != 0 || year%400 == 0)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user