libft
Loading...
Searching...
No Matches
vec_copy.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* vec_copy.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: tspoof <tspoof@student.hive.fi> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2022/12/23 18:22:29 by tspoof #+# #+# */
9/* Updated: 2022/12/23 18:56:29 by tspoof ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "vec.h"
14
15static size_t ft_min(size_t a, size_t b)
16{
17 if (a < b)
18 return (a);
19 return (b);
20}
21
22int vec_copy(t_vec *dst, t_vec *src)
23{
24 size_t len_bytes;
25
26 if (!dst || !src)
27 return (-1);
28 len_bytes = ft_min(dst->alloc_size, src->len * src->elem_size);
29 ft_memcpy(dst->memory, src->memory, len_bytes);
30 dst->len = len_bytes / dst->elem_size;
31 return (1);
32}
void * ft_memcpy(void *dst, const void *src, size_t n)
Copies memory to destination.
Definition ft_memcpy.c:15
Definition vec.h:20
size_t alloc_size
Definition vec.h:23
size_t len
Definition vec.h:24
unsigned char * memory
Definition vec.h:21
size_t elem_size
Definition vec.h:22
int vec_copy(t_vec *dst, t_vec *src)
Definition vec_copy.c:22