gnl merge
This commit is contained in:
commit
fe95fda94d
55 changed files with 600 additions and 104 deletions
45
libft/includes/btree.h
Normal file
45
libft/includes/btree.h
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* btree.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/16 11:13:15 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/16 11:14:02 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef BTREE_H
|
||||
# define BTREE_H
|
||||
|
||||
# include "libft.h"
|
||||
|
||||
typedef struct s_btree t_btree;
|
||||
|
||||
struct s_btree
|
||||
{
|
||||
void *item;
|
||||
size_t content_size;
|
||||
struct s_btree *left;
|
||||
struct s_btree *right;
|
||||
};
|
||||
|
||||
t_btree *btree_create_node(void const *item, size_t content_size);
|
||||
|
||||
void btree_insert_data(
|
||||
t_btree **root,
|
||||
void *item,
|
||||
size_t content_size,
|
||||
int (*cmpf)(void *, void *));
|
||||
|
||||
void *btree_search_item(t_btree *root,
|
||||
void *data_ref, int (*cmpf)(void *, void *));
|
||||
|
||||
int btree_level_count(t_btree *root);
|
||||
void btree_apply_prefix(t_btree *root, void (*applyf)(void *));
|
||||
void btree_apply_infix(t_btree *root, void (*applyf)(void *));
|
||||
void btree_apply_suffix(t_btree *root, void (*applyf)(void *));
|
||||
void btree_print(t_btree *tree, void (*printer)(t_btree *tree));
|
||||
|
||||
#endif
|
||||
|
|
@ -23,12 +23,13 @@ struct s_dlist
|
|||
|
||||
typedef struct s_dlist t_dlist;
|
||||
|
||||
void ft_dlst_add_after(t_dlist **alst, t_dlist *new);
|
||||
void ft_dlst_add_before(t_dlist **alst, t_dlist *new);
|
||||
void ft_dlst_delone(t_dlist **alst, void (*del)(void *, size_t));
|
||||
int ft_dlst_size(t_dlist *list);
|
||||
t_dlist *ft_dlst_new(void const *content, size_t content_size);
|
||||
t_dlist *ft_dlst_last(t_dlist *list);
|
||||
void ft_dlstadd_after(t_dlist **alst, t_dlist *new);
|
||||
void ft_dlstadd_before(t_dlist **alst, t_dlist *new);
|
||||
void ft_dlstdel(t_dlist **alst, void (*del)(void *, size_t));
|
||||
void ft_dlstdelone(t_dlist **alst, void (*del)(void *, size_t));
|
||||
int ft_dlstsize(t_dlist *list);
|
||||
t_dlist *ft_dlstnew(void const *content, size_t content_size);
|
||||
t_dlist *ft_dlstlast(t_dlist *list);
|
||||
char *ft_dlsttostr(t_dlist *list);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 13:22:54 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/07 17:26:13 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/16 10:53:57 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -42,6 +42,8 @@ struct s_fmt
|
|||
t_conv conv;
|
||||
};
|
||||
|
||||
int ft_vdprintf(int fd, const char *format, va_list ap);
|
||||
|
||||
extern t_conv g_convs[];
|
||||
|
||||
t_fmt *ft_fmt_init(void);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/07 15:46:27 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/16 10:58:19 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
# include "ft_xattr.h"
|
||||
# include "lst.h"
|
||||
# include "dlst.h"
|
||||
# include "btree.h"
|
||||
|
||||
# include <string.h>
|
||||
# include <unistd.h>
|
||||
|
|
@ -31,6 +32,14 @@
|
|||
# define FT_MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
# define FT_DIST(a, b) (FT_ABS((a) - (b)))
|
||||
|
||||
typedef struct s_stof t_stof;
|
||||
|
||||
struct s_stof
|
||||
{
|
||||
char *name;
|
||||
int (*f)();
|
||||
};
|
||||
|
||||
void ft_debug(void);
|
||||
|
||||
void *ft_memset(void *b, int c, size_t len);
|
||||
|
|
@ -105,16 +114,23 @@ size_t ft_ilen_base(int n, int base);
|
|||
size_t ft_uilen(unsigned int n);
|
||||
size_t ft_lllen(long long n);
|
||||
size_t ft_lllen_base(long long n, int base);
|
||||
int ft_addrcmp(void *a, void *b);
|
||||
|
||||
char **ft_sstradd(char **list, char *new);
|
||||
void ft_sstrsort(char **list, int size, int (*cmp)());
|
||||
void ft_sstrprint(char **list, char sep);
|
||||
char **ft_sstrdup(char **list);
|
||||
char **ft_sstradd(char **list, char *new);
|
||||
void ft_sstrdel(char **sstr, int index);
|
||||
void ft_sstrfree(char **sstr);
|
||||
|
||||
int ft_time_isrecent(time_t event);
|
||||
|
||||
char *ft_path_notdir(char *path);
|
||||
|
||||
int ft_printf(const char *format, ...);
|
||||
int ft_dprintf(int fd, const char *format, ...);
|
||||
|
||||
char *ft_getenv(char **env, char *key);
|
||||
|
||||
void *ft_realloc(void *data, int size);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 13:27:46 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/07 13:31:28 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/08 11:25:38 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -23,6 +23,7 @@ struct s_list
|
|||
typedef struct s_list t_list;
|
||||
|
||||
t_list *ft_lstnew(void const *content, size_t content_size);
|
||||
void ft_lstdel(t_list **alst, void (*del)(void *, size_t));
|
||||
void ft_lstdelone(t_list **alst, void (*del)(void *, size_t));
|
||||
void ft_lstadd(t_list **alst, t_list *new);
|
||||
void ft_lstiter(t_list *lst, void (*f)(t_list *elem));
|
||||
|
|
|
|||
46
libft/src/btree/btree_apply_by_level.c
Normal file
46
libft/src/btree/btree_apply_by_level.c
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* btree_apply_by_level.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/08/19 12:06:15 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/16 11:14:28 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "btree.h"
|
||||
|
||||
int g_level = 0;
|
||||
|
||||
static void btree_apply_to_level(
|
||||
t_btree *root,
|
||||
int level,
|
||||
int is_first_elem,
|
||||
void (*applyf)(void *item, int current_level, int is_first_elem))
|
||||
{
|
||||
if (level == g_level)
|
||||
{
|
||||
(*applyf)(root->item, level, is_first_elem);
|
||||
return ;
|
||||
}
|
||||
if (root->left)
|
||||
btree_apply_to_level(root->left, level + 1, is_first_elem, applyf);
|
||||
if (root->right)
|
||||
btree_apply_to_level(root->right, level + 1, 0, applyf);
|
||||
}
|
||||
|
||||
void btree_apply_by_level(
|
||||
t_btree *root,
|
||||
void (*applyf)(void *item, int current_level, int is_first_elem))
|
||||
{
|
||||
int height;
|
||||
|
||||
height = btree_level_count(root);
|
||||
while (g_level < height)
|
||||
{
|
||||
btree_apply_to_level(root, 0, 1, applyf);
|
||||
g_level++;
|
||||
}
|
||||
}
|
||||
23
libft/src/btree/btree_apply_infix.c
Normal file
23
libft/src/btree/btree_apply_infix.c
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* btree_create_node.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/14 11:58:47 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "btree.h"
|
||||
|
||||
void btree_apply_infix(t_btree *root, void (*applyf)(void *))
|
||||
{
|
||||
if (root->left)
|
||||
btree_apply_infix(root->left, applyf);
|
||||
(*applyf)(root->item);
|
||||
if (root->right)
|
||||
btree_apply_infix(root->right, applyf);
|
||||
return ;
|
||||
}
|
||||
22
libft/src/btree/btree_apply_prefix.c
Normal file
22
libft/src/btree/btree_apply_prefix.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* btree_create_node.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */
|
||||
/* Updated: 2016/08/18 21:06:44 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "btree.h"
|
||||
|
||||
void btree_apply_prefix(t_btree *root, void (*applyf)(void *))
|
||||
{
|
||||
(*applyf)(root->item);
|
||||
if (root->left)
|
||||
btree_apply_prefix(root->left, applyf);
|
||||
if (root->right)
|
||||
btree_apply_prefix(root->right, applyf);
|
||||
}
|
||||
23
libft/src/btree/btree_apply_suffix.c
Normal file
23
libft/src/btree/btree_apply_suffix.c
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* btree_create_node.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/14 16:08:23 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "btree.h"
|
||||
|
||||
void btree_apply_suffix(t_btree *root, void (*applyf)(void *))
|
||||
{
|
||||
if (root->left)
|
||||
btree_apply_suffix(root->left, applyf);
|
||||
if (root->right)
|
||||
btree_apply_suffix(root->right, applyf);
|
||||
(*applyf)(root->item);
|
||||
return ;
|
||||
}
|
||||
35
libft/src/btree/btree_create_node.c
Normal file
35
libft/src/btree/btree_create_node.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* btree_create_node.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/14 16:11:49 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "btree.h"
|
||||
|
||||
t_btree *btree_create_node(void const *item, size_t content_size)
|
||||
{
|
||||
t_btree *new;
|
||||
|
||||
if (!(new = (t_btree *)malloc(sizeof(t_btree))))
|
||||
return (NULL);
|
||||
new->left = 0;
|
||||
new->right = 0;
|
||||
if (!item)
|
||||
{
|
||||
new->content_size = 0;
|
||||
new->item = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
new->content_size = content_size;
|
||||
new->item = ft_memalloc(content_size + 1);
|
||||
ft_memcpy(new->item, item, content_size);
|
||||
}
|
||||
return (new);
|
||||
}
|
||||
43
libft/src/btree/btree_insert_data.c
Normal file
43
libft/src/btree/btree_insert_data.c
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* btree_create_node.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/14 16:12:47 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "btree.h"
|
||||
|
||||
void btree_insert_data(
|
||||
t_btree **root,
|
||||
void *item,
|
||||
size_t content_size,
|
||||
int (*cmpf)(void *, void *))
|
||||
{
|
||||
t_btree *node;
|
||||
|
||||
if (!*root)
|
||||
{
|
||||
*root = btree_create_node(item, content_size);
|
||||
return ;
|
||||
}
|
||||
node = *root;
|
||||
if ((*cmpf)(item, node->item) < 0)
|
||||
{
|
||||
if (node->left)
|
||||
btree_insert_data(&node->left, item, content_size, cmpf);
|
||||
else
|
||||
node->left = btree_create_node(item, content_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (node->right)
|
||||
btree_insert_data(&node->right, item, content_size, cmpf);
|
||||
else
|
||||
node->right = btree_create_node(item, content_size);
|
||||
}
|
||||
}
|
||||
21
libft/src/btree/btree_level_count.c
Normal file
21
libft/src/btree/btree_level_count.c
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* btree_create_node.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */
|
||||
/* Updated: 2016/08/25 17:46:00 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "btree.h"
|
||||
|
||||
int btree_level_count(t_btree *root)
|
||||
{
|
||||
return (root
|
||||
? 1 + FT_MAX(btree_level_count(root->left),
|
||||
btree_level_count(root->right))
|
||||
: 0);
|
||||
}
|
||||
42
libft/src/btree/btree_print.c
Normal file
42
libft/src/btree/btree_print.c
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* btree_print.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 18:06:24 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/16 11:24:32 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "btree.h"
|
||||
|
||||
static void print_offset(int offset)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < offset)
|
||||
{
|
||||
ft_putstr(" ");
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void btree_print(t_btree *tree, void (*printer)(t_btree *tree))
|
||||
{
|
||||
static int offset = 0;
|
||||
|
||||
print_offset(offset);
|
||||
if (tree == NULL)
|
||||
{
|
||||
ft_putendl("-");
|
||||
return ;
|
||||
}
|
||||
(*printer)(tree);
|
||||
offset += 3;
|
||||
btree_print(tree->right, printer);
|
||||
btree_print(tree->left, printer);
|
||||
offset -= 3;
|
||||
}
|
||||
30
libft/src/btree/btree_search_item.c
Normal file
30
libft/src/btree/btree_search_item.c
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* btree_create_node.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */
|
||||
/* Updated: 2016/08/23 19:04:56 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "btree.h"
|
||||
|
||||
void *btree_search_item(t_btree *root,
|
||||
void *data_ref, int (*cmpf)(void *, void *))
|
||||
{
|
||||
void *out;
|
||||
|
||||
out = NULL;
|
||||
if (root)
|
||||
{
|
||||
out = btree_search_item(root->left, data_ref, cmpf);
|
||||
if (!out && ((*cmpf)(root->item, data_ref) == 0))
|
||||
out = root->item;
|
||||
if (!out)
|
||||
out = btree_search_item(root->right, data_ref, cmpf);
|
||||
}
|
||||
return (out);
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_dlst_add_after(t_dlist **alst, t_dlist *new)
|
||||
void ft_dlstadd_after(t_dlist **alst, t_dlist *new)
|
||||
{
|
||||
if (new)
|
||||
{
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_dlst_add_before(t_dlist **alst, t_dlist *new)
|
||||
void ft_dlstadd_before(t_dlist **alst, t_dlist *new)
|
||||
{
|
||||
if (new)
|
||||
{
|
||||
41
libft/src/dlst/ft_dlstdel.c
Normal file
41
libft/src/dlst/ft_dlstdel.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_dlstdel.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 17:55:40 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/16 11:15:40 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static void ft_dlstdelback(t_dlist **alst, void (*del)(void *, size_t))
|
||||
{
|
||||
if (alst && *alst && del)
|
||||
{
|
||||
ft_dlstdelback(&(*alst)->prev, del);
|
||||
ft_dlstdelone(alst, del);
|
||||
}
|
||||
}
|
||||
|
||||
static void ft_dlstdelfront(t_dlist **alst, void (*del)(void *, size_t))
|
||||
{
|
||||
if (alst && *alst && del)
|
||||
{
|
||||
ft_dlstdelfront(&(*alst)->next, del);
|
||||
ft_dlstdelone(alst, del);
|
||||
}
|
||||
}
|
||||
|
||||
void ft_dlstdel(t_dlist **alst, void (*del)(void *, size_t))
|
||||
{
|
||||
if (alst && *alst && del)
|
||||
{
|
||||
ft_dlstdelback(&(*alst)->prev, del);
|
||||
ft_dlstdelfront(&(*alst)->next, del);
|
||||
ft_dlstdelone(alst, del);
|
||||
}
|
||||
}
|
||||
|
|
@ -6,13 +6,13 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 13:27:13 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/07 13:27:13 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/14 17:52:58 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_dlst_delone(t_dlist **alst, void (*del)(void *, size_t))
|
||||
void ft_dlstdelone(t_dlist **alst, void (*del)(void *, size_t))
|
||||
{
|
||||
t_dlist *tmp;
|
||||
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include "libft.h"
|
||||
|
||||
t_dlist *ft_dlst_last(t_dlist *list)
|
||||
t_dlist *ft_dlstlast(t_dlist *list)
|
||||
{
|
||||
while (list && list->next)
|
||||
list = list->next;
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include "libft.h"
|
||||
|
||||
t_dlist *ft_dlst_new(void const *content, size_t content_size)
|
||||
t_dlist *ft_dlstnew(void const *content, size_t content_size)
|
||||
{
|
||||
t_dlist *new;
|
||||
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 13:27:29 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/07 13:31:08 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/14 16:13:24 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -20,7 +20,7 @@ char *ft_dlsttostr(t_dlist *list)
|
|||
return (NULL);
|
||||
while (list->prev)
|
||||
list = list->prev;
|
||||
str = (char *)ft_strnew(sizeof(char) * (ft_dlst_size(list) + 2));
|
||||
str = (char *)ft_strnew(sizeof(char) * (ft_dlstsize(list) + 2));
|
||||
while (list)
|
||||
{
|
||||
ft_strcat(str, (char *)list->content);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_dlst_size(t_dlist *list)
|
||||
int ft_dlstsize(t_dlist *list)
|
||||
{
|
||||
int size;
|
||||
t_dlist *tmp;
|
||||
26
libft/src/env/ft_getenv.c
vendored
Normal file
26
libft/src/env/ft_getenv.c
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_getenv.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/10 14:30:00 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/16 11:24:52 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_getenv(char **env, char *key)
|
||||
{
|
||||
if (!env)
|
||||
return (NULL);
|
||||
while (*env)
|
||||
{
|
||||
if (ft_strcmp(*env, key) == '=')
|
||||
return (*env + ft_strlen(key) + 1);
|
||||
env++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 13:31:48 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/07 16:56:28 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/16 18:30:20 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -33,9 +33,9 @@ char *ft_unsigned_conversion(t_fmt *fmt, va_list ap)
|
|||
while (fmt->conversion != g_convs[i].id)
|
||||
i++;
|
||||
if (!*fmt->modifier
|
||||
|| ft_strcmp(fmt->modifier, "hh") == 0
|
||||
|| ft_strcmp(fmt->modifier, "h") == 0
|
||||
|| ft_strcmp(fmt->modifier, "z") == 0)
|
||||
|| ft_strequ(fmt->modifier, "hh")
|
||||
|| ft_strequ(fmt->modifier, "h")
|
||||
|| ft_strequ(fmt->modifier, "z"))
|
||||
{
|
||||
uiarg = va_arg(ap, int);
|
||||
return (ft_uitoa_base(uiarg, g_convs[i].base));
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 16:53:07 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/07 17:25:47 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/16 11:15:55 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -38,6 +38,8 @@ static void ft_fmt_validate_flag_conv(t_fmt *fmt)
|
|||
|
||||
i = 0;
|
||||
flag_ptr = fmt->flags;
|
||||
while (fmt->conversion != g_convs[i].id)
|
||||
i++;
|
||||
while (*flag_ptr)
|
||||
{
|
||||
flag = *flag_ptr;
|
||||
|
|
@ -56,8 +58,6 @@ void ft_fmt_validate_flags(t_fmt *fmt)
|
|||
int i;
|
||||
|
||||
i = 0;
|
||||
while (fmt->conversion != g_convs[i].id)
|
||||
i++;
|
||||
ft_fmt_validate_flag_conv(fmt);
|
||||
ft_fmt_validate_flag_flag(fmt);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/07 16:20:10 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/16 18:30:10 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -27,29 +27,49 @@ t_conv g_convs[] =
|
|||
|
||||
int ft_printf(const char *format, ...)
|
||||
{
|
||||
va_list ap1;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
return (ft_vdprintf(1, format, ap));
|
||||
}
|
||||
|
||||
int ft_dprintf(int fd, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
return (ft_vdprintf(fd, format, ap));
|
||||
}
|
||||
|
||||
int ft_vdprintf(int fd, const char *format, va_list ap)
|
||||
{
|
||||
char *str;
|
||||
char *transform;
|
||||
char final[1000];
|
||||
t_fmt *fmt;
|
||||
|
||||
va_start(ap1, format);
|
||||
str = ft_strdup(format);
|
||||
str = (char *)format;
|
||||
ft_bzero(final, 1000);
|
||||
while (*str)
|
||||
{
|
||||
if (*str == '%')
|
||||
{
|
||||
str++;
|
||||
if (!(fmt = ft_printf_parse(&str, ap1)))
|
||||
if (!(fmt = ft_printf_parse(&str, ap)))
|
||||
return (1);
|
||||
if (!fmt->valid)
|
||||
ft_strncat(final, &fmt->conversion, 1);
|
||||
else
|
||||
ft_strcat(final, ft_transform(fmt, ap1));
|
||||
{
|
||||
transform = ft_transform(fmt, ap);
|
||||
ft_strcat(final, transform);
|
||||
free(transform);
|
||||
}
|
||||
free(fmt);
|
||||
}
|
||||
else
|
||||
ft_strncat(final, str++, 1);
|
||||
}
|
||||
ft_putstr(final);
|
||||
ft_putstr_fd(final, fd);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 13:33:24 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/07 16:56:47 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/10 12:59:50 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 13:33:32 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/07 16:40:15 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/16 17:56:37 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
char *ft_transform(t_fmt *fmt, va_list ap)
|
||||
{
|
||||
char *buf;
|
||||
char *ret;
|
||||
int i;
|
||||
|
||||
|
|
@ -24,11 +23,7 @@ char *ft_transform(t_fmt *fmt, va_list ap)
|
|||
fmt->conv = g_convs[i];
|
||||
ret = (*fmt->conv.converter)(fmt, ap);
|
||||
if (fmt->width > (int)ft_strlen(ret))
|
||||
{
|
||||
buf = ret;
|
||||
ret = (char *)malloc(sizeof(char) * (fmt->width + 5));
|
||||
ft_strcpy(ret, buf);
|
||||
}
|
||||
ret = ft_realloc(ret, fmt->width + 5);
|
||||
if (ft_strchr(fmt->flags, '-'))
|
||||
ft_pad_right(ret, fmt);
|
||||
else
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 13:33:35 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/07 17:22:26 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/16 17:46:16 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 13:33:45 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/07 16:58:00 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/16 18:13:08 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -24,7 +24,7 @@ void ft_pad_left(char *str, t_fmt *fmt)
|
|||
{
|
||||
char sign;
|
||||
|
||||
sign = '\0';
|
||||
sign = 0;
|
||||
if (str[0] == '-' || str[0] == '+' || str[0] == ' ')
|
||||
{
|
||||
sign = str[0];
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 13:33:48 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/07 16:58:09 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/16 17:56:42 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@
|
|||
/* ************************************************************************** */
|
||||
|
||||
#include "get_next_line.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static int ft_fdcmp(t_save *a, int *b)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/04 11:09:10 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/04 11:09:11 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/08 11:09:49 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/04 11:09:12 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/04 11:47:22 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/16 18:23:24 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,32 +14,24 @@
|
|||
|
||||
void ft_lst_delif(
|
||||
t_list **alst,
|
||||
void *data_ref, int (*cmp)(),
|
||||
void *data_ref,
|
||||
int (*cmp)(),
|
||||
void (*del)(void *, size_t))
|
||||
{
|
||||
t_list *last;
|
||||
t_list *current;
|
||||
t_list *tmp;
|
||||
t_list **indirect;
|
||||
|
||||
last = NULL;
|
||||
current = *alst;
|
||||
tmp = NULL;
|
||||
while (current)
|
||||
indirect = alst;
|
||||
while (*indirect)
|
||||
{
|
||||
if ((*cmp)(current->content, data_ref) == 0)
|
||||
if ((*cmp)((*indirect)->content, data_ref) == 0)
|
||||
{
|
||||
if (current == *alst)
|
||||
*alst = current->next;
|
||||
else
|
||||
last->next = current->next;
|
||||
tmp = current;
|
||||
current = current->next;
|
||||
ft_lstdelone(&tmp, del);
|
||||
tmp = (*indirect);
|
||||
(*indirect) = (*indirect)->next;
|
||||
ft_printf("free'd at %p\n", tmp);
|
||||
(*del)(tmp->content, tmp->content_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
last = current;
|
||||
current = current->next;
|
||||
}
|
||||
indirect = &(*indirect)->next;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/04 11:09:15 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/04 12:00:41 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/08 13:36:17 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/04 11:09:30 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/04 13:07:22 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/16 14:00:07 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,15 +17,14 @@ t_list *ft_lst_removeif(t_list **alst, void *data_ref, int (*cmp)())
|
|||
t_list *tmp;
|
||||
t_list **indirect;
|
||||
|
||||
tmp = NULL;
|
||||
indirect = alst;
|
||||
while (*indirect)
|
||||
{
|
||||
if ((*cmp)((*indirect)->content, data_ref) == 0)
|
||||
{
|
||||
tmp = (*indirect);
|
||||
tmp->next = NULL;
|
||||
(*indirect) = (*indirect)->next;
|
||||
tmp->next = NULL;
|
||||
return (tmp);
|
||||
}
|
||||
indirect = &(*indirect)->next;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 15:18:57 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 16:40:21 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/16 18:24:38 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,7 +14,11 @@
|
|||
|
||||
void ft_lstdel(t_list **alst, void (*del)(void *, size_t))
|
||||
{
|
||||
if ((*alst)->next)
|
||||
if (alst && *alst && del)
|
||||
{
|
||||
ft_printf("free'd at %p\n", *alst);
|
||||
ft_lstdel(&(*alst)->next, del);
|
||||
ft_lstdelone(&(*alst), del);
|
||||
ft_lstdelone(alst, del);
|
||||
*alst = NULL;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:15 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 15:15:51 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/16 18:22:47 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,11 +14,11 @@
|
|||
|
||||
void ft_lstdelone(t_list **alst, void (*del)(void *, size_t))
|
||||
{
|
||||
if (*alst)
|
||||
if (alst && *alst)
|
||||
{
|
||||
if (del)
|
||||
(*del)((*alst)->content, (*alst)->content_size);
|
||||
free(*alst);
|
||||
*alst = NULL;
|
||||
}
|
||||
*alst = NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,23 +16,19 @@ t_list *ft_lstnew(void const *content, size_t content_size)
|
|||
{
|
||||
t_list *new;
|
||||
|
||||
if (!(new = (t_list *)malloc(sizeof(*new))))
|
||||
return (NULL);
|
||||
new->next = NULL;
|
||||
if (!content)
|
||||
{
|
||||
new = malloc(sizeof(*new));
|
||||
if (!new)
|
||||
return (NULL);
|
||||
new->content_size = 0;
|
||||
new->content = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
new = (t_list *)malloc(sizeof(*new));
|
||||
if (!new)
|
||||
return (NULL);
|
||||
new->content_size = content_size;
|
||||
new->content = ft_memalloc(content_size + 1);
|
||||
ft_memcpy(new->content, content, content_size);
|
||||
}
|
||||
new->next = NULL;
|
||||
return (new);
|
||||
}
|
||||
|
|
|
|||
18
libft/src/math/ft_addrcmp.c
Normal file
18
libft/src/math/ft_addrcmp.c
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_addrcmp.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 15:59:10 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/14 15:59:39 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_addrcmp(void *a, void *b)
|
||||
{
|
||||
return (a - b);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:25 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 14:57:25 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/11 17:40:57 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:28 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 14:57:29 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/11 17:41:21 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:31 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/07 13:10:31 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/11 17:39:00 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:33 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 14:57:33 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/16 12:23:13 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,6 +14,9 @@
|
|||
|
||||
void ft_memdel(void **ap)
|
||||
{
|
||||
free(*ap);
|
||||
*ap = NULL;
|
||||
if (ap && *ap)
|
||||
{
|
||||
free(*ap);
|
||||
*ap = NULL;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:34 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/07 13:46:42 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/11 17:41:14 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
23
libft/src/mem/ft_realloc.c
Normal file
23
libft/src/mem/ft_realloc.c
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_realloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/11 17:37:53 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/16 17:56:17 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_realloc(void *data, int size)
|
||||
{
|
||||
void *new;
|
||||
|
||||
new = ft_memalloc(size);
|
||||
ft_memcpy(new, data, ft_strlen(data));
|
||||
ft_memdel(&data);
|
||||
return (new);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/04 11:45:07 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/04 11:45:08 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/16 12:07:21 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 18:03:58 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 18:04:23 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/14 16:31:02 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -22,7 +22,8 @@ char **ft_sstradd(char **sstr, char *new)
|
|||
size = 0;
|
||||
while (sstr && sstr[size])
|
||||
size++;
|
||||
newlist = (char **)malloc(sizeof(char *) * (size + 3));
|
||||
if (!(newlist = (char **)malloc(sizeof(char *) * (size + 2))))
|
||||
return (NULL);
|
||||
while (sstr && *sstr)
|
||||
newlist[i++] = *sstr++;
|
||||
newlist[i++] = new;
|
||||
|
|
|
|||
30
libft/src/sstr/ft_sstrfree.c
Normal file
30
libft/src/sstr/ft_sstrfree.c
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_sstrfree.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/08 17:01:24 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/14 11:08:19 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_sstrfree(char **sstr)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (sstr)
|
||||
{
|
||||
while (sstr[i])
|
||||
{
|
||||
ft_strdel(sstr + i);
|
||||
i++;
|
||||
}
|
||||
ft_strdel(sstr + i);
|
||||
free(sstr);
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/08/07 10:56:53 by jhalford #+# #+# */
|
||||
/* Updated: 2016/08/20 23:16:44 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/10 12:18:00 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -19,7 +19,7 @@ char *ft_strcat(char *s1, const char *s2)
|
|||
|
||||
size = ft_strlen(s1);
|
||||
j = 0;
|
||||
while (s2[j] != '\0')
|
||||
while (s2 && s2[j])
|
||||
{
|
||||
s1[size + j] = s2[j];
|
||||
j++;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 15:46:03 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/07 15:46:11 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/16 17:58:02 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:58:18 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 14:58:18 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/10 10:14:09 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:58:22 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 14:58:23 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/10 10:14:18 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:58:43 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 14:58:43 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/16 17:52:01 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,8 +17,7 @@ char *ft_strsub(char const *s, unsigned int start, size_t len)
|
|||
char *out;
|
||||
size_t i;
|
||||
|
||||
out = (char *)malloc(sizeof(char) * (len + 1));
|
||||
if (!out)
|
||||
if (!(out = (char *)malloc(sizeof(char) * (len + 1))))
|
||||
return (NULL);
|
||||
i = -1;
|
||||
while (++i < len)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 18:01:04 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 18:01:19 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/08 16:12:50 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ int ft_time_isrecent(time_t event)
|
|||
time_t now;
|
||||
|
||||
now = time(&now);
|
||||
if (now - event > 0 && now - event < 6 * 365 / 12 * 24 * 60 * 60)
|
||||
if (now - event >= 0 && now - event <= 6 * 365 / 12 * 24 * 60 * 60)
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
|
|
|
|||
Loading…
Reference in a new issue