aboutsummaryrefslogtreecommitdiff
path: root/ft_read.s
blob: 2891045faf39378649ca9e71a28781bebe4b43cb (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
; **************************************************************************** ;
;                                                                              ;
;                                                         :::      ::::::::    ;
;    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        ;
;                                                                              ;
; **************************************************************************** ;

%ifdef __LINUX__
    %define M_FT_READ ft_read
    %define M_ERRNO_LOCATION __errno_location  wrt ..plt
    %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
    pop  qword [rax]
    mov  rax, -1
    ret