42_libasm/src/ft_strdup.asm

27 lines
481 B
NASM

extern ft_strlen
extern malloc
extern ft_strcpy
section .text
global ft_strdup
ft_strdup:
call ft_strlen
mov rbx, rdi
mov rdi, rax
call malloc wrt ..plt
cmp rax, 0
je error
mov rdi, rax
mov rsi, rbx
call ft_strcpy
ret
error:
xor rax, rax
ret