blob: 8f6baf11146560b2afabecd50b62b5a335bd1590 (
plain)
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
|
; **************************************************************************** ;
; ;
; ::: :::::::: ;
; ft_read.s :+: :+: :+: ;
; +:+ +:+ +:+ ;
; By: cacharle <marvin@42.fr> +;+ +:+ +;+ ;
; +;+;+;+;+;+ +;+ ;
; Created: 2019/11/22 03:04:44 by cacharle ;+; ;+; ;
; Updated: 2019/11/22 21:19:13 by cacharle ;;; ;;;;;;;;.fr ;
; ;
; **************************************************************************** ;
%include "libasm.s"
%ifdef __LINUX__
%define M_FT_READ ft_read
%define M_ERRNO_LOCATION __errno_location
%define M_SYSCALL_READ 0x0
%else
%define M_FT_READ _ft_read
%define M_ERRNO_LOCATION ___error
%define M_SYSCALL_READ 0x2000003
%endif
extern M_ERRNO_LOCATION
global M_FT_READ
section .text
; int ft_read(int, void*, size_t);
M_FT_READ:
mov rax, M_SYSCALL_READ
syscall
%ifdef __LINUX__
cmp rax, 0
jl FT_READ_ERROR
%else
jc FT_READ_ERROR
%endif
ret
FT_READ_ERROR:
%ifdef __LINUX__
neg rax
%endif
push rax
call M_ERRNO_LOCATION M_EXTERN_CALL_SUFFIX
pop qword [rax]
mov rax, -1
ret
|