mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 11:37:46 +00:00
WASI & darwin: support basic file io based on libc
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
This commit is contained in:
committed by
Ron Evans
parent
6d3c11627c
commit
1406453350
Vendored
+38
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
_, err := os.Open("non-exist")
|
||||
if !os.IsNotExist(err) {
|
||||
panic("should be non exist error")
|
||||
}
|
||||
|
||||
f, err := os.Open("testdata/libc/filesystem.txt")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err := f.Close(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// read after close: error should be returned
|
||||
_, err := f.Read(make([]byte, 10))
|
||||
if err == nil {
|
||||
panic("error expected for reading after closing files")
|
||||
}
|
||||
}()
|
||||
|
||||
data, err := ioutil.ReadAll(f)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
print(string(data))
|
||||
|
||||
}
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
abcdefg
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
Reference in New Issue
Block a user