Added libft.h header and Makefile.
Everything passes norminette and compiles to libft.a on make command.
--- /dev/null
+CC = cc
+CFLAGS = -Wall -Wextra -Werror
+AR = ar
+
+RM = rm -f
+
+INCDIR = .
+SRCDIR = .
+# SOURCES = $(addprefix $(SRCDIR)/, ft_putchar.c ft_putstr.c ft_strcmp.c ft_strlen.c ft_swap.c)
+SOURCES = $(shell find $(SRCDIR) -name "*.c")
+OBJECTS = $(SOURCES:.c=.o)
+
+NAME = libft.a
+
+all : $(NAME)
+
+$(NAME) : $(OBJECTS)
+ $(AR) rcs $(NAME) $(OBJECTS)
+
+%.o : %.c
+ $(CC) $(CFLAGS) -o $@ -c $< -I $(INCDIR)
+
+clean :
+ $(RM) $(OBJECTS)
+
+fclean : clean
+ $(RM) $(NAME)
+
+re : fclean
+ $(MAKE) all
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_atoi.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/13 13:44:39 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 12:45:44 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int atoi(const char *nptr)
+{
+ int res;
+ int sign;
+
+ res = 0;
+ sign = 1;
+ while (ft_isspace(*nptr))
+ ++nptr;
+ if ((*nptr == '+' || *nptr == '-'))
+ {
+ if (*nptr == '-')
+ sign *= -1;
+ ++nptr;
+ }
+ while (ft_isdigit(*nptr))
+ {
+ res *= 10;
+ res += *nptr - '0';
+ ++nptr;
+ }
+ return (sign * res);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_calloc.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 11:34:52 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 12:54:11 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h> // for malloc
+#include "libft.h"
+
+void *calloc(size_t nmemb, size_t size)
+{
+ size_t total_bytes;
+ void *res;
+
+ if (nmemb == 0 || size == 0)
+ return (NULL);
+ total_bytes = nmemb * size;
+ if (total_bytes / size != nmemb)
+ return (NULL);
+ res = malloc(total_bytes);
+ ft_memset(res, 0, total_bytes);
+ return (res);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_isascii.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 12:19:40 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 12:20:08 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+int is_ascii(int c)
+{
+ return (0x00 <= c && c <= 0x7F);
+}
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/14 13:31:47 by ljiriste #+# #+# */
-/* Updated: 2023/08/14 13:32:05 by ljiriste ### ########.fr */
+/* Updated: 2023/08/15 12:55:33 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
-static int ft_islower(int c)
+int ft_islower(int c)
{
return ('a' <= c && c <= 'z');
}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_isprint.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 12:17:32 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 12:20:22 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int ft_isprint(int c)
+{
+ return (0x20 <= c && c <= 0x7E);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_isspace.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 11:29:54 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 11:30:29 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int is_space(int c)
+{
+ return (c == ' ' || ('\t' <= c && c <= '\r'));
+}
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/14 13:31:05 by ljiriste #+# #+# */
-/* Updated: 2023/08/14 13:31:31 by ljiriste ### ########.fr */
+/* Updated: 2023/08/15 12:55:24 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
-static int ft_isupper(int c)
+int ft_isupper(int c)
{
return ('A' <= c && c <= 'Z');
}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_memchr.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 10:56:53 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 11:01:34 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stddef.h>
+#include <sys/types.h>
+#include "libft.h"
+
+void *memchr(const void *s, int c, size_t n)
+{
+ size_t i;
+
+ i = 0;
+ while (i < n)
+ {
+ if (*((unsigned char *)s + i) == (unsigned char)c)
+ return ((unsigned char *)s + i);
+ ++i;
+ }
+ return (NULL);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_memcmp.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 11:06:15 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 12:53:17 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <sys/types.h>
+#include "libft.h"
+
+int ft_memcmp(const void *s1, const void *s2, size_t n)
+{
+ size_t i;
+
+ i = 0;
+ while (*((unsigned char *)s1 + i) == *((unsigned char *)s2 + i)
+ && i + 1 < n)
+ ++i;
+ if (n > 0)
+ return (*((unsigned char *)s1 + i) == *((unsigned char *)s2 + i));
+ else
+ return (0);
+}
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/14 13:36:32 by ljiriste #+# #+# */
-/* Updated: 2023/08/14 13:37:03 by ljiriste ### ########.fr */
+/* Updated: 2023/08/15 12:03:46 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
#include <sys/types.h>
#include "libft.h"
-void *ft_memmove(void *dest, const void *src, size_t n)
+void *ft_memmove(void *dest, const void *src, size_t n)
{
size_t i;
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/14 13:13:22 by ljiriste #+# #+# */
-/* Updated: 2023/08/14 13:38:38 by ljiriste ### ########.fr */
+/* Updated: 2023/08/15 10:39:20 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
void *ft_memset(void *s, int c, size_t n)
{
while (n > 0)
- *((unsigned char *)s + (--n)) = c;
+ *((unsigned char *)s + (--n)) = (unsigned char)c;
return (s);
}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strchr.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 10:41:10 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 12:51:36 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stddef.h>
+#include "libft.h"
+
+char *strchr(const char *s, int c)
+{
+ while (*s != '\0')
+ {
+ if (*s == c)
+ return ((char *)s);
+ ++s;
+ }
+ return (NULL);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strdup.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/17 13:33:49 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 12:52:18 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h> // For the malloc function
+#include "libft.h"
+
+char *ft_strdup(const char *s)
+{
+ char *dest;
+ size_t s_len;
+
+ s_len = ft_strlen(s);
+ dest = malloc((s_len + 1) * sizeof(char));
+ if (dest)
+ ft_strlcpy(dest, s, s_len + 1);
+ return (dest);
+}
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/12 17:32:33 by ljiriste #+# #+# */
-/* Updated: 2023/08/14 13:39:39 by ljiriste ### ########.fr */
+/* Updated: 2023/08/15 12:55:06 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
#include <sys/types.h>
#include "libft.h"
-size_t ft_strlcat(char *dst, char *src, size_t size)
+size_t ft_strlcat(char *dst, const char *src, size_t size)
{
size_t length;
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/11 17:28:43 by ljiriste #+# #+# */
-/* Updated: 2023/08/14 13:29:38 by ljiriste ### ########.fr */
+/* Updated: 2023/08/15 12:55:52 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
#include <sys/types.h>
#include "libft.h"
-size_t ft_strlcpy(char *dst, char *src, size_t size)
+size_t ft_strlcpy(char *dst, const char *src, size_t size)
{
size_t i;
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/14 13:40:59 by ljiriste #+# #+# */
-/* Updated: 2023/08/14 13:41:35 by ljiriste ### ########.fr */
+/* Updated: 2023/08/15 12:05:43 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
len = 0;
while (s[len] != '\0')
++len;
- return len;
+ return (len);
}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strncmp.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/12 17:02:07 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 12:56:20 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <sys/types.h>
+#include "libft.h"
+
+int ft_strncmp(const char *s1, const char *s2, size_t n)
+{
+ size_t i;
+
+ i = 0;
+ while (s1[i] == s2[i] && s1[i] != '\0' && s2[i] != '\0' && i + 1 < n)
+ ++i;
+ if (n > 0)
+ return (s1[i] - s2[i]);
+ else
+ return (0);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strnstr.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/12 17:15:34 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 12:50:26 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stddef.h> // For the NULL pointer
+#include <sys/types.h>
+#include "libft.h"
+
+char *ft_strnstr(const char *big, const char *little, size_t len)
+{
+ size_t little_len;
+ size_t i;
+
+ little_len = ft_strlen(little);
+ i = 0;
+ while (big[i] != '\0' && i + little_len <= len)
+ {
+ if (!(ft_strncmp(big + i, little, little_len)))
+ return ((char *)big + i);
+ ++i;
+ }
+ return (NULL);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strrchr.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 10:46:09 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 12:51:17 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stddef.h>
+#include "libft.h"
+
+char *strrchr(const char *s, int c)
+{
+ char *result;
+
+ result = NULL;
+ while (*s != '\0')
+ {
+ if (*s == c)
+ result = (char *)s;
+ ++s;
+ }
+ return (result);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_tolower.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 10:36:54 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 12:53:38 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int ft_tolower(int c)
+{
+ if (ft_isupper(c))
+ c = c + 'a' - 'A';
+ return (c);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_toupper.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 10:35:21 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 12:54:28 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int ft_toupper(int c)
+{
+ if (ft_islower(c))
+ c = c + 'A' - 'a';
+ return (c);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* libft.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 12:58:15 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 12:58:48 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef LIBFT_H
+# define LIBFT_H
+
+# include <sys/types.h>
+
+int ft_isalnum(int c);
+int ft_isalpha(int c);
+int ft_isdigit(int c);
+int ft_islower(int c);
+int ft_isprint(int c);
+int ft_isspace(int c);
+int ft_isupper(int c);
+int ft_isascii(int c);
+
+void *ft_memset(void *s, int c, size_t n);
+void *ft_memcpy(void *dest, const void *src, size_t n);
+void *ft_memmove(void *dest, const void *src, size_t n);
+void *ft_memchr(const void *s, int c, size_t n);
+void *ft_calloc(size_t nmemb, size_t size);
+void ft_bzero(void *s, size_t n);
+int ft_memcmp(const void *s1, const void *s2, size_t n);
+
+size_t ft_strlen(const char *s);
+size_t ft_strlcpy(char *dst, const char *src, size_t size);
+size_t ft_strlcat(char *dst, const char *src, size_t size);
+int ft_strncmp(const char *s1, const char *s2, size_t n);
+char *ft_strchr(const char *s, int c);
+char *ft_strrchr(const char *s, int c);
+char *ft_strnstr(const char *big, const char *little, size_t len);
+char *ft_strdup(const char *s);
+
+int ft_toupper(int c);
+int ft_tolower(int c);
+
+int ft_atoi(const char *nptr);
+
+#endif