This repository was archived by the owner on Oct 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_va_add.c
46 lines (43 loc) · 1.77 KB
/
ft_va_add.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_va_add.c :+: :+: */
/* +:+ */
/* By: fbes <fbes@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2022/02/22 17:31:09 by fbes #+# #+# */
/* Updated: 2022/02/23 21:45:35 by fbes ######## odam.nl */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "libft.h"
/**
* Add a pointer to memory to a ft_va_list (the memory gets duplicated)
* @param[in] list The list to append to
* @param[in] index The index to store the pointer at
* @param[in] item The item to duplicate and put into the list
* @param[in] size The size of memory to copy for the duplication (WARNING:
* for strings, include the EOF character in the size!!)
* @return Returns NULL on error, a pointer to the duplicated
* item on success
*/
t_ft_va_item *ft_va_add(t_ft_va_list list, size_t index, void *item,
size_t size)
{
t_ft_va_item *dup;
dup = (t_ft_va_item *)malloc(sizeof(t_ft_va_item));
if (!dup)
return (NULL);
dup->size = size;
if (size > 0)
{
dup->item = malloc(size);
if (!dup->item)
return (ft_free((void *)dup));
ft_memcpy(dup->item, item, size);
}
else
dup->item = NULL;
list[index] = dup;
return (dup);
}