removed libft
This commit is contained in:
parent
3d1bba5039
commit
6018ed7ad4
56 changed files with 0 additions and 1092 deletions
|
|
@ -1,37 +0,0 @@
|
||||||
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 +0,0 @@
|
||||||
jhalford
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_bzero(void *s, size_t n)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = -1;
|
|
||||||
while (++i < n)
|
|
||||||
*(char *)s++ = 0;
|
|
||||||
}
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
#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);
|
|
||||||
}
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
#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);
|
|
||||||
}
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_isascii(int c)
|
|
||||||
{
|
|
||||||
unsigned char a;
|
|
||||||
|
|
||||||
a = (unsigned char)c;
|
|
||||||
if (a >= 0 && a <= 127)
|
|
||||||
return (a);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_isdigit(int c)
|
|
||||||
{
|
|
||||||
unsigned char a;
|
|
||||||
|
|
||||||
a = (unsigned char)c;
|
|
||||||
if (a >= '0' && a <= '9')
|
|
||||||
return (a);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_isprint(int c)
|
|
||||||
{
|
|
||||||
unsigned char a;
|
|
||||||
|
|
||||||
a = (unsigned char)c;
|
|
||||||
if (a >= 32 && a <= 126)
|
|
||||||
return (a);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
@ -1,55 +0,0 @@
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
static char *ft_strrev(char *str)
|
|
||||||
{
|
|
||||||
int len;
|
|
||||||
char tmp;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
len = 0;
|
|
||||||
while (str[len] != '\0')
|
|
||||||
len++;
|
|
||||||
while (i < len / 2)
|
|
||||||
{
|
|
||||||
tmp = str[len - (i + 1)];
|
|
||||||
str[len - (i + 1)] = str[i];
|
|
||||||
str[i] = tmp;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
|
|
||||||
static size_t ft_size(int n)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 1;
|
|
||||||
while (n /= 10)
|
|
||||||
i++;
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_itoa(int n)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
char *str;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
str = ft_strnew(ft_size(n) + 1);
|
|
||||||
if (n == 0)
|
|
||||||
{
|
|
||||||
str[i++] = '0';
|
|
||||||
str[i] = '\0';
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
while (n)
|
|
||||||
{
|
|
||||||
str[i++] = ABS(n % 10) + '0';
|
|
||||||
n /= 10;
|
|
||||||
}
|
|
||||||
if (NEG(n))
|
|
||||||
str[i++] = '-';
|
|
||||||
str[i] = '\0';
|
|
||||||
return (ft_strrev(str));
|
|
||||||
}
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_memalloc(size_t size)
|
|
||||||
{
|
|
||||||
void *addr;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
addr = malloc(size);
|
|
||||||
if (addr == NULL)
|
|
||||||
return (NULL);
|
|
||||||
i = -1;
|
|
||||||
while (++i < size)
|
|
||||||
((char *)addr)[i] = 0;
|
|
||||||
return (addr);
|
|
||||||
}
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
#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);
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
#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);
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
#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);
|
|
||||||
}
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
#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);
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_memdel(void **ap)
|
|
||||||
{
|
|
||||||
free(*ap);
|
|
||||||
*ap = NULL;
|
|
||||||
}
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
#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);
|
|
||||||
}
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
#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);
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_putchar(char c)
|
|
||||||
{
|
|
||||||
write(1, &c, 1);
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_putchar_fd(char c, int fd)
|
|
||||||
{
|
|
||||||
write(fd, &c, 1);
|
|
||||||
}
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_putendl(char const *s)
|
|
||||||
{
|
|
||||||
char nl;
|
|
||||||
|
|
||||||
nl = '\n';
|
|
||||||
write(1, s, ft_strlen(s));
|
|
||||||
write(1, &nl, 1);
|
|
||||||
}
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_putendl_fd(char const *s, int fd)
|
|
||||||
{
|
|
||||||
char nl;
|
|
||||||
|
|
||||||
nl = '\n';
|
|
||||||
write(fd, s, ft_strlen(s));
|
|
||||||
write(fd, &nl, 1);
|
|
||||||
}
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putnbr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/08/02 21:25:03 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/08/04 21:28:16 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_putnbr(int n)
|
|
||||||
{
|
|
||||||
if (n == -2147483648)
|
|
||||||
{
|
|
||||||
ft_putchar('-');
|
|
||||||
ft_putchar('2');
|
|
||||||
ft_putnbr(147483648);
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
else if (n < 0)
|
|
||||||
ft_putchar('-');
|
|
||||||
n = ABS(n);
|
|
||||||
if (n >= 10)
|
|
||||||
ft_putnbr(n / 10);
|
|
||||||
ft_putchar(n % 10 + '0');
|
|
||||||
}
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putnbr_fd.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/08/02 21:25:03 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/08/04 21:28:16 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_putnbr_fd(int n, int fd)
|
|
||||||
{
|
|
||||||
if (n == -2147483648)
|
|
||||||
{
|
|
||||||
ft_putchar_fd('-', fd);
|
|
||||||
ft_putchar_fd('2', fd);
|
|
||||||
ft_putnbr_fd(147483648, fd);
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
else if (n < 0)
|
|
||||||
ft_putchar_fd('-', fd);
|
|
||||||
n = ABS(n);
|
|
||||||
if (n >= 10)
|
|
||||||
ft_putnbr_fd(n / 10, fd);
|
|
||||||
ft_putchar_fd(n % 10 + '0', fd);
|
|
||||||
}
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putstr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/08/03 16:13:07 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/08/25 17:03:59 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_putstr(char const *s)
|
|
||||||
{
|
|
||||||
write(1, s, ft_strlen(s));
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_putstr_fd(char const *s, int fd)
|
|
||||||
{
|
|
||||||
write(fd, s, ft_strlen(s));
|
|
||||||
}
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
#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);
|
|
||||||
}
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_strclr(char *s)
|
|
||||||
{
|
|
||||||
size_t size;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
size = ft_strlen(s);
|
|
||||||
i = -1;
|
|
||||||
while (++i < size)
|
|
||||||
s[i] = 0;
|
|
||||||
}
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_strdel(char **as)
|
|
||||||
{
|
|
||||||
free(*as);
|
|
||||||
*as = NULL;
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
#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);
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_strequ(char const *s1, char const *s2)
|
|
||||||
{
|
|
||||||
return(ft_strcmp(s1, s2) == 0);
|
|
||||||
}
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_striter(char *s, void (*f)(char *))
|
|
||||||
{
|
|
||||||
size_t size;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
size = ft_strlen(s);
|
|
||||||
i = -1;
|
|
||||||
while (++i < size)
|
|
||||||
(*f)(s + i);
|
|
||||||
}
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_striteri(char *s, void (*f)(unsigned int, char *))
|
|
||||||
{
|
|
||||||
size_t size;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
size = ft_strlen(s);
|
|
||||||
i = -1;
|
|
||||||
while (++i < size)
|
|
||||||
(*f)(i, s + i);
|
|
||||||
}
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strjoin(char const *s1, char const *s2)
|
|
||||||
{
|
|
||||||
char *join;
|
|
||||||
|
|
||||||
join = ft_strnew(ft_strlen(s1) + ft_strlen(s2) + 1);
|
|
||||||
ft_strcpy(join, s1);
|
|
||||||
ft_strcat(join, s2);
|
|
||||||
return (join);
|
|
||||||
}
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* 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));
|
|
||||||
}
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
size_t ft_strlen(const char *s)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (s[i])
|
|
||||||
i++;
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strmap(char const *s, char (*f)(char))
|
|
||||||
{
|
|
||||||
size_t size;
|
|
||||||
size_t i;
|
|
||||||
char *out;
|
|
||||||
|
|
||||||
size = ft_strlen(s);
|
|
||||||
out = (char *)malloc(sizeof(char) * (size + 1));
|
|
||||||
if (out == NULL)
|
|
||||||
return (NULL);
|
|
||||||
i = -1;
|
|
||||||
while (++i < size)
|
|
||||||
out[i] = (*f)(s[i]);
|
|
||||||
return (out);
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
|
|
||||||
{
|
|
||||||
size_t size;
|
|
||||||
size_t i;
|
|
||||||
char *out;
|
|
||||||
|
|
||||||
size = ft_strlen(s);
|
|
||||||
out = (char *)malloc(sizeof(char) * (size + 1));
|
|
||||||
if (out == NULL)
|
|
||||||
return (NULL);
|
|
||||||
i = -1;
|
|
||||||
while (++i < size)
|
|
||||||
out[i] = (*f)(i, s[i]);
|
|
||||||
return (out);
|
|
||||||
}
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_strnequ(char const *s1, char const *s2, size_t n)
|
|
||||||
{
|
|
||||||
return(ft_strncmp(s1, s2, n) == 0);
|
|
||||||
}
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strnew(size_t size)
|
|
||||||
{
|
|
||||||
char *addr;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
addr = (char *)malloc(size + 1);
|
|
||||||
if (addr == NULL)
|
|
||||||
return (NULL);
|
|
||||||
i = -1;
|
|
||||||
while (++i <= size)
|
|
||||||
addr[i] = '\0';
|
|
||||||
return (addr);
|
|
||||||
}
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
#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);
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
#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);
|
|
||||||
}
|
|
||||||
|
|
@ -1,93 +0,0 @@
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
static char **alloc_table(char **table, const char *str, char c)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int n_words;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
n_words = 0;
|
|
||||||
while (str[i] == c)
|
|
||||||
i++;
|
|
||||||
while (str[i] != '\0')
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
if (str[i] == c)
|
|
||||||
{
|
|
||||||
n_words++;
|
|
||||||
while (str[i] == c)
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (str[i - 1] != c)
|
|
||||||
n_words++;
|
|
||||||
table = (char**)malloc(sizeof(*table) * (n_words + 10));
|
|
||||||
table[n_words] = 0;
|
|
||||||
return (table);
|
|
||||||
}
|
|
||||||
|
|
||||||
static char **alloc_words(char **table, const char *str, char c)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
int k;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
j = 0;
|
|
||||||
k = 0;
|
|
||||||
while (str[i] == c)
|
|
||||||
i++;
|
|
||||||
while (str[i] != '\0')
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
if (str[i] == c || !str[i])
|
|
||||||
{
|
|
||||||
table[j] = (char*)malloc(sizeof(**table) * (k + 10));
|
|
||||||
j++;
|
|
||||||
k = 0;
|
|
||||||
while (str[i] == c)
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
k++;
|
|
||||||
}
|
|
||||||
return (table);
|
|
||||||
}
|
|
||||||
|
|
||||||
static char **fill_table(char **table, const char *str, char c)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
int k;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
j = 0;
|
|
||||||
k = 0;
|
|
||||||
while (str[i] == c)
|
|
||||||
i++;
|
|
||||||
while (str[i] != '\0')
|
|
||||||
{
|
|
||||||
table[j][k] = str[i];
|
|
||||||
i++;
|
|
||||||
k++;
|
|
||||||
if (str[i] == c || !str[i])
|
|
||||||
{
|
|
||||||
table[j][k] = '\0';
|
|
||||||
j++;
|
|
||||||
k = 0;
|
|
||||||
while (str[i] == c)
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (table);
|
|
||||||
}
|
|
||||||
|
|
||||||
char **ft_strsplit(char const *s, char c)
|
|
||||||
{
|
|
||||||
char **table;
|
|
||||||
|
|
||||||
table = 0;
|
|
||||||
table = alloc_table(table, s, c);
|
|
||||||
table = alloc_words(table, s, c);
|
|
||||||
table = fill_table(table, s, c);
|
|
||||||
return (table);
|
|
||||||
}
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strsub(char const *s, unsigned int start, size_t len)
|
|
||||||
{
|
|
||||||
char *out;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
out = (char *)malloc(sizeof(char) * (len + 1));
|
|
||||||
if (!out)
|
|
||||||
return (NULL);
|
|
||||||
i = -1;
|
|
||||||
while (++i < len)
|
|
||||||
out[i] = s[i + start];
|
|
||||||
out[i] = '\0';
|
|
||||||
return (out);
|
|
||||||
}
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strtrim(char const *s)
|
|
||||||
{
|
|
||||||
char *out;
|
|
||||||
size_t size;
|
|
||||||
|
|
||||||
out = ft_strdup(s);
|
|
||||||
while (*out && SEP(*out))
|
|
||||||
out++;
|
|
||||||
size = ft_strlen(out);
|
|
||||||
while (size - 1 && SEP(out[size - 1]))
|
|
||||||
{
|
|
||||||
size--;
|
|
||||||
out[size] = '\0';
|
|
||||||
}
|
|
||||||
return (out);
|
|
||||||
}
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
#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);
|
|
||||||
}
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
#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);
|
|
||||||
}
|
|
||||||
Binary file not shown.
|
|
@ -1,64 +0,0 @@
|
||||||
#ifndef LIBFT_H
|
|
||||||
#define LIBFT_H
|
|
||||||
# include <string.h>
|
|
||||||
# include <unistd.h>
|
|
||||||
# include <stdlib.h>
|
|
||||||
# define SEP(x) (x == ' ' || x == '\t' || x == '\n')
|
|
||||||
# define ABS(x) (((x) < 0) ? -(x) : (x))
|
|
||||||
# define NEG(x) (((x) < 0) ? 1 : 0)
|
|
||||||
# define POS(x) (((x) > 0) ? 1 : 0)
|
|
||||||
|
|
||||||
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);
|
|
||||||
void *ft_memalloc(size_t size);
|
|
||||||
void ft_memdel(void **ap);
|
|
||||||
char *ft_strnew(size_t size);
|
|
||||||
void ft_strdel(char **as);
|
|
||||||
void ft_strclr(char *s);
|
|
||||||
void ft_striter(char *s, void (*f)(char *));
|
|
||||||
void ft_striteri(char *s, void (*f)(unsigned int, char *));
|
|
||||||
char *ft_strmap(char const *s, char (*f)(char));
|
|
||||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
|
|
||||||
int ft_strequ(char const *s1, char const *s2);
|
|
||||||
int ft_strnequ(char const *s1, char const *s2, size_t n);
|
|
||||||
char *ft_strsub(char const *s, unsigned int start, size_t len);
|
|
||||||
char *ft_strjoin(char const *s1, char const *s2);
|
|
||||||
char *ft_strtrim(char const *s);
|
|
||||||
char **ft_strsplit(char const *s, char c);
|
|
||||||
char *ft_itoa(int n);
|
|
||||||
void ft_putchar(char c);
|
|
||||||
void ft_putstr(char const *s);
|
|
||||||
void ft_putendl(char const *s);
|
|
||||||
void ft_putnbr(int n);
|
|
||||||
void ft_putchar_fd(char c, int fd);
|
|
||||||
void ft_putstr_fd(char const *s, int fd);
|
|
||||||
void ft_putendl_fd(char const *s, int fd);
|
|
||||||
void ft_putnbr_fd(int n, int fd);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Loading…
Reference in a new issue