toSyscallErr => syscall.Errno

This commit is contained in:
xushiwei
2024-06-26 00:28:21 +08:00
parent d64d220b49
commit 1d3710afd8
2 changed files with 12 additions and 15 deletions

View File

@@ -20,6 +20,7 @@ package os
import ( import (
"errors" "errors"
"runtime" "runtime"
"syscall"
_ "unsafe" _ "unsafe"
"github.com/goplus/llgo/c" "github.com/goplus/llgo/c"
@@ -51,12 +52,8 @@ func toMode(mode FileMode) os.ModeT {
panic("todo: toMode") panic("todo: toMode")
} }
func toSyscallErr(errno c.Int) error {
panic("todo: toSyscallErr")
}
func toPathErr(op, path string, errno c.Int) error { func toPathErr(op, path string, errno c.Int) error {
return &PathError{Op: op, Path: path, Err: toSyscallErr(errno)} return &PathError{Op: op, Path: path, Err: syscall.Errno(errno)}
} }
func Chdir(dir string) error { func Chdir(dir string) error {
@@ -179,7 +176,7 @@ func Getwd() (dir string, err error) {
if wd != nil { if wd != nil {
return c.GoString(wd), nil return c.GoString(wd), nil
} }
return "", toSyscallErr(os.Errno) return "", syscall.Errno(os.Errno)
} }
// TODO(xsw): // TODO(xsw):
@@ -203,7 +200,7 @@ func Link(oldname, newname string) error {
if ret == 0 { if ret == 0 {
return nil return nil
} }
return &LinkError{"link", oldname, newname, toSyscallErr(ret)} return &LinkError{"link", oldname, newname, syscall.Errno(ret)}
} }
// TODO(xsw): // TODO(xsw):
@@ -277,7 +274,7 @@ func Rename(oldpath, newpath string) error {
if ret == 0 { if ret == 0 {
return nil return nil
} }
return &LinkError{"rename", oldpath, newpath, toSyscallErr(ret)} return &LinkError{"rename", oldpath, newpath, syscall.Errno(ret)}
} }
/* TODO(xsw): /* TODO(xsw):
@@ -299,7 +296,7 @@ func Setenv(key, value string) error {
if ret == 0 { if ret == 0 {
return nil return nil
} }
return &SyscallError{"setenv", toSyscallErr(ret)} return &SyscallError{"setenv", syscall.Errno(ret)}
} }
func Symlink(oldname, newname string) error { func Symlink(oldname, newname string) error {
@@ -307,7 +304,7 @@ func Symlink(oldname, newname string) error {
if ret == 0 { if ret == 0 {
return nil return nil
} }
return &LinkError{"symlink", oldname, newname, toSyscallErr(ret)} return &LinkError{"symlink", oldname, newname, syscall.Errno(ret)}
} }
// TODO(xsw): // TODO(xsw):
@@ -326,7 +323,7 @@ func Unsetenv(key string) error {
if ret == 0 { if ret == 0 {
return nil return nil
} }
return toSyscallErr(ret) return syscall.Errno(ret)
} }
// UserCacheDir returns the default root directory to use for user-specific // UserCacheDir returns the default root directory to use for user-specific

View File

@@ -40,8 +40,8 @@ func NewFile(fd uintptr, name string) *File {
// It returns the number of bytes written and an error, if any. // It returns the number of bytes written and an error, if any.
func (f *File) write(b []byte) (n int, err error) { func (f *File) write(b []byte) (n int, err error) {
n = int(os.Write(c.Int(f.fd), unsafe.Pointer(unsafe.SliceData(b)), uintptr(len(b)))) n = int(os.Write(c.Int(f.fd), unsafe.Pointer(unsafe.SliceData(b)), uintptr(len(b))))
if e := os.Errno; e != 0 { if n != len(b) {
err = toSyscallErr(e) err = syscall.Errno(os.Errno)
} }
return return
} }
@@ -50,8 +50,8 @@ func (f *File) write(b []byte) (n int, err error) {
// It returns the number of bytes read and an error, if any. // It returns the number of bytes read and an error, if any.
func (f *File) read(b []byte) (n int, err error) { func (f *File) read(b []byte) (n int, err error) {
n = int(os.Read(c.Int(f.fd), unsafe.Pointer(unsafe.SliceData(b)), uintptr(len(b)))) n = int(os.Read(c.Int(f.fd), unsafe.Pointer(unsafe.SliceData(b)), uintptr(len(b))))
if e := os.Errno; e != 0 { if n != len(b) {
err = toSyscallErr(e) err = syscall.Errno(os.Errno)
} }
return return
} }