minishell
vect_append_range.c File Reference
#include "ft_vect.h"
#include "../ft_math/ft_math.h"
#include "../ft_mem/ft_mem.h"
Include dependency graph for vect_append_range.c:

Go to the source code of this file.

Functions

static bool vect_append_internal (t_vect *vect, const void *value, size_t count, int is_str)
 
bool vect_append_range (t_vect *vect, const void *value, size_t count)
 
bool vect_append_str (t_vect *vect, const char *value, size_t count)
 

Variables

static const int g_flag_string = 1
 
static const int g_flag_not_string = 0
 

Function Documentation

◆ vect_append_internal()

static bool vect_append_internal ( t_vect vect,
const void *  value,
size_t  count,
int  is_str 
)
static

Definition at line 21 of file vect_append_range.c.

23 {
24  size_t bytes_to_copy;
25  size_t new_len;
26 
27  if (!can_mulp(vect->elemsize, count))
28  return (false);
29  if (!can_addp(vect->len, count))
30  return (false);
31  new_len = vect->len + count;
32  if (vect->cap < (new_len + is_str) && !vect_reserve(vect, new_len + is_str))
33  return (false);
34  bytes_to_copy = vect->elemsize * count;
35  ft_memmove(((unsigned char *)vect->p) + (vect->len * vect->elemsize),
36  value, bytes_to_copy);
37  vect->len = new_len;
38  if (is_str)
39  ((char *)(vect->p))[vect->len] = '\0';
40  return (true);
41 }
bool can_addp(size_t a, size_t b)
Definition: can_add.c:43
bool can_mulp(size_t a, size_t b)
Definition: can_mul.c:50
void * ft_memmove(void *dst, const void *src, size_t n)
Definition: ft_memmove.c:16
bool vect_reserve(t_vect *vect, size_t newcap)
Definition: vect_reserve.c:17
size_t cap
Definition: ft_vect.h:25
size_t elemsize
Definition: ft_vect.h:27
void * p
Definition: ft_vect.h:28
size_t len
Definition: ft_vect.h:26
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vect_append_range()

bool vect_append_range ( t_vect vect,
const void *  value,
size_t  count 
)

Definition at line 43 of file vect_append_range.c.

44 {
45  return (vect_append_internal(vect, value, count, g_flag_not_string));
46 }
static const int g_flag_not_string
static bool vect_append_internal(t_vect *vect, const void *value, size_t count, int is_str)
Here is the call graph for this function:

◆ vect_append_str()

bool vect_append_str ( t_vect vect,
const char *  value,
size_t  count 
)

Definition at line 48 of file vect_append_range.c.

49 {
50  return (vect_append_internal(vect, value, count, g_flag_string));
51 }
static const int g_flag_string
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ g_flag_not_string

const int g_flag_not_string = 0
static

Definition at line 19 of file vect_append_range.c.

◆ g_flag_string

const int g_flag_string = 1
static

Definition at line 18 of file vect_append_range.c.