Merge pull request #612 from xushiwei/q

library: os.ReadFile
This commit is contained in:
xushiwei
2024-07-30 17:18:28 +08:00
committed by GitHub
5 changed files with 40 additions and 7 deletions

View 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)
}

View File

@@ -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)
}

View File

@@ -5,8 +5,9 @@
package os
import (
"syscall"
"time"
"github.com/goplus/llgo/c/syscall"
)
func fillFileStatFromSys(fs *fileStat, name string) {

View File

@@ -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.

View File

@@ -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.