|
Libft
Custom implementation of core libc functions with additional utility helpers.
|
Dynamic growable buffer utilities. More...
Functions | |
| bool | buff_adjust (t_buff *buff) |
| Shrinks buffer capacity to match its current length. | |
| bool | buff_append (t_buff *dst, const t_buff *src) |
| Appends the content of a source buffer to the end of a buffer. | |
| bool | buff_append_format (t_buff *buff, const char *fstring,...) |
| Appends formatted string to buffer using variadic arguments. | |
| bool | buff_append_n (t_buff *b, const char *str, long n) |
| Appends n first bytes of a string to the end of the buffer. | |
| bool | buff_append_vformat (t_buff *buff, const char *fstring, va_list args) |
| Appends formatted string to buffer using va_list. | |
| bool | buff_cmp (const t_buff *a, const t_buff *b) |
| Compares two buffers data byte by byte. | |
| bool | buff_dup (t_buff *dst, const t_buff *src) |
| Copies the content of a source buffer into an existing buffer. | |
| bool | buff_dup_n (t_buff *dst, const t_buff *src, size_t n) |
| Copies up to n bytes from a source buffer into an existing buffer. | |
| void | buff_free (t_buff *buff) |
| Frees the buffer's internal data. | |
| void | buff_free_void (void *buff) |
| Frees a t_buff item through a generic void* callback signature. | |
| ssize_t | buff_get_index_c (const t_buff *buff, char c) |
| Finds the index of the first occurrence of a character in the buffer. | |
| ssize_t | buff_get_index_s (const t_buff *buff, const char *s, ssize_t slen) |
| Finds the first occurrence of a substring in the buffer. | |
| char * | buff_get_string (const t_buff *buff) |
| Returns a newly allocated copy of the buffer content. | |
| bool | buff_init (t_buff *buff, size_t initial_cap, const char *str, long n) |
| Initializes a buffer with the specified initial capacity. | |
| bool | buff_insert (t_buff *dst, size_t index, const t_buff *src) |
| Inserts a source buffer in a buffer at the specified index. | |
| bool | buff_insert_n (t_buff *b, size_t index, const char *str, long n) |
| Inserts n first bytes of a string in the buffer at specified index. | |
| bool | buff_prepend (t_buff *dst, const t_buff *src) |
| Prepends a source buffer to the beginning of a buffer. | |
| bool | buff_prepend_n (t_buff *b, const char *str, long n) |
| Prepends n first bytes of a string to the beginning of the buffer. | |
| bool | buff_read_all (t_buff *buff, int fd) |
| Reads all available data from a file descriptor into buffer. | |
| bool | buff_read_until_c (t_buff *buff, int fd, char c) |
| Reads from a file descriptor until a specific character is found. | |
| bool | buff_read_until_n (t_buff *buff, int fd, size_t n) |
| Reads up to n bytes from a file descriptor into buffer. | |
| bool | buff_read_until_s (t_buff *buff, int fd, const char *s, ssize_t slen) |
| Reads from a file descriptor until a specific substring is found. | |
| void | buff_rm_part (t_buff *buff, size_t i_start, ssize_t len) |
| Removes a portion of the buffer starting at i_start. | |
Dynamic growable buffer utilities.
Functions to initialize, grow, shrink and manipulate dynamic buffers.
| bool buff_adjust | ( | t_buff * | buff | ) |
Shrinks buffer capacity to match its current length.
| buff | Pointer to an initialized buffer (borrowed). |


Appends the content of a source buffer to the end of a buffer.
Buffer is automatically grown if necessary.
| dst | Destination buffer to append to (borrowed). |
| src | Source buffer to append (borrowed, read-only). |

| bool buff_append_format | ( | t_buff * | buff, |
| const char * | fstring, | ||
| ... | |||
| ) |
Appends formatted string to buffer using variadic arguments.
Supports printf formats:
%c %s %d %i %u %x %X %p %%.
Supports printf-like flags:
-0.#+and width.
| buff | Pointer to an initialized buffer (borrowed). |
| fstring | Format string (borrowed, read-only). |
| ... | Variadic arguments for format specifiers. |

| bool buff_append_n | ( | t_buff * | b, |
| const char * | str, | ||
| long | n | ||
| ) |
Appends n first bytes of a string to the end of the buffer.
Buffer is automatically grown if necessary.
| b | Pointer to an initialized buffer (borrowed). |
| str | String to append (borrowed, read-only). |
| n | Number of bytes to append, or -1 to use str_len(str). |


| bool buff_append_vformat | ( | t_buff * | buff, |
| const char * | fstring, | ||
| va_list | args | ||
| ) |
Appends formatted string to buffer using va_list.
| buff | Pointer to an initialized buffer (borrowed). |
| fstring | Format string (borrowed, read-only). |
| args | Variable argument list. |


Compares two buffers data byte by byte.
| a | First buffer to compare (borrowed, read-only). |
| b | Second buffer to compare (borrowed, read-only). |
Copies the content of a source buffer into an existing buffer.
| dst | Destination buffer to overwrite (borrowed, initialized). |
| src | Source buffer to duplicate (borrowed, initialized). |

