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_strdup.s | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'ft_strdup.s') diff --git a/ft_strdup.s b/ft_strdup.s index a31f36f..346f2b4 100644 --- a/ft_strdup.s +++ b/ft_strdup.s @@ -10,30 +10,42 @@ ; ; ; **************************************************************************** ; -extern _ft_strlen -extern _ft_strcpy -extern _malloc - -global _ft_strdup +%ifdef __LINUX__ + %define M_FT_STRDUP ft_strdup + %define M_FT_STRLEN ft_strlen + %define M_FT_STRCPY ft_strcpy + %define M_MALLOC malloc +%else + %define M_FT_STRDUP _ft_strdup + %define M_FT_STRLEN _ft_strlen + %define M_FT_STRCPY _ft_strcpy + %define M_MALLOC _malloc +%endif + +extern M_FT_STRLEN +extern M_FT_STRCPY +extern M_MALLOC + +global M_FT_STRDUP + +section .text ; char *ft_strdup(const char *str); -_ft_strdup: +M_FT_STRDUP: push rdi ; save rdi because it will be overwrite for malloc - call _ft_strlen ; rdi is still == str + call M_FT_STRLEN ; rdi is still == str inc rax ; len++ for '\0' mov rdi, rax ; size to malloc - call _malloc + call M_MALLOC wrt ..plt cmp rax, 0 je FT_STRDUP_ERROR pop rsi ; original str as src mov rdi, rax ; allocated as dest - call _ft_strcpy + call M_FT_STRCPY ret FT_STRDUP_ERROR: pop rdi ret - - -- cgit