extend stdlib to allow import of more packages (#1099)

* stdlib: extend stdlib to allow import of more packages
This commit is contained in:
Cornel
2020-06-23 12:56:28 +03:00
committed by GitHub
parent de45da5df4
commit 720a54a0fe
16 changed files with 549 additions and 13 deletions
+5
View File
@@ -0,0 +1,5 @@
package os
func Getenv(key string) string {
return ""
}
+39
View File
@@ -0,0 +1,39 @@
package os
import (
"errors"
)
var (
ErrInvalid = errors.New("invalid argument")
ErrPermission = errors.New("permission denied")
ErrClosed = errors.New("file already closed")
// Portable analogs of some common system call errors.
// Note that these are exported for use in the Filesystem interface.
ErrUnsupported = errors.New("operation not supported")
ErrNotImplemented = errors.New("operation not implemented")
ErrNotExist = errors.New("file not found")
ErrExist = errors.New("file exists")
)
func IsPermission(err error) bool {
return err == ErrPermission
}
func NewSyscallError(syscall string, err error) error {
if err == nil {
return nil
}
return &SyscallError{syscall, err}
}
// SyscallError records an error from a specific system call.
type SyscallError struct {
Syscall string
Err error
}
func (e *SyscallError) Error() string { return e.Syscall + ": " + e.Err.Error() }
func (e *SyscallError) Unwrap() error { return e.Err }
+6
View File
@@ -0,0 +1,6 @@
package os
type Signal interface {
String() string
Signal() // to distinguish from other Stringers
}
+20 -11
View File
@@ -6,16 +6,7 @@
package os
import (
"errors"
)
// Portable analogs of some common system call errors.
// Note that these are exported for use in the Filesystem interface.
var (
ErrUnsupported = errors.New("operation not supported")
ErrNotImplemented = errors.New("operation not implemented")
ErrNotExist = errors.New("file not found")
ErrExist = errors.New("file exists")
"syscall"
)
// Mkdir creates a directory. If the operation fails, it will return an error of
@@ -91,6 +82,10 @@ func (f *File) Read(b []byte) (n int, err error) {
return
}
func (f *File) ReadAt(b []byte, off int64) (n int, err error) {
return 0, ErrNotImplemented
}
// Write writes len(b) bytes to the File. It returns the number of bytes written
// and an error, if any. Write returns a non-nil error when n != len(b).
func (f *File) Write(b []byte) (n int, err error) {
@@ -125,6 +120,20 @@ func (f *File) Stat() (FileInfo, error) {
return nil, &PathError{"stat", f.name, ErrNotImplemented}
}
// Sync is a stub, not yet implemented
func (f *File) Sync() error {
return ErrNotImplemented
}
func (f *File) SyscallConn() (syscall.RawConn, error) {
return nil, ErrNotImplemented
}
// Fd returns the file handle referencing the open file.
func (f *File) Fd() uintptr {
panic("unimplemented: os.file.Fd()")
}
const (
PathSeparator = '/' // OS-specific path separator
PathListSeparator = ':' // OS-specific path list separator
@@ -194,7 +203,7 @@ type FileInfo interface {
Name() string // base name of the file
Size() int64 // length in bytes for regular files; system-dependent for others
Mode() FileMode // file mode bits
// ModTime() time.Time // modification time
// TODO ModTime() time.Time // modification time
IsDir() bool // abbreviation for Mode().IsDir()
Sys() interface{} // underlying data source (can return nil)
}
+5
View File
@@ -0,0 +1,5 @@
package os
func Hostname() (name string, err error) {
return "", ErrNotImplemented
}