Copies up to n bytes from a source buffer into an existing buffer.
| dst | Destination buffer to overwrite (borrowed, initialized). |
| src | Source buffer to duplicate (borrowed, initialized). |
| n | Maximum number of bytes to copy. |


| void buff_free | ( | t_buff * | buff | ) |
Frees the buffer's internal data.
Sets buff->data to NULL after freeing. Sets buff->len and buff->cap to 0 after freeing.
| buff | Pointer to the buffer (borrowed). |

| void buff_free_void | ( | void * | buff | ) |
Frees a t_buff item through a generic void* callback signature.
Wrapper around buff_free() intended for APIs that expect void (*)(void *), such as vector_free().
| buff | Pointer to a t_buff item passed as void* (borrowed). |

| ssize_t buff_get_index_c | ( | const t_buff * | buff, |
| char | c | ||
| ) |
Finds the index of the first occurrence of a character in the buffer.
| buff | Pointer to an initialized buffer (borrowed, read-only). |
| c | Character to find. |
| ssize_t buff_get_index_s | ( | const t_buff * | buff, |
| const char * | s, | ||
| ssize_t | slen | ||
| ) |
Finds the first occurrence of a substring in the buffer.
| buff | Pointer to an initialized buffer (borrowed, read-only). |
| s | Substring to find (borrowed, read-only). |
| slen | Number of bytes in s, or -1 to use str_len(s). |

| char * buff_get_string | ( | const t_buff * | buff | ) |
Returns a newly allocated copy of the buffer content.
If the buffer data is not null-terminated, a trailing '\0' is added in the returned string.
| buff | Pointer to an initialized buffer (borrowed, read-only). |

| bool buff_init | ( | t_buff * | buff, |
| size_t | initial_cap, | ||
| const char * | str, | ||
| long | n | ||
| ) |
Initializes a buffer with the specified initial capacity.
If str is not NULL, it is appended after initialization. If str is NULL, n is ignored.
| buff | Pointer to the buffer structure to initialize (borrowed, uninitialized). |
| initial_cap | Initial capacity of the buffer. |
| str | Optional string to append after initialization (borrowed, read-only). |
| n | Number of bytes to append, or -1 to use str_len(str). |


Inserts a source buffer in a buffer at the specified index.
Buffer is automatically grown if necessary.
| dst | Destination buffer to insert into (borrowed). |
| index | Insertion index. |
| src | Source buffer to insert (borrowed, read-only). |

| bool buff_insert_n | ( | t_buff * | b, |
| size_t | index, | ||
| const char * | str, | ||
| long | n | ||
| ) |
Inserts n first bytes of a string in the buffer at specified index.
Buffer is automatically grown if necessary.
| b | Pointer to an initialized buffer (borrowed). |
| index | Insertion index. |
| str | String to insert (borrowed, read-only). |
| n | Number of bytes to insert, or -1 to use str_len(str). |


Prepends a source buffer to the beginning of a buffer.
Buffer is automatically grown if necessary.
| dst | Destination buffer to prepend to (borrowed). |
| src | Source buffer to prepend (borrowed, read-only). |

| bool buff_prepend_n | ( | t_buff * | b, |
| const char * | str, | ||
| long | n | ||
| ) |
Prepends n first bytes of a string to the beginning of the buffer.
Buffer is automatically grown if necessary.
| b | Pointer to an initialized buffer (borrowed). |
| str | String to prepend (borrowed, read-only). |
| n | Number of bytes to prepend, or -1 to use str_len(str). |


| bool buff_read_all | ( | t_buff * | buff, |
| int | fd | ||
| ) |
Reads all available data from a file descriptor into buffer.
| buff | Pointer to an initialized buffer (borrowed). |
| fd | File descriptor to read from. |

| bool buff_read_until_c | ( | t_buff * | buff, |
| int | fd, | ||
| char | c | ||
| ) |
Reads from a file descriptor until a specific character is found.
| buff | Pointer to an initialized buffer (borrowed). |
| fd | File descriptor to read from. |
| c | Character to search for. |

| bool buff_read_until_n | ( | t_buff * | buff, |
| int | fd, | ||
| size_t | n | ||
| ) |
Reads up to n bytes from a file descriptor into buffer.
| buff | Pointer to an initialized buffer (borrowed). |
| fd | File descriptor to read from. |
| n | Number of bytes to read. |

| bool buff_read_until_s | ( | t_buff * | buff, |
| int | fd, | ||
| const char * | s, | ||
| ssize_t | slen | ||
| ) |
Reads from a file descriptor until a specific substring is found.
| buff | Pointer to an initialized buffer (borrowed). |
| fd | File descriptor to read from. |
| s | Target substring to search for (borrowed, read-only). |
| slen | Length of s, or -1 to use str_len(s). |

| void buff_rm_part | ( | t_buff * | buff, |
| size_t | i_start, | ||
| ssize_t | len | ||
| ) |
Removes a portion of the buffer starting at i_start.
| buff | Pointer to an initialized buffer (borrowed). |
| i_start | Starting index for removal. |
| len | Number of bytes to remove, or negative to remove until end. |
