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

Go to the source code of this file.

Functions

size_t buff_get_required_cap (size_t current_cap, size_t target_len)
 Calculates the required capacity to accommodate a target length.
 
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.
 

Function Documentation

◆ buff_get_required_cap()

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.

Parameters
current_capCurrent capacity of the buffer.
target_lenTarget length to accommodate.
Returns
The new required capacity.
Here is the caller graph for this function:

◆ buff_read_n_bytes()

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.

Note
Interrupted reads (EINTR) are retried.
Warning
buff must be initialized before calling this function.
buff must have enough available capacity for n additional bytes.
Parameters
buffPointer to an initialized buffer (borrowed).
fdFile descriptor to read from.
nMaximum number of bytes to read.
Returns
Number of bytes read, or -1 on read error.
Here is the caller graph for this function: