aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/os/file.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/os/file.go')
-rw-r--r--libgo/go/os/file.go20
1 files changed, 19 insertions, 1 deletions
diff --git a/libgo/go/os/file.go b/libgo/go/os/file.go
index 52dd943..e717f17 100644
--- a/libgo/go/os/file.go
+++ b/libgo/go/os/file.go
@@ -44,11 +44,13 @@ import (
"errors"
"internal/poll"
"internal/testlog"
+ "internal/unsafeheader"
"io"
"io/fs"
"runtime"
"syscall"
"time"
+ "unsafe"
)
// Name returns the name of the file as presented to Open.
@@ -246,7 +248,12 @@ func (f *File) Seek(offset int64, whence int) (ret int64, err error) {
// WriteString is like Write, but writes the contents of string s rather than
// a slice of bytes.
func (f *File) WriteString(s string) (n int, err error) {
- return f.Write([]byte(s))
+ var b []byte
+ hdr := (*unsafeheader.Slice)(unsafe.Pointer(&b))
+ hdr.Data = (*unsafeheader.String)(unsafe.Pointer(&s)).Data
+ hdr.Cap = len(s)
+ hdr.Len = len(s)
+ return f.Write(b)
}
// Mkdir creates a new directory with the specified name and permission
@@ -644,6 +651,17 @@ func (dir dirFS) Open(name string) (fs.File, error) {
return f, nil
}
+func (dir dirFS) Stat(name string) (fs.FileInfo, error) {
+ if !fs.ValidPath(name) || runtime.GOOS == "windows" && containsAny(name, `\:`) {
+ return nil, &PathError{Op: "stat", Path: name, Err: ErrInvalid}
+ }
+ f, err := Stat(string(dir) + "/" + name)
+ if err != nil {
+ return nil, err
+ }
+ return f, nil
+}
+
// ReadFile reads the named file and returns the contents.
// A successful call returns err == nil, not err == EOF.
// Because ReadFile reads the whole file, it does not treat an EOF from Read