works
This commit is contained in:
parent
3efbeb3903
commit
cae367e0fc
7 changed files with 51 additions and 63 deletions
|
|
@ -105,13 +105,6 @@ test: $(NAME) test.c
|
|||
@gcc test.c -I $(INC_DIR) -L. -lfts -o test
|
||||
@printf "\r\033[38;5;117m✓ MAKE test\033[0m\033[K\n"
|
||||
|
||||
debug: $(NAME) debug.c
|
||||
@gcc debug.c -I $(INC_DIR) -L. -lfts -o debug
|
||||
@printf "\r\033[38;5;117m✓ MAKE debug\033[0m\033[K\n"
|
||||
|
||||
run-dbg: debug
|
||||
lldb ./debug
|
||||
|
||||
.PHONY : fclean clean re run-gdb
|
||||
|
||||
-include $(OBJS:.o=.d)
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
#include "libft.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ft_puts("h2g2");
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -1,10 +1,8 @@
|
|||
global _ft_cat
|
||||
global ft_cat
|
||||
|
||||
extern ft_putchar
|
||||
|
||||
%define STDOUT 1
|
||||
%define BUFF_SIZE 10
|
||||
%define BUFF_SIZE 1024
|
||||
|
||||
section .bss
|
||||
buf: resb BUFF_SIZE
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ ft_putchar:
|
|||
|
||||
; success case then return c
|
||||
pop rax
|
||||
movzx rax, al ; cast to char
|
||||
ret
|
||||
|
||||
err:
|
||||
|
|
|
|||
|
|
@ -12,19 +12,24 @@ ft_strdup:
|
|||
mov rax, 0
|
||||
cmp rdi, 0
|
||||
je end
|
||||
|
||||
push rdi
|
||||
call _ft_strlen
|
||||
inc rax
|
||||
push rax
|
||||
mov rdi, rax
|
||||
|
||||
sub rsp, 8 ; align stack to 16 bytes, x86_64 or mach don't know
|
||||
call _malloc
|
||||
add rsp, 8
|
||||
|
||||
pop rcx
|
||||
pop rsi
|
||||
cmp rax, 0
|
||||
je end
|
||||
|
||||
mov rdi, rax
|
||||
pop rcx
|
||||
pop rsi
|
||||
cld
|
||||
cld ; clear the directon flag
|
||||
rep movsb
|
||||
end:
|
||||
ret
|
||||
|
|
|
|||
|
|
@ -3,14 +3,16 @@ global ft_strlen
|
|||
|
||||
_ft_strlen:
|
||||
ft_strlen:
|
||||
mov rax, 0
|
||||
cmp rdi, 0
|
||||
je end
|
||||
loop:
|
||||
cmp byte [rdi], 0
|
||||
je end
|
||||
inc rax
|
||||
inc rdi
|
||||
jmp loop
|
||||
mov rax, 0
|
||||
cmp rdi, 0
|
||||
je end
|
||||
t
|
||||
mov rcx, -1
|
||||
cld
|
||||
repnz scasb
|
||||
|
||||
not rcx
|
||||
lea rax, [rcx - 1]
|
||||
|
||||
end:
|
||||
ret
|
||||
|
|
|
|||
|
|
@ -6,11 +6,6 @@ int ft_putstr(const char *str)
|
|||
return (write(1, str, strlen(str)));
|
||||
}
|
||||
|
||||
/* int ft_putchar(const char c) */
|
||||
/* { */
|
||||
/* return (write(1, &c, 1)); */
|
||||
/* } */
|
||||
|
||||
int ft_putnstr(const char *str, size_t n)
|
||||
{
|
||||
return (write(1, str, n));
|
||||
|
|
@ -400,26 +395,26 @@ int test_strdup()
|
|||
}
|
||||
str = ft_strdup("Coucou");
|
||||
str_cmp = strdup("Coucou");
|
||||
/* len = strlen(str); */
|
||||
/* len_cmp = strlen(str_cmp); */
|
||||
/* if (len != len_cmp) */
|
||||
/* { */
|
||||
/* printf("FAILED: len is %d vs %d\n", len, len_cmp); */
|
||||
/* return (1); */
|
||||
/* } */
|
||||
/* i = -1; */
|
||||
/* while (++i < len) */
|
||||
/* { */
|
||||
/* if (str[i] != str_cmp[i]) */
|
||||
/* { */
|
||||
/* ft_putnstr(str, len); */
|
||||
/* ft_putnstr(str_cmp, len); */
|
||||
/* printf("FAILED: %c vs %c\n", str[i], str_cmp[i]); */
|
||||
/* return (1); */
|
||||
/* } */
|
||||
/* } */
|
||||
/* free(str); */
|
||||
/* free(str_cmp); */
|
||||
len = strlen(str);
|
||||
len_cmp = strlen(str_cmp);
|
||||
if (len != len_cmp)
|
||||
{
|
||||
printf("FAILED: len is %d vs %d\n", len, len_cmp);
|
||||
return (1);
|
||||
}
|
||||
i = -1;
|
||||
while (++i < len)
|
||||
{
|
||||
if (str[i] != str_cmp[i])
|
||||
{
|
||||
ft_putnstr(str, len);
|
||||
ft_putnstr(str_cmp, len);
|
||||
printf("FAILED: %c vs %c\n", str[i], str_cmp[i]);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
free(str);
|
||||
free(str_cmp);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -427,13 +422,15 @@ int test_strdup()
|
|||
int test_cat(char ** argv)
|
||||
{
|
||||
ft_putstr(__func__); ft_putstr(":\n");
|
||||
|
||||
/* ft_putstr("Wait for a user input:\n"); */
|
||||
/* ft_cat(0); */
|
||||
ft_putstr("\ntest.c:\n");
|
||||
ft_cat(open(__FILE__, O_RDONLY));
|
||||
ft_putstr("\ntest binary:\n");
|
||||
ft_cat(open(argv[0], O_RDONLY));
|
||||
ft_cat(-42);
|
||||
|
||||
/* ft_putstr("\ntest.c:\n"); */
|
||||
/* ft_cat(open(__FILE__, O_RDONLY)); */
|
||||
|
||||
/* ft_putstr("\ntest binary:\n"); */
|
||||
/* ft_cat(open("test", O_RDONLY)); */
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
@ -510,16 +507,15 @@ int main(int argc, char **argv)
|
|||
test_memcpy() ||
|
||||
test_strdup())
|
||||
return (1);
|
||||
exit(1);
|
||||
ft_putstr("\nPART BONUS:\n_______\n");
|
||||
if (test_isupper() ||
|
||||
test_islower() ||
|
||||
test_isupper())
|
||||
/* test_putchar()) */
|
||||
test_isupper() ||
|
||||
test_putchar())
|
||||
return (1);
|
||||
ft_putstr("\nPART 3:\n_______\n");
|
||||
if (test_cat(argv))
|
||||
return (1);
|
||||
puts("\033c\n\033[38;5;117mALL PASSED:\n___________\n\033[0m");
|
||||
puts("\033c\n\033[38;5;117mALL PASSED\n___________\n\033[0m");
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue