minishell
ft_mem.h File Reference
#include <stddef.h>
Include dependency graph for ft_mem.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void * ft_memset (void *b, int c, size_t len)
 
void ft_bzero (void *s, size_t n)
 
void * ft_memcpy (void *dst, const void *src, size_t n)
 
void * ft_memmove (void *dst, const void *src, size_t n)
 
void * ft_memchr (const void *s, int c, size_t n)
 
int ft_memcmp (const void *s1, const void *s2, size_t n)
 
void * ft_calloc (size_t count, size_t size)
 
void * ft_calloc_nofill (size_t count, size_t size)
 
void ft_swap (void *a, void *b, size_t bytes)
 

Function Documentation

◆ ft_bzero()

void ft_bzero ( void *  s,
size_t  n 
)

Definition at line 15 of file ft_bzero.c.

16 {
17  char *ptr;
18 
19  ptr = s;
20  while (n-- > 0)
21  {
22  *ptr = 0;
23  ptr++;
24  }
25 }
Here is the caller graph for this function:

◆ ft_calloc()

void* ft_calloc ( size_t  count,
size_t  size 
)

Definition at line 29 of file ft_calloc.c.

30 {
31  void *p_ret;
32 
33  p_ret = ft_calloc_nofill(count, size);
34  if (p_ret != NULL)
35  ft_bzero(p_ret, count * size);
36  return (p_ret);
37 }
void ft_bzero(void *s, size_t n)
Definition: ft_bzero.c:15
void * ft_calloc_nofill(size_t count, size_t size)
Definition: ft_calloc.c:17
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_calloc_nofill()

void* ft_calloc_nofill ( size_t  count,
size_t  size 
)

Definition at line 17 of file ft_calloc.c.

18 {
19  size_t bytes_to_allocate;
20 
21  if (!can_mulp(count, size))
22  return (NULL);
23  bytes_to_allocate = count * size;
24  if (bytes_to_allocate <= 0)
25  bytes_to_allocate = 1;
26  return (malloc(bytes_to_allocate));
27 }
bool can_mulp(size_t a, size_t b)
Definition: can_mul.c:50
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_memchr()

void* ft_memchr ( const void *  s,
int  c,
size_t  n 
)

Definition at line 16 of file ft_memchr.c.

17 {
18  unsigned char *p_s;
19  unsigned char looking_for;
20 
21  if (n == 0)
22  return (NULL);
23  p_s = (unsigned char *)s;
24  looking_for = (unsigned char)c;
25  while (--n > 0 && *p_s != looking_for)
26  p_s++;
27  if (*p_s == looking_for)
28  return (p_s);
29  else
30  return (NULL);
31 }
Here is the caller graph for this function:

◆ ft_memcmp()

int ft_memcmp ( const void *  s1,
const void *  s2,
size_t  n 
)

Definition at line 16 of file ft_memcmp.c.

17 {
18  unsigned char *p_s1;
19  unsigned char *p_s2;
20 
21  if (n == 0)
22  return (0);
23  p_s1 = (unsigned char *)s1;
24  p_s2 = (unsigned char *)s2;
25  while (--n > 0 && *p_s1 == *p_s2)
26  {
27  p_s1++;
28  p_s2++;
29  }
30  return ((int)(*p_s1) - (int)(*p_s2));
31 }

◆ ft_memcpy()

void* ft_memcpy ( void *  dst,
const void *  src,
size_t  n 
)

Definition at line 15 of file ft_memcpy.c.

16 {
17  return (ft_memmove(dst, src, n));
18 }
void * ft_memmove(void *dst, const void *src, size_t n)
Definition: ft_memmove.c:16
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_memmove()

void* ft_memmove ( void *  dst,
const void *  src,
size_t  n 
)

Definition at line 16 of file ft_memmove.c.

17 {
18  unsigned char *p_c_dst;
19  unsigned char *p_c_src;
20  signed char direction;
21 
22  if (src == dst || n == 0)
23  return (dst);
24  p_c_dst = (unsigned char *)dst;
25  p_c_src = (unsigned char *)src;
26  if (dst > src)
27  {
28  p_c_dst += n - 1;
29  p_c_src += n - 1;
30  direction = -1;
31  }
32  else
33  direction = 1;
34  while (n-- > 0)
35  {
36  *p_c_dst = *p_c_src;
37  p_c_dst += direction;
38  p_c_src += direction;
39  }
40  return (dst);
41 }
Here is the caller graph for this function:

◆ ft_memset()

void* ft_memset ( void *  b,
int  c,
size_t  len 
)

Definition at line 16 of file ft_memset.c.

17 {
18  unsigned char *p_c_target;
19 
20  p_c_target = target;
21  while (len_to_fill-- > 0)
22  {
23  *p_c_target = (unsigned char)val_to_set;
24  p_c_target++;
25  }
26  return (target);
27 }

◆ ft_swap()

void ft_swap ( void *  a,
void *  b,
size_t  bytes 
)

Definition at line 32 of file ft_swap.c.

33 {
34  _ft_swap(a, b, bytes);
35 }
void _ft_swap(unsigned char *a, unsigned char *b, size_t bytes)
Definition: ft_swap.c:15
Here is the call graph for this function:
Here is the caller graph for this function: