aboutsummaryrefslogtreecommitdiffstats
path: root/inc/libft.h
diff options
context:
space:
mode:
authorThomas Vanbesien <tvanbesi@proton.me>2026-02-21 15:49:06 +0100
committerThomas Vanbesien <tvanbesi@proton.me>2026-02-21 15:51:44 +0100
commit671a58519ef6207b54947ff70eea497ff7eb58ae (patch)
tree783a971119bfed965113b84bc306ba941e884663 /inc/libft.h
parentd699849b2360f90c61f645c5d4d4232cd3e1c962 (diff)
downloadLibft-671a58519ef6207b54947ff70eea497ff7eb58ae.tar.gz
Libft-671a58519ef6207b54947ff70eea497ff7eb58ae.zip
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.
Diffstat (limited to 'inc/libft.h')
-rw-r--r--inc/libft.h106
1 files changed, 106 insertions, 0 deletions
diff --git a/inc/libft.h b/inc/libft.h
new file mode 100644
index 0000000..d57cd8d
--- /dev/null
+++ b/inc/libft.h
@@ -0,0 +1,106 @@
+/**
+ * @file libft.h
+ * @brief Reimplementations of standard C library functions.
+ *
+ * Every function mirrors its libc counterpart unless noted otherwise.
+ * Functions that operate on raw memory interpret bytes as unsigned char.
+ * BSD extensions (strlcpy, strlcat, strnstr) follow the OpenBSD semantics.
+ */
+
+#ifndef LIBFT_H
+#define LIBFT_H
+
+#include <stddef.h>
+
+/* ======================================
+ * Character classification & conversion
+ * ====================================== */
+
+/** @brief Return non-zero if @p c is an alphabetic letter. */
+int ft_isalpha (int c);
+/** @brief Return non-zero if @p c is a decimal digit. */
+int ft_isdigit (int c);
+/** @brief Return non-zero if @p c is alphanumeric. */
+int ft_isalnum (int c);
+/** @brief Return non-zero if @p c is a 7-bit ASCII value. */
+int ft_isascii (int c);
+/** @brief Return non-zero if @p c is a printable character. */
+int ft_isprint (int c);
+/** @brief Convert @p c to uppercase if it is a lowercase letter. */
+int ft_toupper (int c);
+/** @brief Convert @p c to lowercase if it is an uppercase letter. */
+int ft_tolower (int c);
+
+/* ======================================
+ * String examination
+ * ====================================== */
+
+/** @brief Return the length of the string @p s. */
+size_t ft_strlen (const char *s);
+/**
+ * @brief Compare at most @p n bytes of @p s1 and @p s2.
+ * @return Negative, zero, or positive integer.
+ */
+int ft_strncmp (const char *s1, const char *s2, size_t n);
+/** @brief Return a pointer to the first occurrence of @p c in @p s. */
+char *ft_strchr (const char *s, int c);
+/** @brief Return a pointer to the last occurrence of @p c in @p s. */
+char *ft_strrchr (const char *s, int c);
+/**
+ * @brief Locate @p little in @p big, searching at most @p len bytes.
+ * @note BSD extension — not available in glibc.
+ */
+char *ft_strnstr (const char *big, const char *little, size_t len);
+/** @brief Convert the initial portion of @p nptr to int. */
+int ft_atoi (const char *nptr);
+
+/* ======================================
+ * String manipulation
+ * ====================================== */
+
+/**
+ * @brief Copy @p src into @p dst, NUL-terminating the result.
+ * @return Length of @p src.
+ * @note BSD extension — not available in glibc.
+ */
+size_t ft_strlcpy (char *dst, const char *src, size_t size);
+/**
+ * @brief Append @p src to @p dst, NUL-terminating the result.
+ * @return Intended total length (dst_len + src_len).
+ * @note BSD extension — not available in glibc.
+ */
+size_t ft_strlcat (char *dst, const char *src, size_t size);
+/** @brief Return a malloc'd duplicate of @p s. */
+char *ft_strdup (const char *s);
+
+/* ======================================
+ * Memory operations
+ * ====================================== */
+
+/** @brief Fill @p n bytes of @p s with the byte @p c. */
+void *ft_memset (void *s, int c, size_t n);
+/** @brief Zero @p n bytes starting at @p s. */
+void ft_bzero (void *s, size_t n);
+/** @brief Copy @p n bytes from @p src to @p dest (no overlap). */
+void *ft_memcpy (void *dest, const void *src, size_t n);
+/** @brief Copy @p n bytes from @p src to @p dest (overlap-safe). */
+void *ft_memmove (void *dest, const void *src, size_t n);
+/** @brief Scan @p n bytes of @p s for the byte @p c. */
+void *ft_memchr (const void *s, int c, size_t n);
+/**
+ * @brief Compare @p n bytes of @p s1 and @p s2.
+ * @return Negative, zero, or positive integer.
+ */
+int ft_memcmp (const void *s1, const void *s2, size_t n);
+
+/* ======================================
+ * Memory allocation
+ * ====================================== */
+
+/**
+ * @brief Allocate zeroed memory for @p nmemb elements of @p size bytes.
+ * @return NULL on overflow or allocation failure.
+ */
+void *ft_calloc (size_t nmemb, size_t size);
+
+#endif