|
Libft
Custom implementation of core libc functions with additional utility helpers.
|
#include "libft.h"#include "string_internal.h"#include <errno.h>#include <stdlib.h>#include <unistd.h>
Macros | |
| #define | DEFAULT_STRING_CAP 128 |
| #define | STRING_GROWTH 2 |
Functions | |
| size_t | string_get_required_cap (size_t current_cap, size_t target_cap) |
| Calculates the required capacity to accommodate a target cap. | |
| bool | string_grow (t_string *string, size_t target_cap) |
| Grows the string to accommodate the target length if necessary. | |
| ssize_t | string_read_n_bytes (t_string *string, int fd, size_t n) |
| Reads up to n bytes from a file descriptor into a string. | |
| #define DEFAULT_STRING_CAP 128 |
| #define STRING_GROWTH 2 |
| size_t string_get_required_cap | ( | size_t | current_cap, |
| size_t | target_cap | ||
| ) |
Calculates the required capacity to accommodate a target cap.
Uses exponential growth strategy (doubles capacity) to amortize multiple growth operations to O(1) on average.
| current_cap | Current capacity of the string. |
| target_len | Target length to accommodate. |

| bool string_grow | ( | t_string * | string, |
| size_t | target_cap | ||
| ) |
Grows the string to accommodate the target length if necessary.
No-op if current capacity is already sufficient.
| string | Pointer to an initialized string (borrowed). |
| target_len | The minimum length the string should accommodate. |


| ssize_t string_read_n_bytes | ( | t_string * | string, |
| int | fd, | ||
| size_t | n | ||
| ) |
Reads up to n bytes from a file descriptor into a string.
Reads directly at the end of string->data and increases string->len by the number of bytes read. Reading stops after n bytes, EOF, or a read error.
| string | Pointer to an initialized string (borrowed). |
| fd | File descriptor to read from. |
| n | Maximum number of bytes to read. |
