「✨」 feat(strdup): yayy :D
This commit is contained in:
1
Makefile
1
Makefile
@@ -40,6 +40,7 @@ re: fclean
|
|||||||
$(MAKE) -s all
|
$(MAKE) -s all
|
||||||
|
|
||||||
test: $(OBJ)
|
test: $(OBJ)
|
||||||
|
rm -f out
|
||||||
$(t_CC) $(OBJ) $(t_SRC) $(t_CFLAGS) -o $(t_NAME)
|
$(t_CC) $(OBJ) $(t_SRC) $(t_CFLAGS) -o $(t_NAME)
|
||||||
|
|
||||||
.PHONY: clean fclean all re
|
.PHONY: clean fclean all re
|
||||||
|
|||||||
31
src/mem/ft_strdup.s
Normal file
31
src/mem/ft_strdup.s
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
section .text
|
||||||
|
global ft_strdup
|
||||||
|
|
||||||
|
extern malloc
|
||||||
|
extern ft_strlen
|
||||||
|
extern ft_strcpy
|
||||||
|
|
||||||
|
; char *ft_strdup(const char *str)
|
||||||
|
ft_strdup:
|
||||||
|
cmp rdi, 0
|
||||||
|
je .endz
|
||||||
|
|
||||||
|
push rdi
|
||||||
|
call ft_strlen
|
||||||
|
dec rax
|
||||||
|
|
||||||
|
mov rdi, rax
|
||||||
|
call malloc
|
||||||
|
|
||||||
|
mov rdx, rdi
|
||||||
|
mov rdi, rax
|
||||||
|
pop rsi
|
||||||
|
call ft_strcpy
|
||||||
|
|
||||||
|
jmp .end
|
||||||
|
|
||||||
|
.endz:
|
||||||
|
mov rax, 0
|
||||||
|
|
||||||
|
.end:
|
||||||
|
ret
|
||||||
@@ -3,6 +3,7 @@ char *ft_strcpy(char *dest, const char *src);
|
|||||||
int ft_strcmp(const char *s1, const char *s2);
|
int ft_strcmp(const char *s1, const char *s2);
|
||||||
int ft_write(int fd, const char *buf, unsigned int count);
|
int ft_write(int fd, const char *buf, unsigned int count);
|
||||||
int ft_read(int fd, char *buf, unsigned int count);
|
int ft_read(int fd, char *buf, unsigned int count);
|
||||||
|
char *ft_strdup(const char *str);
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@@ -49,5 +50,7 @@ int main(void)
|
|||||||
printf("| %d _ 42 | %d : %s\n", fd, ft_read(fd, xd, 42), xd);
|
printf("| %d _ 42 | %d : %s\n", fd, ft_read(fd, xd, 42), xd);
|
||||||
|
|
||||||
printf("\n--- ft_strdup ---\n");
|
printf("\n--- ft_strdup ---\n");
|
||||||
printf("HELL NAH\n");
|
printf("%s\n", ft_strdup("this is a very cool test yayy"));
|
||||||
|
printf("%s\n", ft_strdup("hi"));
|
||||||
|
printf("%s\n", ft_strdup(NULL));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user