Implemented stat syscall
This commit is contained in:
parent
392b35423f
commit
53ecf40229
6 changed files with 69 additions and 0 deletions
27
lib/fs/fs.q
Normal file
27
lib/fs/fs.q
Normal file
|
@ -0,0 +1,27 @@
|
|||
import mem
|
||||
import sys
|
||||
|
||||
readFile(path []byte) -> (*byte, int) {
|
||||
stat := new(sys.file_stat)
|
||||
|
||||
if sys.stat(path, stat) < 0 {
|
||||
return 0, 0
|
||||
}
|
||||
|
||||
size := stat.st_size
|
||||
|
||||
if size < 512 {
|
||||
size = 512
|
||||
}
|
||||
|
||||
file := sys.open(path, 0, 0)
|
||||
|
||||
if file < 0 {
|
||||
return 0, 0
|
||||
}
|
||||
|
||||
contents := mem.alloc(size)
|
||||
length := sys.read(file, contents, size)
|
||||
sys.close(file)
|
||||
return contents, length
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue