part 1 done, not tested

This commit is contained in:
Jack Halford 2016-08-27 22:57:08 +02:00
parent 3a4ce47442
commit 7a528ecf11
31 changed files with 625 additions and 0 deletions

37
libft/Makefile Normal file
View file

@ -0,0 +1,37 @@
NAME = libft.a
CC = gcc
AR = ar -rc
D_SRC = .
D_OBJ = obj
O_FLAGS =
W_FLAGS = -Wall -Wextra -Werror
DEBUG =
MKDIR = mkdir -p
RM = /bin/rm -rf
F_SRC := $(shell ls -1 $(D_SRC) | grep "\.c$$")
F_OBJ := $(F_SRC:.c=.o)
F_OBJ := $(addprefix $(D_OBJ)/, $(F_OBJ))
.PHONY: all clean fclean re
all: $(NAME)
$(D_OBJ)/%.o: $(D_SRC)/%.c
@$(MKDIR) $(D_OBJ)
@$(CC) $(W_FLAGS) -c $< -o $@ $(DEBUG)
@echo "Compiling "$<"..."
$(NAME): $(F_OBJ)
$(AR) $(NAME) $(F_OBJ)
ranlib $(NAME)
clean:
$(RM) $(D_OBJ)
fclean: clean
$(RM) $(NAME)
re: fclean all

1
libft/auteur Normal file
View file

@ -0,0 +1 @@
jhalford

47
libft/ft_atoi.c Normal file
View file

