|
Libft
Custom implementation of core libc functions with additional utility helpers.
|
#include "libft.h"#include "buff_internal.h"#include <errno.h>#include <stdlib.h>#include <unistd.h>
Macros | |
| #define | DEFAULT_BUFF_CAP 128 |
| #define | BUFF_GROWTH 2 |
Functions | |
| size_t | buff_get_required_cap (size_t current_cap, size_t target_len) |
| Calculates the required capacity to accommodate a target length. | |
| bool | buff_grow (t_buff *buff, size_t target_len) |
| Grows the buffer to accommodate the target length if necessary. | |
| ssize_t | buff_read_n_bytes (t_buff *buff, int fd, size_t n) |
| Reads up to n bytes from a file descriptor into a buffer. | |
| #define BUFF_GROWTH 2 |
| #define DEFAULT_BUFF_CAP 128 |
| size_t buff_get_required_cap | ( | size_t | current_cap, |
| size_t | target_len | ||
| ) |
Calculates the required capacity to accommodate a target length.
Uses exponential growth strategy (doubles capacity) to amortize multiple growth operations to O(1) on average.
| current_cap | Current capacity of the buffer. |
| target_len | Target length to accommodate. |

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


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