|
|
|
|
@@ -1,41 +1,66 @@
|
|
|
|
|
int ft_strlen(char *str);
|
|
|
|
|
char *ft_strcpy(char *dest, const char *src);
|
|
|
|
|
int ft_strcmp(const char *s1, const char *s2);
|
|
|
|
|
int ft_write(int fd, const char *buf, unsigned int count);
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
ssize_t ft_strlen(char *str);
|
|
|
|
|
char *ft_strcpy(char *dest, const char *src);
|
|
|
|
|
int ft_strcmp(const char *s1, const char *s2);
|
|
|
|
|
ssize_t ft_write(int fd, const char *buf, unsigned int count);
|
|
|
|
|
ssize_t ft_read(int fd, char *buf, unsigned int count);
|
|
|
|
|
char *ft_strdup(const char *str);
|
|
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
|
{
|
|
|
|
|
printf("\n--- ft_strlen ---\n");
|
|
|
|
|
printf("arg : \"i love kissing girls\" | result : %d\n", ft_strlen("i love kissing girls"));
|
|
|
|
|
printf("arg : NULL | result : %d\n", ft_strlen(NULL));
|
|
|
|
|
printf("arg : \"\" | result : %d\n", ft_strlen(""));
|
|
|
|
|
printf("arg: \"i love kissing girls\" | result: %ld (expected: %ld)\n", ft_strlen("i love kissing girls"), strlen("i love kissing girls"));
|
|
|
|
|
printf("arg: \"\" | result: %ld (expected: %ld)\n", ft_strlen(""), strlen(""));
|
|
|
|
|
printf("EXCPETION: arg: NULL | result: %ld\n", ft_strlen(NULL));
|
|
|
|
|
|
|
|
|
|
printf("\n--- ft_strcpy ---\n");
|
|
|
|
|
char *a1 = calloc(sizeof(char), 10);
|
|
|
|
|
char *a2 = calloc(sizeof(char), 10);
|
|
|
|
|
printf("arg : \"abcdefgh\" | result : %s\n", ft_strcpy(a1, "abcdefgh"));
|
|
|
|
|
printf("arg : \"abcdefgh\" | result : %s\n", strcpy(a2, "abcdefgh"));
|
|
|
|
|
printf("arg : \"67\" | result : %s\n", ft_strcpy(a1, "67"));
|
|
|
|
|
printf("arg : \"67\" | result : %s\n", strcpy(a2, "67"));
|
|
|
|
|
printf("EXCEPTION : dest : NULL | result : %s\n", ft_strcpy(NULL, "67"));
|
|
|
|
|
printf("EXCEPTION : src : NULL | result : %s\n", ft_strcpy(a2, NULL));
|
|
|
|
|
printf("arg: \"abcdefgh\" | result: %s ", ft_strcpy(a1, "abcdefgh"));
|
|
|
|
|
printf("(expected: %s)\n", strcpy(a2, "abcdefgh"));
|
|
|
|
|
printf("arg: \"67\" | result: %s ", ft_strcpy(a1, "67"));
|
|
|
|
|
printf("(expected: %s)\n", strcpy(a2, "67"));
|
|
|
|
|
printf("EXCEPTION: dest: NULL | result: %s\n", ft_strcpy(NULL, "67"));
|
|
|
|
|
printf("EXCEPTION: src: NULL | result: %s\n", ft_strcpy(a2, NULL));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("\n--- ft_strcmp ---\n");
|
|
|
|
|
printf("arg : \"aaaaaa\" \"aaaa\" | result : %d (expected : %d)\n", ft_strcmp("aaaaaa", "aaaa"), strcmp("aaaaaa", "aaaa"));
|
|
|
|
|
printf("arg : \"aaaa\" \"bb\" | result : %d (expected : %d)\n", ft_strcmp("aaaa", "bb"), strcmp("aaaa", "bb"));
|
|
|
|
|
printf("arg : \"i love nixos !!\" \"i love nixos !!\" | result : %d (expected : %d)\n", ft_strcmp("i love nixos !!", "i love nixos !!"), strcmp("i love nixos !!", "i love nixos !!"));
|
|
|
|
|
printf("EXCEPTION : s1 : NULL | result : %d \n", ft_strcmp(NULL, "hiiiii :D"));
|
|
|
|
|
printf("EXCEPTION : s2 : NULL | result : %d \n", ft_strcmp("hihi :3", NULL));
|
|
|
|
|
printf("arg: \"aaaaaa\" \"aaaa\" | result: %d (expected: %d)\n", ft_strcmp("aaaaaa", "aaaa"), strcmp("aaaaaa", "aaaa"));
|
|
|
|
|
printf("arg: \"aaaa\" \"bb\" | result: %d (expected: %d)\n", ft_strcmp("aaaa", "bb"), strcmp("aaaa", "bb"));
|
|
|
|
|
printf("arg: \"i love nixos !!\" \"i love nixos !!\" | result: %d (expected: %d)\n", ft_strcmp("i love nixos !!", "i love nixos !!"), strcmp("i love nixos !!", "i love nixos !!"));
|
|
|
|
|
printf("EXCEPTION: s1: NULL | result: %d \n", ft_strcmp(NULL, "hiiiii :D"));
|
|
|
|
|
printf("EXCEPTION: s2: NULL | result: %d \n", ft_strcmp("hihi :3", NULL));
|
|
|
|
|
|
|
|
|
|
printf("\n--- ft_write ---\n");
|
|
|
|
|
printf("| 1 \"xd\" 2 | %d\n", ft_write(1, "xd", 2));
|
|
|
|
|
printf("| 200 \"xd\" 2 | %d\n", ft_write(200, "xd", 2));
|
|
|
|
|
int fd = open("out", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
|
|
|
|
|
printf("| %d \"[...]\" 42 | %d\n", fd, ft_write(fd, "wizard money gang, we love casting spells\n", 42));
|
|
|
|
|
printf("arg: 1 \"xd\" 2 | result: %ld ", ft_write(1, "xd", 2));
|
|
|
|
|
printf("(expected: %ld)\n", write(1, "xd", 2));
|
|
|
|
|
printf("arg: 200 \"xd\" 2 | result: %ld ", ft_write(200, "xd", 2));
|
|
|
|
|
printf("(expected: %ld)\n", write(200, "xd", 2));
|
|
|
|
|
int fd = open("out_libasm", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
|
|
|
|
|
int fd2 = open("out_libc", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
|
|
|
|
|
printf("arg: %d \"[...]\" 42 | result: %ld ", fd, ft_write(fd, "wizard money gang, we love casting spells", 41));
|
|
|
|
|
printf("(expected: %ld)\n", write(fd2, "wizard money gang, we love casting spells", 41));
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
|
|
printf("\n--- ft_read ---\n");
|
|
|
|
|
char *xd = calloc(sizeof(char), 43);
|
|
|
|
|
printf("arg: 200 (buffer) 2 | result: %ld : \"%s\" ", ft_read(200, xd, 6), xd);
|
|
|
|
|
printf("(expected: %ld : \"%s\")\n", read(200, xd, 6), xd);
|
|
|
|
|
fd = open("out_libasm", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
|
|
|
|
|
fd2 = open("out_libc", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
|
|
|
|
|
printf("arg: %d (buffer) 42 | result: %ld : \"%s\" ", fd, ft_read(fd, xd, 41), xd);
|
|
|
|
|
printf("(expected: %ld : \"%s\")\n", read(fd2, xd, 41), xd);
|
|
|
|
|
|
|
|
|
|
printf("\n--- ft_strdup ---\n");
|
|
|
|
|
printf("%s\n", ft_strdup("this is a very cool test yayy"));
|
|
|
|
|
printf("%s\n", ft_strdup("hi"));
|
|
|
|
|
if (ft_strdup(NULL) == NULL)
|
|
|
|
|
printf("arg: NULL | %s\n", "(null)"); // because printf's behavior on NULL is unexpected, i will not try it (it segfaults on my computer :c)
|
|
|
|
|
else
|
|
|
|
|
printf("arg: NULL | %s\n (this should never happen)", ft_strdup(NULL));
|
|
|
|
|
}
|
|
|
|
|
|