bonus: ft_lstnew.c
This commit is contained in:
parent
182fa5576b
commit
a9d02d597e
2 changed files with 36 additions and 0 deletions
25
libft/ft_lstnew.c
Normal file
25
libft/ft_lstnew.c
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstnew(void const *content, size_t content_size)
|
||||
{
|
||||
t_list *link;
|
||||
size_t i;
|
||||
|
||||
link->next = NULL;
|
||||
if (!content)
|
||||
{
|
||||
link->content_size = 0;
|
||||
link->content = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
link->content_size = content_size;
|
||||
link->content = ft_memalloc(content_size);
|
||||
if (!link->content)
|
||||
return (NULL);
|
||||
i = -1;
|
||||
while (++i < content_size)
|
||||
((char *)link->content)[i] = ((char *)content)[i];
|
||||
}
|
||||
return (link)
|
||||
}
|
||||
|
|
@ -8,6 +8,13 @@
|
|||
# define NEG(x) (((x) < 0) ? 1 : 0)
|
||||
# define POS(x) (((x) > 0) ? 1 : 0)
|
||||
|
||||
typedef struct s_list
|
||||
{
|
||||
void *content;
|
||||
size_t content_size;
|
||||
struct s_list *next;
|
||||
} t_list;
|
||||
|
||||
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);
|
||||
|
|
@ -36,6 +43,7 @@ int ft_isascii(int c);
|
|||
int ft_isprint(int c);
|
||||
int ft_toupper(int c);
|
||||
int ft_tolower(int c);
|
||||
|
||||
void *ft_memalloc(size_t size);
|
||||
void ft_memdel(void **ap);
|
||||
char *ft_strnew(size_t size);
|
||||
|
|
@ -61,4 +69,7 @@ void ft_putstr_fd(char const *s, int fd);
|
|||
void ft_putendl_fd(char const *s, int fd);
|
||||
void ft_putnbr_fd(int n, int fd);
|
||||
|
||||
t_list *ft_lstnew(void const *content, size_t content_size);
|
||||
void ft_lstadd(t_list **alst, t_list *new);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in a new issue