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

Go to the source code of this file.

Functions

size_t string_get_required_cap (size_t current_cap, size_t target_cap)
 Calculates the required capacity to accommodate a target cap.
 
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.
 

Function Documentation

◆ string_get_required_cap()

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.

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

◆ string_read_n_bytes()

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.

Note
Interrupted reads (EINTR) are retried.
Warning
string must be initialized before calling this function.
string must have enough available capacity for n additional bytes.
Parameters
stringPointer to an initialized string (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: