From cd5c9e6a923878e797212d27476ee217eb844a14 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Thu, 11 Feb 2021 15:40:48 +0100 Subject: Added Linux compatibility --- ft_read.s | 56 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'ft_read.s') diff --git a/ft_read.s b/ft_read.s index f65ade3..7f8c5db 100644 --- a/ft_read.s +++ b/ft_read.s @@ -10,38 +10,38 @@ ; ; ; **************************************************************************** ; -global _ft_read +%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 -%define F_GETFD 1 -%define SYSCALL_READ 0x2000003 -%define SYSCALL_FCNTL 0x200005c +extern M_ERRNO_LOCATION -; int ft_read(int, void*, size_t); -_ft_read: - cmp rdx, 0 - je FT_READ_NO_SIZE - cmp rdi, 0 - jl FT_READ_ERROR - cmp rsi, 0 - je FT_READ_ERROR - - push rdx - push rsi - xor rsi, rsi - mov esi, F_GETFD - mov rax, SYSCALL_FCNTL - syscall - pop rsi - pop rdx - cmp eax, 0 - jne FT_READ_ERROR +global M_FT_READ - mov rax, SYSCALL_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: - mov rax, -1 - ret -FT_READ_NO_SIZE: - xor rax, rax +%ifdef __LINUX__ + neg rax +%endif + push rax + call M_ERRNO_LOCATION wrt ..plt + pop qword [rax] + mov rax, -1 ret -- cgit