os: stub out support for some more features

This is necessary for the following:

  - to make sure os/exec can be imported
  - to make sure internal/testenv can be imported

The internal/testenv package (which imports os/exec) is used by a lot of
tests. By adding support for it, more tests can be run.

This commit adds a bunch of new packages that now pass all tests.
This commit is contained in:
Ayke van Laethem
2020-09-25 19:59:48 +02:00
committed by Ron Evans
parent 6cbaed75c8
commit 718746dd21
12 changed files with 186 additions and 12 deletions
+4
View File
@@ -12,3 +12,7 @@ func Getenv(key string) string {
func LookupEnv(key string) (string, bool) {
return syscall.Getenv(key)
}
func Environ() []string {
return syscall.Environ()
}
+33
View File
@@ -16,3 +16,36 @@ func Getpid() int {
func Getppid() int {
return syscall.Getppid()
}
type ProcAttr struct {
Dir string
Env []string
Files []*File
Sys *syscall.SysProcAttr
}
type ProcessState struct {
}
func (p *ProcessState) String() string {
return "" // TODO
}
func (p *ProcessState) Success() bool {
return false // TODO
}
type Process struct {
Pid int
}
func StartProcess(name string, argv []string, attr *ProcAttr) (*Process, error) {
return nil, &PathError{"fork/exec", name, ErrNotImplemented}
}
func (p *Process) Wait() (*ProcessState, error) {
return nil, ErrNotImplemented
}
func (p *Process) Kill() error {
return ErrNotImplemented
}
+31
View File
@@ -52,6 +52,16 @@ func Remove(path string) error {
return nil
}
// Symlink is a stub, it is not implemented.
func Symlink(oldname, newname string) error {
return ErrNotImplemented
}
// RemoveAll is a stub, it is not implemented.
func RemoveAll(path string) error {
return ErrNotImplemented
}
// File represents an open file descriptor.
type File struct {
handle FileHandle
@@ -187,6 +197,27 @@ func (e *PathError) Error() string {
return e.Op + " " + e.Path + ": " + e.Err.Error()
}
func (e *PathError) Unwrap() error {
return e.Err
}
// LinkError records an error during a link or symlink or rename system call and
// the paths that caused it.
type LinkError struct {
Op string
Old string
New string
Err error
}
func (e *LinkError) Error() string {
return e.Op + " " + e.Old + " " + e.New + ": " + e.Err.Error()
}
func (e *LinkError) Unwrap() error {
return e.Err
}
const (
O_RDONLY int = syscall.O_RDONLY
O_WRONLY int = syscall.O_WRONLY
+2
View File
@@ -21,6 +21,8 @@ var (
Stderr = &File{unixFileHandle(syscall.Stderr), "/dev/stderr"}
)
const DevNull = "/dev/null"
// isOS indicates whether we're running on a real operating system with
// filesystem support.
const isOS = true
+4
View File
@@ -48,3 +48,7 @@ func (f stdioFileHandle) Close() error {
//go:linkname putchar runtime.putchar
func putchar(c byte)
func Pipe() (r *File, w *File, err error) {
return nil, nil, ErrNotImplemented
}
+19
View File
@@ -2,4 +2,23 @@
package os
import "syscall"
type syscallFd = int
func Pipe() (r *File, w *File, err error) {
var p [2]int
err = handleSyscallError(syscall.Pipe2(p[:], syscall.O_CLOEXEC))
if err != nil {
return
}
r = &File{
handle: unixFileHandle(p[0]),
name: "|0",
}
w = &File{
handle: unixFileHandle(p[1]),
name: "|1",
}
return
}
+17
View File
@@ -5,3 +5,20 @@ package os
import "syscall"
type syscallFd = syscall.Handle
func Pipe() (r *File, w *File, err error) {
var p [2]syscall.Handle
e := handleSyscallError(syscall.Pipe(p[:]))
if e != nil {
return nil, nil, err
}
r = &File{
handle: unixFileHandle(p[0]),
name: "|0",
}
w = &File{
handle: unixFileHandle(p[1]),
name: "|1",
}
return
}