From 671a58519ef6207b54947ff70eea497ff7eb58ae Mon Sep 17 00:00:00 2001 From: Thomas Vanbesien Date: Sat, 21 Feb 2026 15:49:06 +0100 Subject: Restructure project layout and clean up test suite Move sources to src/, header to inc/, and tests to tests/src/. Update Makefiles and .gitignore for the new layout. Refactor test harness: add crash-wrapper macros (_S_CRASH, _S_CRASH_I, _S_CRASH_V, _S_CRASH_BUF) replacing 58 hand-written wrappers, add shared _s_test_int_range helper eliminating duplicate _s_test_func, add _S_RAND_ITERS constant, move srand() to main() in all test binaries, and add Doxygen comments to test_utils.h. --- src/ft_atoi.c | 26 ++++++++++++++++++++++++++ src/ft_bzero.c | 7 +++++++ src/ft_calloc.c | 19 +++++++++++++++++++ src/ft_isalnum.c | 7 +++++++ src/ft_isalpha.c | 7 +++++++ src/ft_isascii.c | 7 +++++++ src/ft_isdigit.c | 7 +++++++ src/ft_isprint.c | 7 +++++++ src/ft_memchr.c | 16 ++++++++++++++++ src/ft_memcmp.c | 19 +++++++++++++++++++ src/ft_memcpy.c | 16 ++++++++++++++++ src/ft_memmove.c | 26 ++++++++++++++++++++++++++ src/ft_memset.c | 12 ++++++++++++ src/ft_strchr.c | 7 +++++++ src/ft_strdup.c | 16 ++++++++++++++++ src/ft_strlcat.c | 23 +++++++++++++++++++++++ src/ft_strlcpy.c | 20 ++++++++++++++++++++ src/ft_strlen.c | 12 ++++++++++++ src/ft_strncmp.c | 16 ++++++++++++++++ src/ft_strnstr.c | 19 +++++++++++++++++++ src/ft_strrchr.c | 18 ++++++++++++++++++ src/ft_tolower.c | 9 +++++++++ src/ft_toupper.c | 9 +++++++++ 23 files changed, 325 insertions(+) create mode 100644 src/ft_atoi.c create mode 100644 src/ft_bzero.c create mode 100644 src/ft_calloc.c create mode 100644 src/ft_isalnum.c create mode 100644 src/ft_isalpha.c create mode 100644 src/ft_isascii.c create mode 100644 src/ft_isdigit.c create mode 100644 src/ft_isprint.c create mode 100644 src/ft_memchr.c create mode 100644 src/ft_memcmp.c create mode 100644 src/ft_memcpy.c create mode 100644 src/ft_memmove.c create mode 100644 src/ft_memset.c create mode 100644 src/ft_strchr.c create mode 100644 src/ft_strdup.c create mode 100644 src/ft_strlcat.c create mode 100644 src/ft_strlcpy.c create mode 100644 src/ft_strlen.c create mode 100644 src/ft_strncmp.c create mode 100644 src/ft_strnstr.c create mode 100644 src/ft_strrchr.c create mode 100644 src/ft_tolower.c create mode 100644 src/ft_toupper.c (limited to 'src') diff --git a/src/ft_atoi.c b/src/ft_atoi.c new file mode 100644 index 0000000..2fe091a --- /dev/null +++ b/src/ft_atoi.c @@ -0,0 +1,26 @@ +#include "libft.h" + +int +ft_atoi (const char *nptr) +{ + int sign; + int result; + + result = 0; + sign = 1; + // Skip isspace() characters: space, \t, \n, \v, \f, \r. + while (*nptr == ' ' || (*nptr >= '\t' && *nptr <= '\r')) + nptr++; + if (*nptr == '-' || *nptr == '+') + { + if (*nptr == '-') + sign = -1; + nptr++; + } + while (*nptr >= '0' && *nptr <= '9') + { + result = result * 10 + (*nptr - '0'); + nptr++; + } + return (result * sign); +} diff --git a/src/ft_bzero.c b/src/ft_bzero.c new file mode 100644 index 0000000..10f67bd --- /dev/null +++ b/src/ft_bzero.c @@ -0,0 +1,7 @@ +#include "libft.h" + +void +ft_bzero (void *s, size_t n) +{ + ft_memset (s, 0, n); +} diff --git a/src/ft_calloc.c b/src/ft_calloc.c new file mode 100644 index 0000000..7726c64 --- /dev/null +++ b/src/ft_calloc.c @@ -0,0 +1,19 @@ +#include "libft.h" +#include + +void * +ft_calloc (size_t nmemb, size_t size) +{ + void *ptr; + size_t total; + + // Detect multiplication overflow before allocating. + if (nmemb && size > (size_t)-1 / nmemb) + return (NULL); + total = nmemb * size; + ptr = malloc (total); + if (!ptr) + return (NULL); + ft_bzero (ptr, total); + return (ptr); +} diff --git a/src/ft_isalnum.c b/src/ft_isalnum.c new file mode 100644 index 0000000..4b477f8 --- /dev/null +++ b/src/ft_isalnum.c @@ -0,0 +1,7 @@ +#include "libft.h" + +int +ft_isalnum (int c) +{ + return (ft_isalpha (c) || ft_isdigit (c)); +} diff --git a/src/ft_isalpha.c b/src/ft_isalpha.c new file mode 100644 index 0000000..c19cf58 --- /dev/null +++ b/src/ft_isalpha.c @@ -0,0 +1,7 @@ +#include "libft.h" + +int +ft_isalpha (int c) +{ + return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')); +} diff --git a/src/ft_isascii.c b/src/ft_isascii.c new file mode 100644 index 0000000..f9e877e --- /dev/null +++ b/src/ft_isascii.c @@ -0,0 +1,7 @@ +#include "libft.h" + +int +ft_isascii (int c) +{ + return (c >= 0 && c <= 127); +} diff --git a/src/ft_isdigit.c b/src/ft_isdigit.c new file mode 100644 index 0000000..43de53f --- /dev/null +++ b/src/ft_isdigit.c @@ -0,0 +1,7 @@ +#include "libft.h" + +int +ft_isdigit (int c) +{ + return (c >= '0' && c <= '9'); +} diff --git a/src/ft_isprint.c b/src/ft_isprint.c new file mode 100644 index 0000000..73964ff --- /dev/null +++ b/src/ft_isprint.c @@ -0,0 +1,7 @@ +#include "libft.h" + +int +ft_isprint (int c) +{ + return (c >= 32 && c <= 126); +} diff --git a/src/ft_memchr.c b/src/ft_memchr.c new file mode 100644 index 0000000..08d5c3e --- /dev/null +++ b/src/ft_memchr.c @@ -0,0 +1,16 @@ +#include "libft.h" + +void * +ft_memchr (const void *s, int c, size_t n) +{ + const unsigned char *ptr; + + ptr = s; + while (n--) + { + if (*ptr == (unsigned char)c) + return ((void *)ptr); + ptr++; + } + return (NULL); +} diff --git a/src/ft_memcmp.c b/src/ft_memcmp.c new file mode 100644 index 0000000..ce6cc77 --- /dev/null +++ b/src/ft_memcmp.c @@ -0,0 +1,19 @@ +#include "libft.h" + +int +ft_memcmp (const void *s1, const void *s2, size_t n) +{ + const unsigned char *p1; + const unsigned char *p2; + + p1 = s1; + p2 = s2; + while (n--) + { + if (*p1 != *p2) + return (*p1 - *p2); + p1++; + p2++; + } + return (0); +} diff --git a/src/ft_memcpy.c b/src/ft_memcpy.c new file mode 100644 index 0000000..26c4f76 --- /dev/null +++ b/src/ft_memcpy.c @@ -0,0 +1,16 @@ +#include "libft.h" + +void * +ft_memcpy (void *dest, const void *src, size_t n) +{ + unsigned char *dst_bytes; + const unsigned char *src_bytes; + + if (!dest && !src) + return (dest); + dst_bytes = dest; + src_bytes = src; + while (n--) + *dst_bytes++ = *src_bytes++; + return (dest); +} diff --git a/src/ft_memmove.c b/src/ft_memmove.c new file mode 100644 index 0000000..ace0d90 --- /dev/null +++ b/src/ft_memmove.c @@ -0,0 +1,26 @@ +#include "libft.h" + +void * +ft_memmove (void *dest, const void *src, size_t n) +{ + unsigned char *dst_bytes; + const unsigned char *src_bytes; + + if (!dest && !src) + return (dest); + dst_bytes = dest; + src_bytes = src; + if (dst_bytes > src_bytes) + { + dst_bytes += n; + src_bytes += n; + while (n--) + *--dst_bytes = *--src_bytes; + } + else + { + while (n--) + *dst_bytes++ = *src_bytes++; + } + return (dest); +} diff --git a/src/ft_memset.c b/src/ft_memset.c new file mode 100644 index 0000000..5be8fe6 --- /dev/null +++ b/src/ft_memset.c @@ -0,0 +1,12 @@ +#include "libft.h" + +void * +ft_memset (void *s, int c, size_t n) +{ + unsigned char *ptr; + + ptr = s; + while (n--) + *ptr++ = (unsigned char)c; + return (s); +} diff --git a/src/ft_strchr.c b/src/ft_strchr.c new file mode 100644 index 0000000..0952232 --- /dev/null +++ b/src/ft_strchr.c @@ -0,0 +1,7 @@ +#include "libft.h" + +char * +ft_strchr (const char *s, int c) +{ + return (ft_memchr (s, c, ft_strlen (s) + 1)); +} diff --git a/src/ft_strdup.c b/src/ft_strdup.c new file mode 100644 index 0000000..3a6be31 --- /dev/null +++ b/src/ft_strdup.c @@ -0,0 +1,16 @@ +#include "libft.h" +#include + +char * +ft_strdup (const char *s) +{ + size_t len; + char *dup; + + len = ft_strlen (s); + dup = malloc (len + 1); + if (!dup) + return (NULL); + ft_memcpy (dup, s, len + 1); + return (dup); +} diff --git a/src/ft_strlcat.c b/src/ft_strlcat.c new file mode 100644 index 0000000..1274ba5 --- /dev/null +++ b/src/ft_strlcat.c @@ -0,0 +1,23 @@ +#include "libft.h" + +size_t +ft_strlcat (char *dst, const char *src, size_t size) +{ + size_t dst_len; + size_t src_len; + size_t avail; + + dst_len = ft_strlen (dst); + src_len = ft_strlen (src); + if (dst_len >= size) + return (size + src_len); + avail = size - dst_len - 1; + if (src_len < avail) + ft_memcpy (dst + dst_len, src, src_len + 1); + else + { + ft_memcpy (dst + dst_len, src, avail); + dst[size - 1] = '\0'; + } + return (dst_len + src_len); +} diff --git a/src/ft_strlcpy.c b/src/ft_strlcpy.c new file mode 100644 index 0000000..2611041 --- /dev/null +++ b/src/ft_strlcpy.c @@ -0,0 +1,20 @@ +#include "libft.h" + +size_t +ft_strlcpy (char *dst, const char *src, size_t size) +{ + size_t src_len; + + src_len = ft_strlen (src); + if (size > 0) + { + if (src_len < size) + ft_memcpy (dst, src, src_len + 1); + else + { + ft_memcpy (dst, src, size - 1); + dst[size - 1] = '\0'; + } + } + return (src_len); +} diff --git a/src/ft_strlen.c b/src/ft_strlen.c new file mode 100644 index 0000000..06b0aae --- /dev/null +++ b/src/ft_strlen.c @@ -0,0 +1,12 @@ +#include "libft.h" + +size_t +ft_strlen (const char *s) +{ + size_t i; + + i = 0; + while (s[i]) + i++; + return (i); +} diff --git a/src/ft_strncmp.c b/src/ft_strncmp.c new file mode 100644 index 0000000..2fa1099 --- /dev/null +++ b/src/ft_strncmp.c @@ -0,0 +1,16 @@ +#include "libft.h" + +int +ft_strncmp (const char *s1, const char *s2, size_t n) +{ + while (n--) + { + if ((unsigned char)*s1 != (unsigned char)*s2) + return ((unsigned char)*s1 - (unsigned char)*s2); + if (*s1 == '\0') + return (0); + s1++; + s2++; + } + return (0); +} diff --git a/src/ft_strnstr.c b/src/ft_strnstr.c new file mode 100644 index 0000000..23ac891 --- /dev/null +++ b/src/ft_strnstr.c @@ -0,0 +1,19 @@ +#include "libft.h" + +char * +ft_strnstr (const char *big, const char *little, size_t len) +{ + size_t llen; + + if (*little == '\0') + return ((char *)big); + llen = ft_strlen (little); + while (*big && len >= llen) + { + if (ft_memcmp (big, little, llen) == 0) + return ((char *)big); + big++; + len--; + } + return (NULL); +} diff --git a/src/ft_strrchr.c b/src/ft_strrchr.c new file mode 100644 index 0000000..8ec72d1 --- /dev/null +++ b/src/ft_strrchr.c @@ -0,0 +1,18 @@ +#include "libft.h" + +char * +ft_strrchr (const char *s, int c) +{ + size_t len; + + len = ft_strlen (s); + while (len > 0) + { + if (s[len] == (char)c) + return ((char *)s + len); + len--; + } + if (s[0] == (char)c) + return ((char *)s); + return (NULL); +} diff --git a/src/ft_tolower.c b/src/ft_tolower.c new file mode 100644 index 0000000..52fbc94 --- /dev/null +++ b/src/ft_tolower.c @@ -0,0 +1,9 @@ +#include "libft.h" + +int +ft_tolower (int c) +{ + if (c >= 'A' && c <= 'Z') + return (c + ('a' - 'A')); + return (c); +} diff --git a/src/ft_toupper.c b/src/ft_toupper.c new file mode 100644 index 0000000..e52e0fa --- /dev/null +++ b/src/ft_toupper.c @@ -0,0 +1,9 @@ +#include "libft.h" + +int +ft_toupper (int c) +{ + if (c >= 'a' && c <= 'z') + return (c - ('a' - 'A')); + return (c); +} -- cgit v1.2.3