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_write.s | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'ft_write.s') diff --git a/ft_write.s b/ft_write.s index 62616c5..01ba580 100644 --- a/ft_write.s +++ b/ft_write.s @@ -10,38 +10,38 @@ ; ; ; **************************************************************************** ; -global _ft_write +%ifdef __LINUX__ + %define M_FT_WRITE ft_write + %define M_ERRNO_LOCATION __errno_location + %define M_SYSCALL_WRITE 0x1 +%else + %define M_FT_WRITE _ft_write + %define M_ERRNO_LOCATION ___error + %define M_SYSCALL_WRITE 0x2000004 +%endif -%define F_GETFD 1 -%define SYSCALL_WRITE 0x2000004 -%define SYSCALL_FCNTL 0x200005c +extern M_ERRNO_LOCATION -; int ft_write(int rdi, const void *rsi, size_t rdx); -_ft_write: - cmp rdx, 0 - je FT_WRITE_NO_SIZE - cmp rdi, 0 - jl FT_WRITE_ERROR ; fd < 0 - cmp rsi, 0 - je FT_WRITE_ERROR ; buf == NULL - - 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_WRITE_ERROR +global M_FT_WRITE - mov rax, SYSCALL_WRITE +section .text +; int ft_write(int rdi, const void *rsi, size_t rdx); +M_FT_WRITE: + mov rax, M_SYSCALL_WRITE syscall +%ifdef __LINUX__ + cmp rax, 0 + jl FT_WRITE_ERROR +%else + jc FT_WRITE_ERROR +%endif ret FT_WRITE_ERROR: +%ifdef __LINUX__ + neg rax +%endif + push rax + call M_ERRNO_LOCATION wrt ..plt + pop qword [rax] mov rax, -1 ret -FT_WRITE_NO_SIZE: - mov rax, 0 - ret -- cgit