add: strdup

This commit is contained in:
starnakin 2024-09-03 10:37:12 +02:00
parent 3632b34e40
commit b3a4690a85
2 changed files with 29 additions and 1 deletions

View File

@ -7,3 +7,4 @@ char *ft_strcpy(char *dest, const char *src);
size_t ft_strlen(const char *str);
int ft_strcmp( const char *first, const char *second);
ssize_t ft_write(int fd, const void *buf, size_t count);
char *ft_strdup(const char *s);

27
src/ft_strdup.asm Normal file
View File

@ -0,0 +1,27 @@
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
cmp rax, 0
je error
mov rdi, rax
mov rsi, rbx
call ft_strcpy
ret
error:
xor rax, rax
ret