fix(read): fixing the infinite loop on the read function
- The original will infinite loop
This commit is contained in:
parent
d55c035b97
commit
d93443fb91
1 changed files with 7 additions and 2 deletions
|
|
@ -5,11 +5,13 @@ section .text
|
|||
global ft_read
|
||||
|
||||
ft_read:
|
||||
cmp rsi, 0 ; check if the buffer is NULL
|
||||
je .exit ; if true go to exit
|
||||
mov rax, 0 ; syscall 0 is for read
|
||||
syscall ; call the system call read
|
||||
cmp rax, 0 ; check if the return value of syscall
|
||||
jl .error ; jump if the syscall return less than 0
|
||||
ret ; return the value of the syscall
|
||||
jmp .exit ; jump to exit
|
||||
|
||||
.error:
|
||||
mov rdi, rax ; stock errno value in rdi
|
||||
|
|
@ -17,4 +19,7 @@ ft_read:
|
|||
call __errno_location ; rax = &errno
|
||||
mov [rax], edi ; stock the errno return in the address of rax
|
||||
mov rax, -1 ; set the value of rax to -1
|
||||
ret ; return with -1 (and errno value)
|
||||
jmp .exit ; jump to exit
|
||||
|
||||
.exit:
|
||||
ret
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue