Files
libasm/srcs/ft_strdup.s

38 lines
499 B
ArmAsm

global ft_strdup
extern malloc
extern ft_strcpy
extern ft_strlen
extern __errno_location
section .text
ft_strdup:
test rdi, rdi ; test if arg is NULL
jz .err
push rdi ;push to use it for the strcpy
call ft_strlen
inc rax
mov rdi, rax
call malloc wrt ..plt
test rax, rax
jz .malloc_failed
mov rdi, rax
pop rsi
sub rsp, 8
call ft_strcpy
add rsp, 8
ret
.malloc_failed:
sub rsp, 8
call __errno_location wrt ..plt
add rsp, 8
mov dword [rax], 12
pop rax
.err:
xor rax, rax
ret