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
|
package syscall
|
||||||
|
|
||||||
const (
|
const (
|
||||||
LLGoPackage = "decl"
|
LLGoPackage = "noinit"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Errno = uintptr
|
type Errno = uintptr
|
||||||
@@ -25,3 +25,8 @@ type Errno = uintptr
|
|||||||
// A Signal is a number describing a process signal.
|
// A Signal is a number describing a process signal.
|
||||||
// It implements the os.Signal interface.
|
// It implements the os.Signal interface.
|
||||||
type Signal = int
|
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
|
package os
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"syscall"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/goplus/llgo/c/syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
func fillFileStatFromSys(fs *fileStat, name string) {
|
func fillFileStatFromSys(fs *fileStat, name string) {
|
||||||
|
|||||||
@@ -6,12 +6,15 @@
|
|||||||
|
|
||||||
package os
|
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.
|
// Stat returns the FileInfo structure describing file.
|
||||||
// If there is an error, it will be of type *PathError.
|
// If there is an error, it will be of type *PathError.
|
||||||
func (f *File) Stat() (FileInfo, error) {
|
func (f *File) Stat() (FileInfo, error) {
|
||||||
/* TODO(xsw):
|
|
||||||
if f == nil {
|
if f == nil {
|
||||||
return nil, ErrInvalid
|
return nil, ErrInvalid
|
||||||
}
|
}
|
||||||
@@ -22,8 +25,6 @@ func (f *File) Stat() (FileInfo, error) {
|
|||||||
}
|
}
|
||||||
fillFileStatFromSys(&fs, f.name)
|
fillFileStatFromSys(&fs, f.name)
|
||||||
return &fs, nil
|
return &fs, nil
|
||||||
*/
|
|
||||||
panic("todo: os.File.Stat")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// statNolog stats a file with no test logging.
|
// statNolog stats a file with no test logging.
|
||||||
|
|||||||
@@ -7,8 +7,9 @@
|
|||||||
package os
|
package os
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"syscall"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/goplus/llgo/internal/lib/syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A fileStat is the implementation of FileInfo returned by Stat and Lstat.
|
// A fileStat is the implementation of FileInfo returned by Stat and Lstat.
|
||||||
|
|||||||
Reference in New Issue
Block a user