patch library: os/exec
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -8,13 +8,17 @@ package exec
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"io/fs"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrNotFound is the error resulting if a path search failed to find an executable file.
|
// ErrNotFound is the error resulting if a path search failed to find an executable file.
|
||||||
var ErrNotFound = errors.New("executable file not found in $PATH")
|
var ErrNotFound = errors.New("executable file not found in $PATH")
|
||||||
|
|
||||||
func findExecutable(file string) error {
|
func findExecutable(file string) error {
|
||||||
/* TODO(xsw):
|
|
||||||
d, err := os.Stat(file)
|
d, err := os.Stat(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -23,7 +27,7 @@ func findExecutable(file string) error {
|
|||||||
if m.IsDir() {
|
if m.IsDir() {
|
||||||
return syscall.EISDIR
|
return syscall.EISDIR
|
||||||
}
|
}
|
||||||
err = unix.Eaccess(file, unix.X_OK)
|
err = unixEaccess(file, unix_X_OK)
|
||||||
// ENOSYS means Eaccess is not available or not implemented.
|
// ENOSYS means Eaccess is not available or not implemented.
|
||||||
// EPERM can be returned by Linux containers employing seccomp.
|
// EPERM can be returned by Linux containers employing seccomp.
|
||||||
// In both cases, fall back to checking the permission bits.
|
// In both cases, fall back to checking the permission bits.
|
||||||
@@ -34,8 +38,6 @@ func findExecutable(file string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return fs.ErrPermission
|
return fs.ErrPermission
|
||||||
*/
|
|
||||||
panic("todo: exec.findExecutable")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// LookPath searches for an executable named file in the
|
// LookPath searches for an executable named file in the
|
||||||
@@ -47,7 +49,6 @@ func findExecutable(file string) error {
|
|||||||
// As of Go 1.19, LookPath will instead return that path along with an error satisfying
|
// As of Go 1.19, LookPath will instead return that path along with an error satisfying
|
||||||
// errors.Is(err, ErrDot). See the package documentation for more details.
|
// errors.Is(err, ErrDot). See the package documentation for more details.
|
||||||
func LookPath(file string) (string, error) {
|
func LookPath(file string) (string, error) {
|
||||||
/* TODO(xsw):
|
|
||||||
// NOTE(rsc): I wish we could use the Plan 9 behavior here
|
// NOTE(rsc): I wish we could use the Plan 9 behavior here
|
||||||
// (only bypass the path if file begins with / or ./ or ../)
|
// (only bypass the path if file begins with / or ./ or ../)
|
||||||
// but that would not match all the Unix shells.
|
// but that would not match all the Unix shells.
|
||||||
@@ -68,15 +69,16 @@ func LookPath(file string) (string, error) {
|
|||||||
path := filepath.Join(dir, file)
|
path := filepath.Join(dir, file)
|
||||||
if err := findExecutable(path); err == nil {
|
if err := findExecutable(path); err == nil {
|
||||||
if !filepath.IsAbs(path) {
|
if !filepath.IsAbs(path) {
|
||||||
|
/* TODO(xsw):
|
||||||
if execerrdot.Value() != "0" {
|
if execerrdot.Value() != "0" {
|
||||||
return path, &Error{file, ErrDot}
|
return path, &Error{file, ErrDot}
|
||||||
}
|
}
|
||||||
execerrdot.IncNonDefault()
|
execerrdot.IncNonDefault()
|
||||||
|
*/
|
||||||
|
panic("todo: exec.LookPath: !filepath.IsAbs(path)")
|
||||||
}
|
}
|
||||||
return path, nil
|
return path, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "", &Error{file, ErrNotFound}
|
return "", &Error{file, ErrNotFound}
|
||||||
*/
|
|
||||||
panic("todo: exec.LookPath")
|
|
||||||
}
|
}
|
||||||
|
|||||||
13
internal/lib/os/exec/unix_constants.go
Normal file
13
internal/lib/os/exec/unix_constants.go
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
// Copyright 2022 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.
|
||||||
|
|
||||||
|
//go:build unix
|
||||||
|
|
||||||
|
package exec
|
||||||
|
|
||||||
|
const (
|
||||||
|
unix_R_OK = 0x4
|
||||||
|
unix_W_OK = 0x2
|
||||||
|
unix_X_OK = 0x1
|
||||||
|
)
|
||||||
11
internal/lib/os/exec/unix_eaccess_linux.go
Normal file
11
internal/lib/os/exec/unix_eaccess_linux.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
// Copyright 2022 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 exec
|
||||||
|
|
||||||
|
import "syscall"
|
||||||
|
|
||||||
|
func unixEaccess(path string, mode uint32) error {
|
||||||
|
return syscall.Faccessat(AT_FDCWD, path, mode, AT_EACCESS)
|
||||||
|
}
|
||||||
13
internal/lib/os/exec/unix_eaccess_other.go
Normal file
13
internal/lib/os/exec/unix_eaccess_other.go
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
// Copyright 2022 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.
|
||||||
|
|
||||||
|
//go:build unix && !linux
|
||||||
|
|
||||||
|
package exec
|
||||||
|
|
||||||
|
import "syscall"
|
||||||
|
|
||||||
|
func unixEaccess(path string, mode uint32) error {
|
||||||
|
return syscall.ENOSYS
|
||||||
|
}
|
||||||
@@ -24,6 +24,34 @@ import (
|
|||||||
"github.com/goplus/llgo/c/os"
|
"github.com/goplus/llgo/c/os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unix returns the time stored in tv as seconds plus nanoseconds.
|
||||||
|
func (tv *Timeval) Unix() (sec int64, nsec int64) {
|
||||||
|
return int64(tv.Sec), int64(tv.Usec) * 1000
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nano returns the time stored in ts as nanoseconds.
|
||||||
|
func (ts *Timespec) Nano() int64 {
|
||||||
|
return int64(ts.Sec)*1e9 + int64(ts.Nsec)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nano returns the time stored in tv as nanoseconds.
|
||||||
|
func (tv *Timeval) Nano() int64 {
|
||||||
|
return int64(tv.Sec)*1e9 + int64(tv.Usec)*1000
|
||||||
|
}
|
||||||
|
|
||||||
|
func Getpagesize() int {
|
||||||
|
panic("todo: syscall.Getpagesize")
|
||||||
|
}
|
||||||
|
|
||||||
|
func Exit(code int) {
|
||||||
|
os.Exit(c.Int(code))
|
||||||
|
}
|
||||||
|
|
||||||
func Getcwd(buf []byte) (n int, err error) {
|
func Getcwd(buf []byte) (n int, err error) {
|
||||||
ptr := unsafe.Pointer(unsafe.SliceData(buf))
|
ptr := unsafe.Pointer(unsafe.SliceData(buf))
|
||||||
ret := os.Getcwd(ptr, uintptr(len(buf)))
|
ret := os.Getcwd(ptr, uintptr(len(buf)))
|
||||||
|
|||||||
Reference in New Issue
Block a user