add: strdup
This commit is contained in:
parent
3632b34e40
commit
b3a4690a85
@ -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
27
src/ft_strdup.asm
Normal 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
|
Loading…
Reference in New Issue
Block a user