1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
include 'sys.asm'
format ELF64 executable
segment writable readable
struc db [data]
{
common
. db data
.size = $ - .
}
stat_msg db 'Get file stats', 10
open_msg db 'Open file', 10
read_msg db 'Read file', 10
close_msg db 'Close file', 10
msg_dn db ':', 10
indexname db 'index.html'
;; indexstat stat
indexlen rq 1
indexfd dd 0
indexbuf dd ?
indexbuf_len rq 1
segment readable executable
entry _main
_main:
ls_write STDOUT, open_msg, open_msg.size
ls_open indexname, O_RDONLY, 0
mov qword [indexfd], rax
cmp [indexfd], 0
jl error
ls_write STDOUT, read_msg, read_msg.size
ls_read qword [indexfd], indexbuf, indexbuf_len
cmp qword rax, 0
jl error
mov [indexlen], rax
ls_write STDOUT, close_msg, close_msg.size
ls_close qword [indexfd]
cmp qword rax, 0
jl error
ls_write STDOUT, indexname, indexname.size
ls_write STDOUT, msg_dn, msg_dn.size
ls_write STDOUT, indexbuf, [indexlen]
cmp qword rax, 0
jl error
ls_exit 0
error:
ls_close qword [indexfd]
ls_exit 1
|