Libft
Custom implementation of core libc functions with additional utility helpers.
Loading...
Searching...
No Matches
libft.h File Reference
#include <stdarg.h>
#include <stddef.h>
#include <stdbool.h>
#include <sys/types.h>
Include dependency graph for libft.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  s_buff
 Dynamic buffer structure for efficient string/data manipulation. More...
struct  s_node
 Doubly linked list node structure. More...

Macros

#define BUFFER_SIZE   128

Typedefs

typedef struct s_buff t_buff
typedef struct s_node t_node
typedef t_nodet_list
 Type alias for a pointer to a list node (list head).

Functions

bool buff_init (t_buff *b, size_t initial_cap)
 Initializes a buffer with the specified initial capacity.
bool buff_adjust (t_buff *buff)
 Shrinks buffer capacity to match its current length.
void buff_free (t_buff *b)
 Frees the buffer's internal data.
int buff_get_index (t_buff *buff, char c)
 Finds the index of a character in the buffer.
bool buff_prepend (t_buff *b, const char *str, long n)
 Prepends a string to the beginning of the buffer.
bool buff_insert (t_buff *b, size_t index, const char *str, long n)
 Inserts a string at a specific index in the buffer.
bool buff_append (t_buff *b, const char *str, long n)
 Appends a string to the end of the buffer.
t_buffbuff_dup_n (const t_buff *src, size_t n)
 Duplicates up to n bytes of a buffer into a new buffer.
void buff_rm_part (t_buff *buff, size_t i_start, ssize_t len)
 Removes a portion of the buffer starting at i_start.
bool buff_append_format (t_buff *buff, const char *fstring,...)
 Appends formatted string to buffer using variadic arguments.
bool buff_append_vformat (t_buff *buff, const char *fstring, va_list args)
 Appends formatted string to buffer using va_list.
int buff_read_until (t_buff *buff, int fd, char c)
 Reads from a file descriptor until a specific character is found.
bool buff_read_all (t_buff *buff, int fd)
 Reads all available data from a file descriptor into buffer.
int ft_isalnum (int c)
 Checks if a character is alphanumeric.
int ft_isalpha (int c)
 Checks if a character is alphabetic.
int ft_isascii (int c)
 Checks if a character is a valid ASCII character (0-127).
int ft_isdigit (int c)
 Checks if a character is a digit ('0'-'9').
bool ft_isincharset (char c, const char *charset)
 Checks if a character is present in a character set.
int ft_isprint (int c)
 Checks if a character is printable (32-126).
int ft_isspace (char c)
 Checks if a character is whitespace (9-13).
int ft_tolower (int c)
 Converts an uppercase letter to lowercase.
int ft_toupper (int c)
 Converts a lowercase letter to uppercase.
int ft_atoi (const char *str)
 Converts a string to an integer.
long ft_atol (const char *str)
 Converts a string to a long integer.
char * ft_itoa (int n)
 Converts an integer to a string.
char * ft_utoa (unsigned int n)
 Converts an unsigned integer to a string.
char * ft_ltoa (long n)
 Converts a long integer to a string.
char * ft_ultoa_base (unsigned long n, const char *base)
 Converts an unsigned long to a string in a given base.
bool parse_int (char *s, int *out)
 Parses a string to an integer with overflow detection.
t_buffget_next_chunk (int fd, char separator)
 Reads the next chunk from a file descriptor until separator is found.
void get_next_chunk_free (void)
 Frees all internal stashes used by get_next_chunk.
t_nodenode_new (void *content, t_node *prev, t_node *next)
 Creates a new list node.
void node_free (t_node **node, void(*del_content)(void *))
 Frees a node and optionally its content.
bool list_add_end (t_list *list, void *new_content)
 Adds a new element at the end of the list.
bool list_add_start (t_list *list, void *new_content)
 Adds a new element at the start of the list.
size_t list_get_size (t_list list)
 Calculates the number of nodes in the list.
void * list_get_content (t_list list, bool(*select_function)(void *))
 Finds content in list matching a selection function.
void * list_get_content_n (t_list list, size_t index)
 Gets content at a specific index in the list.
void * list_get_content_last (t_list list)
 Gets the content of the last node in the list.
t_nodelist_get_node_n (t_list list, size_t index)
 Gets the node at a specific index in the list.
t_nodelist_get_node_last (t_list list)
 Gets the last node in the list.
void list_iter (t_list lst, void(*f)(void *))
 Applies a function to each element of the list.
t_list list_map (t_list list, void *(*f)(void *), void(*del)(void *))
 Creates a new list by applying a function to each element.
void list_rm (t_list *list, t_node *node, void(*del_content)(void *))
 Removes a specific node from the list.
