22 lines
500 B
ArmAsm
22 lines
500 B
ArmAsm
extern __errno_location
|
|
|
|
section .text
|
|
global ft_read
|
|
|
|
ft_read:
|
|
mov rax, 0 ; syscall read, other arguments should be good accord to calling convention
|
|
syscall
|
|
cmp eax, -1 ; linux syscalls errors are always in the range -4095 to -1
|
|
jg .done
|
|
cmp eax, -4095
|
|
jl .done
|
|
mov rbx, rax ; save return value of syscall
|
|
call __errno_location ; put address of errno in rax
|
|
neg rbx ; errno should be positive
|
|
mov [rax], rbx ; set errno
|
|
mov rax, -1 ; set return value of ft_read to -1
|
|
ret
|
|
|
|
.done:
|
|
ret
|