@ -0,0 +1,47 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/03 16:17:21 by jhalford #+# #+# */
/* Updated: 2016/08/07 18:10:10 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
static int ft_iswhitespace(char c)
{
if (c == ' ' || c == '\t' || c == '\n')
return (1);
else if (c == '\v' || c == '\f' || c == '\r')
return (1);
return (0);
}
int ft_atoi(const char *str)
{
int i;
int res;
int sign;
i = 0;
res = 0;
sign = 1;
while (ft_iswhitespace(str[i]))
i++;
if (str[i] == '-' || str[i] == '+')
{
if (str[i + 1] >= '0' && str[i + 1] <= '9')
{
sign = (str[i] == '+') ? 1 : -1;
i++;
}
else
return (0);
}
while (str[i] >= '0' && str[i] <= '9')
res = res * 10 + str[i++] - '0';
res *= sign;
return (res);
}

10
libft/ft_bzero.c Normal file
View file

@ -0,0 +1,10 @@
#include "libft.h"
void ft_bzero(void *s, size_t n)
{
size_t i;
i = -1;
while (++i < n)
*(char *)s++ = 0;
}

13
libft/ft_isalnum.c Normal file
View file

@ -0,0 +1,13 @@
#include "libft.h"
int ft_isalnum(int c)
{
unsigned char a;
a = (unsigned char)c;
if ((a >= 'a' && a <= 'z')
|| (a >= 'A' && a <= 'Z')
|| (a >= '0' && a <= '9'))
return (a);
return (0);
}

11
libft/ft_isalpha.c Normal file
View file

@ -0,0 +1,11 @@
#include "libft.h"
int ft_isalpha(int c)
{
unsigned char a;
a = (unsigned char)c;
if ((a >= 'a' && a <= 'z') || (a >= 'A' && a <= 'Z'))
return (a);
return (0);
}

11
libft/ft_isascii.c Normal file
View file

@ -0,0 +1,11 @@
#include "libft.h"
int ft_isascii(int c)
{
unsigned char a;
a = (unsigned char)c;
if (a >= 0 && a <= 127)
return (a);
return (0);
}

11
libft/ft_isdigit.c Normal file
View file

@ -0,0 +1,11 @@
#include "libft.h"
int ft_isdigit(int c)
{
unsigned char a;
a = (unsigned char)c;
if (a >= '0' && a <= '9')
return (a);
return (0);
}

11
libft/ft_isprint.c Normal file
View file

@ -0,0 +1,11 @@
#include "libft.h"
int ft_isprint(int c)
{
unsigned char a;
a = (unsigned char)c;
if (a >= 32 && a <= 126)
return (a);
return (0);
}

15
libft/ft_memccpy.c Normal file
View file

@ -0,0 +1,15 @@
#include "libft.h"
void *ft_memccpy(void *dst, const void *src, int c, size_t n)
{
size_t i;
i = -1;
while (++i < n)
{
*(char *)dst++ = *(char *)src;
if (*(char *)src++ == (unsigned char)c)
return (dst);
}
return (NULL);
}

17
libft/ft_memchr.c Normal file
View file

@ -0,0 +1,17 @@
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
void *a;
size_t i;
i = -1;
a = (unsigned char *)s;
while (++i < n)
{
if (*(unsigned char *)a == (unsigned char)c)
return (a);
a++;
}
return (NULL);
}

16
libft/ft_memcmp.c Normal file
View file

@ -0,0 +1,16 @@
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
size_t i;
int cmp;
i = 0;
while (++i < n)
{
cmp = ((unsigned char *)s1)[i] - ((unsigned char *)s2)[i];
if (cmp)
return (cmp);
}
return (cmp);
}

11
libft/ft_memcpy.c Normal file
View file

@ -0,0 +1,11 @@
#include "libft.h"
void *ft_memcpy(void *dst, const void *src, size_t n)
{
size_t i;
i = -1;
while (++i < n)
((char *)dst)[i] = *(char *)src++;
return (dst);
}

14
libft/ft_memmove.c Normal file
View file

@ -0,0 +1,14 @@
#include "libft.h"
void *ft_memmove(void *dst, const void *src, size_t len)
{
size_t i;
i = 0;
while (i < len && (dst + i < src || dst + i > src + len))
{
((char *)dst)[i] = ((char *)src)[i];
i++;
}
return (dst);
}

11
libft/ft_memset.c Normal file
View file

@ -0,0 +1,11 @@
#include "libft.h"
void *ft_memset(void *b, int c, size_t len)
{
size_t i;
i = -1;
while (++i < len)
((unsigned char *)b)[i] = (unsigned char)c;
return (b);
}

29
libft/ft_strcat.c Normal file
View file

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/07 10:56:53 by jhalford #+# #+# */
/* Updated: 2016/08/20 23:16:44 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strcat(char *s1, const char *s2)
{
size_t size;
size_t j;
size = ft_strlen(s1);
j = 0;
while (s2[j] != '\0')
{
s1[size + j] = s2[j];
j++;
}
s1[size + j] = '\0';
return (s1);
}

17
libft/ft_strchr.c Normal file
View file

@ -0,0 +1,17 @@
#include "libft.h"
char *strchr(const char *s, int c)
{
char *a;
a = (char *)s;
while (*a)
{
if (*a == (char)c)
return (a);
a++;
}
if (*a == (char)c)
return (a);
return (NULL);
}

31
libft/ft_strcmp.c Normal file
View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/07 10:49:02 by jhalford #+# #+# */
/* Updated: 2016/08/25 17:06:34 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strcmp(const char *s1, const char *s2)
{
int cmp;
int i;
i = 0;
while (1)
{
cmp = (s1[i] - s2[i]);
if (s1[i] == '\0' && s2[i] == '\0')
return (cmp);
if (s1[i] == s2[i])
i++;
else
return (cmp);
}
}

27
libft/ft_strcpy.c Normal file
View file

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/07 10:48:12 by jhalford #+# #+# */
/* Updated: 2016/08/20 23:37:18 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strcpy(char *dst, const char *src)
{
int i;
i = 0;
while (src[i] != '\0')
{
dst[i] = src[i];
i++;
}
dst[i] = '\0';
return (dst);
}

19
libft/ft_strdup.c Normal file
View file

@ -0,0 +1,19 @@
#include "libft.h"
char *ft_strdup(const char *s1)
{
char *dup;
int size;
int i;
i = 0;
size = ft_strlen(s1);
dup = (char*)malloc(sizeof(*dup) * (size + 1));
while (s1[i] != '\0')
{
dup[i] = s1[i];
i++;
}
dup[i] = '\0';
return (dup);
}

31
libft/ft_strlcat.c Normal file
View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/07 10:57:16 by jhalford #+# #+# */
/* Updated: 2016/08/07 21:44:13 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
size_t i;
size_t dst_size;
size_t src_size;
dst_size = ft_strlen(dst);
src_size = ft_strlen(src);
i = 0;
while (src[i] != '\0' && ((dst_size + i) < (size - 1)))
{
dst[dst_size + i] = src[i];
i++;
}
dst[dst_size + i] = '\0';
return (src_size + ((dst_size < size) ? dst_size : size));
}

11
libft/ft_strlen.c Normal file
View file

@ -0,0 +1,11 @@
#include "libft.h"
size_t strlen(const char *s)
{
int i;
i = 0;
while (s[i])
i++;
return (i);
}

29
libft/ft_strncat.c Normal file
View file

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/07 10:57:07 by jhalford #+# #+# */
/* Updated: 2016/08/07 10:57:11 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strncat(char *s1, const char *s2, size_t n)
{
size_t size;;
size_t j;
size = ft_strlen(s1);
j = 0;
while (s2[j] != '\0' && j < n)
{
s1[size + j] = s2[j];
j++;
}
s1[size + j] = '\0';
return (s1);
}

33
libft/ft_strncmp.c Normal file
View file

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/07 10:49:12 by jhalford #+# #+# */
/* Updated: 2016/08/15 22:25:07 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
int cmp;
size_t i;
i = 0;
while (1)
{
cmp = (s1[i] - s2[i]);
if (i >= n - 1)
return (cmp);
if (s1[i] == '\0' && s2[i] == '\0')
return (cmp);
if (s1[i] == s2[i])
i++;
else
return (cmp);
}
}

31
libft/ft_strncpy.c Normal file
View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/07 10:48:21 by jhalford #+# #+# */
/* Updated: 2016/08/07 10:48:25 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strncpy(char *dst, const char *src, size_t len)
{
size_t i;
i = 0;
while (src[i] != '\0' && i < len)
{
dst[i] = src[i];
i++;
}
while (i < len)
{
dst[i] = '\0';
i++;
}
return (dst);
}

23
libft/ft_strnstr.c Normal file
View file

@ -0,0 +1,23 @@
#include "libft.h"
char *ft_strnstr(const char *big, const char *little, size_t len)
{
size_t i;
size_t j;
char *a;
a = (char *)big;
i = 0;
while (a[i] != '\0' && i < len)
{
j = 0;
while (a[i + j] == little[j])
{
j++;
if (little[j] == '\0')
return (a + i);
}
i++;
}
return (NULL);
}

19
libft/ft_strrchr.c Normal file
View file

@ -0,0 +1,19 @@
#include "libft.h"
char *strrchr(const char *s, int c)
{
char *a;
size_t i;
size_t len;
a = (char *)s;
len = ft_strlen(a);
i = 0;
while (i <= len)
{
if (a[len - i] == (char)c)
return (a);
i++;
}
return (NULL);
}

35
libft/ft_strstr.c Normal file
View file

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/07 10:48:35 by jhalford #+# #+# */
/* Updated: 2016/08/09 13:53:17 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strstr(const char *big, const char *little)
{
size_t i;
size_t j;
char *a;
a = (char *)big;
i = 0;
while (a[i] != '\0')
{
j = 0;
while (a[i + j] == little[j])
{
j++;
if (little[j] == '\0')
return (a + i);
}
i++;
}
return (0);
}

11
libft/ft_tolower.c Normal file
View file

@ -0,0 +1,11 @@
#include "libft.h"
int ft_toupper(int c)
{
unsigned char a;
a = (unsigned char)c;
if (a >= 'A' && a <= 'Z')
return (a + 32);
return (a);
}

11
libft/ft_toupper.c Normal file
View file

@ -0,0 +1,11 @@
#include "libft.h"
int ft_toupper(int c)
{
unsigned char a;
a = (unsigned char)c;
if (a >= 'a' && a <= 'z')
return (a - 32);
return (a);
}

32
libft/libft.h Normal file
View file

@ -0,0 +1,32 @@
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
void *ft_memset(void *b, int c, size_t len);
void ft_bzero(void *s, size_t n);
void *ft_memcpy(void *dst, const void *src, size_t n);
void *ft_memccpy(void *dst, const void *src, int c, size_t n);
void *ft_memmove(void *dst, const void *src, size_t len);
void *ft_memchr(const void *s, int c, size_t n);
int ft_memcmp(const void *s1, const void *s2, size_t n);
size_t ft_strlen(const char *s);
char *ft_strdup(const char *s1);
char *ft_strcpy(char *dst, const char *src);
char *ft_strncpy(char *dst, const char *src, size_t len);
char *ft_strcat(char *s1, const char *s2);
char *ft_strncat(char *s1, const char *s2, size_t n);
size_t ft_strlcat(char *dst, const char *src, size_t size);
char *strchr(const char *s, int c);
char *strrchr(const char *s, int c);
char *ft_strstr(const char *big, const char *little);
char *ft_strnstr(const char *big, const char *little, size_t len);
int ft_strcmp(const char *s1, const char *s2);
int ft_strncmp(const char *s1, const char *s2, size_t n);
int ft_atoi(const char *str);
int ft_isalpha(int c);
int ft_isdigit(int c);
int ft_isalnum(int c);
int ft_isascii(int c);
int ft_isprint(int c);
int ft_toupper(int c);
int ft_tolower(int c);