void list_rm_all (t_list *list, void(*del_content)(void *))
 Removes all nodes from the list.
void * ft_calloc (size_t count, size_t size)
 Allocates and zeroes memory for an array.
bool ft_realloc (char **buff, size_t cap, size_t newcap)
 Reallocates a buffer to a new capacity.
long min (long a, long b)
 Returns the minimum of two long integers.
long max (long a, long b)
 Returns the maximum of two long integers.
size_t absolute (long nbr)
 Returns the absolute value of a long integer.
long power (int a, int b)
 Computes a raised to the power of b.
size_t modulo (long a, size_t b)
 Computes the modulo of a signed integer with an unsigned modulus.
int square_root_exact (int nb)
 Calculates the exact integer square root.
int square_root_rounded (int nb)
 Calculates the nearest integer square root.
void ft_bzero (void *s, size_t n)
 Sets n bytes of memory to zero.
void * ft_memchr (const void *s, int c, size_t n)
 Locates the first occurrence of a byte in memory.
int ft_memcmp (const void *s1, const void *s2, size_t n)
 Compares two memory areas byte by byte.
void * ft_memcpy (void *dst, const void *src, size_t n)
 Copies n bytes from src to dst.
void * ft_memmove (void *dst, const void *src, size_t len)
 Copies n bytes from src to dst, handling overlapping memory.
void * ft_memset (void *b, int c, size_t len)
 Fills memory with a constant byte.
int ft_vdprintf (int fd, const char *fstring, va_list args)
 Writes formatted output to a file descriptor using va_list.
int ft_dprintf (int fd, const char *fstring,...)
 Writes formatted output to a file descriptor.
int ft_vprintf (const char *fstring, va_list args)
 Writes formatted output to stdout using va_list.
int ft_printf (const char *fstring,...)
 Writes formatted output to stdout.
void ft_putchar_fd (char c, int fd)
 Writes a character to a file descriptor.
void ft_putendl_fd (char *s, int fd)
 Writes a string followed by newline to a file descriptor.
void ft_putnbr_fd (int n, int fd)
 Writes an integer to a file descriptor.
void ft_putstr_fd (char *s, int fd)
 Writes a string to a file descriptor.
char ** str_split (char const *s, char c)
 Splits a string into an array of strings using a delimiter.
size_t str_count_words (char const *s, char sep)
 Counts words in a string separated by a delimiter.
void str_array_free (char ***tab_ptr)
 Frees all strings in a null-terminated array and the tab itself.
char * str_chr (const char *s, int c)
 Locates the first occurrence of a character in a string.
char * str_dup (const char *s1)
 Duplicates a string.
void str_iteri (char *s, void(*f)(unsigned int, char *))
 Applies a function to each character of a string with its index.
char * str_join (char const *s1, char const *s2)
 Concatenates two strings into a new string.
size_t str_lcat (char *dst, const char *src, size_t dstsize)
 Appends src to dst with size limit.
size_t str_lcpy (char *dst, const char *src, size_t dstsize)
 Copies src to dst with size limit.
size_t str_len (const char *s)
 Calculates the length of a string.
char * str_mapi (char const *s, char(*f)(unsigned int, char))
 Creates a new string by applying a function to each character.
int str_ncmp (const char *s1, const char *s2, size_t n)
 Compares at most n characters of two strings.
char * str_nstr (const char *haystack, const char *needle, size_t len)
 Locates a substring within a string, limited by length.
char * str_rchr (const char *s, int c)
 Locates the last occurrence of a character in a string.
char * str_trim (char const *s1, char const *set)
 Trims characters from the beginning and end of a string.
char * str_sub (char const *s, unsigned int start, size_t len)
 Extracts a substring from a string.

Macro Definition Documentation

◆ BUFFER_SIZE

#define BUFFER_SIZE   128

Typedef Documentation

◆ t_buff

typedef struct s_buff t_buff

◆ t_list

typedef t_node* t_list

Type alias for a pointer to a list node (list head).

◆ t_node

typedef struct s_node t_node

Function Documentation

◆ ft_putchar_fd()

void ft_putchar_fd ( char c,
int fd )

Writes a character to a file descriptor.

Parameters
cCharacter to write.
fdFile descriptor to write to.

◆ str_array_free()

void str_array_free ( char *** tab_ptr)

Frees all strings in a null-terminated array and the tab itself.

Parameters
tabArray of strings to free.
Returns
NULL always.
Here is the caller graph for this function:

◆ str_count_words()

size_t str_count_words ( char const * s,
char sep )

Counts words in a string separated by a delimiter.

Parameters
sString to analyze.
sepDelimiter character.
Returns
Number of words.
Here is the caller graph for this function: