write_file

This commit is contained in:
IgorCielniak
2025-12-18 11:32:35 +01:00
parent 6efd7c4e19
commit 50451840b7
32 changed files with 3064 additions and 24 deletions

33
test_read_file.sl Normal file
View File

@@ -0,0 +1,33 @@
import stdlib/stdlib.sl
import stdlib/io.sl
: main
"/etc/hostname" # (len addr)
swap # (addr len)
read_file # (file_len file_addr)
dup 0 > if # if file_len > 0, success
write_buf # print file contents (file_len file_addr)
0
exit
then
dup -2 == if # open() failed
drop
"open() failed: errno=" puts
swap puts
exit
then
dup -1 == if # fstat() failed
drop
"fstat() failed: errno=" puts
swap puts
exit
then
dup -3 == if # mmap() failed
drop
"mmap() failed" puts
exit
then
"unknown read_file failure" puts
dup # file_len file_len file_addr
exit # Exit with returned file_len as the program exit code (debug)
;