-
-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathperror.src
More file actions
59 lines (52 loc) · 1.07 KB
/
perror.src
File metadata and controls
59 lines (52 loc) · 1.07 KB
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
.assume adl=1
;-------------------------------------------------------------------------------
.section .text
.global _perror
.type _perror, @function
; void perror(const char*)
_perror:
pop de
ex (sp), hl
push de
add hl, bc
xor a, a
sbc hl, bc
jr z, .L.null_string
cp a, (hl)
jr z, .L.empty_string
; fprintf(stderr, "%s: ", str)
call .L.errchar_puts
ld hl, _perror_colon_space_str
call .L.errchar_puts
.L.null_string:
.L.empty_string:
ld hl, (_errno)
call _strerror.hijack_hl
call .L.errchar_puts
ld a, $0A ; '\n'
.L.errchar_putchar:
; input:
; - A = character to display
; - HL = nul terminated string to display afterward
; output:
; - HL points to nul terminator
push hl
ld l, a
push hl
call _errchar
pop hl
pop hl
.L.errchar_puts:
ld a, (hl)
or a, a
ret z
inc hl
jr .L.errchar_putchar
.extern _errno
.extern _errchar
.extern _strerror.hijack_hl
;-------------------------------------------------------------------------------
.section .rodata._perror_colon_space_str
.local _perror_colon_space_str
_perror_colon_space_str:
.asciz ": "