library: os.ReadFile
This commit is contained in:
25
_cmptest/readfiledemo/readf.go
Normal file
25
_cmptest/readfiledemo/readf.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fileName := "err.log"
|
||||
os.WriteFile(fileName, []byte("123"), 0644)
|
||||
|
||||
_, err := os.Stat(fileName)
|
||||
if os.IsNotExist(err) {
|
||||
fmt.Fprintf(os.Stderr, "File %s not found\n", fileName)
|
||||
return
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(fileName)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "ReadFile: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("%s\n", data)
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
package syscall
|
||||
|
||||
const (
|
||||
LLGoPackage = "decl"
|
||||
LLGoPackage = "noinit"
|
||||
)
|
||||
|
||||
type Errno = uintptr
|
||||
@@ -25,3 +25,8 @@ type Errno = uintptr
|
||||
// A Signal is a number describing a process signal.
|
||||
// It implements the os.Signal interface.
|
||||
type Signal = int
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
@@ -5,8 +5,9 @@
|
||||
package os
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/goplus/llgo/c/syscall"
|
||||
)
|
||||
|
||||
func fillFileStatFromSys(fs *fileStat, name string) {
|
||||
|
||||
@@ -6,12 +6,15 @@
|
||||
|
||||
package os
|
||||
|
||||
import "syscall"
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/os"
|
||||
"github.com/goplus/llgo/internal/lib/syscall"
|
||||
)
|
||||
|
||||
// Stat returns the FileInfo structure describing file.
|
||||
// If there is an error, it will be of type *PathError.
|
||||
func (f *File) Stat() (FileInfo, error) {
|
||||
/* TODO(xsw):
|
||||
if f == nil {
|
||||
return nil, ErrInvalid
|
||||
}
|
||||
@@ -22,8 +25,6 @@ func (f *File) Stat() (FileInfo, error) {
|
||||
}
|
||||
fillFileStatFromSys(&fs, f.name)
|
||||
return &fs, nil
|
||||
*/
|
||||
panic("todo: os.File.Stat")
|
||||
}
|
||||
|
||||
// statNolog stats a file with no test logging.
|
||||
|
||||
@@ -7,8 +7,9 @@
|
||||
package os
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/goplus/llgo/internal/lib/syscall"
|
||||
)
|
||||
|
||||
// A fileStat is the implementation of FileInfo returned by Stat and Lstat.
|
||||
|
||||
Reference in New Issue
Block a user