diff --git a/libft/Makefile b/libft/Makefile index 64fef351..b6ff4664 100644 --- a/libft/Makefile +++ b/libft/Makefile @@ -66,6 +66,7 @@ ft_printf/ft_printf.c\ ft_printf/ft_printf_color.c\ ft_printf/ft_printf_parse.c\ ft_printf/ft_transform.c\ +ft_printf/ft_vprintf.c\ ft_printf/lib_fmt.c\ ft_printf/lib_fmt_error.c\ ft_printf/lib_pad.c\ @@ -78,7 +79,6 @@ lst/ft_lst_cfree.c\ lst/ft_lst_delif.c\ lst/ft_lst_delsub.c\ lst/ft_lst_filter.c\ -lst/ft_lst_filterout.c\ lst/ft_lst_find.c\ lst/ft_lst_merge.c\ lst/ft_lst_order_delsub.c\ @@ -102,6 +102,7 @@ lst/ft_lstnew_range.c\ lst/ft_lstsort.c\ lst/pop.c\ lst/push.c\ +lst/top.c\ math/ft_addrcmp.c\ math/ft_ilen.c\ math/ft_ilen_base.c\ @@ -115,6 +116,7 @@ math/ft_uitoa_base.c\ math/ft_ulltoa_base.c\ math/id.c\ mem/ft_bzero.c\ +mem/ft_malloc.c\ mem/ft_memalloc.c\ mem/ft_memccpy.c\ mem/ft_memchr.c\ @@ -134,6 +136,7 @@ sstr/ft_sstrcat.c\ sstr/ft_sstrdel.c\ sstr/ft_sstrdup.c\ sstr/ft_sstrfree.c\ +sstr/ft_sstrmerge.c\ sstr/ft_sstrprint.c\ sstr/ft_sstrprint_fd.c\ sstr/ft_sstrsort.c\ @@ -183,10 +186,14 @@ str/ft_strstr.c\ str/ft_strsub.c\ str/ft_strtok.c\ str/ft_strtrim.c\ +sys/create_directory.c\ sys/dup2_close.c\ +sys/fd_replace.c\ sys/ft_getenv.c\ sys/ft_xattr_count.c\ sys/ft_xattr_print.c\ +sys/is_directory.c\ +sys/open_access.c\ time/ft_mytime_free.c\ time/ft_mytime_get.c\ time/ft_time_isrecent.c diff --git a/libft/includes/cliopts.h b/libft/includes/cliopts.h index f70f2345..9ea82890 100644 --- a/libft/includes/cliopts.h +++ b/libft/includes/cliopts.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 20:22:56 by jhalford #+# #+# */ -/* Updated: 2017/03/26 15:25:54 by jhalford ### ########.fr */ +/* Updated: 2017/03/25 14:59:53 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,7 @@ typedef struct s_cliopts t_cliopts; typedef struct s_data_template t_data_template; typedef long long t_flag; -struct s_cliopts +struct s_cliopts { char c; char *str; @@ -30,14 +30,15 @@ struct s_cliopts int arg_required:1; }; -struct s_data_template +struct s_data_template { t_flag flag; char **av_data; }; -int cliopts_get(char **av, t_cliopts opt_map[], void *data); +int cliopts_get(char **av, t_cliopts opt_map[], void *data); t_cliopts *cliopts_getmap_long(t_cliopts opt_map[], char *arg); t_cliopts *cliopts_getmap_short(t_cliopts opt_map[], char arg); +int cliopts_has(char **av, char c); #endif diff --git a/libft/includes/error.h b/libft/includes/error.h index 5138dade..5ea206a9 100644 --- a/libft/includes/error.h +++ b/libft/includes/error.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 15:34:21 by jhalford #+# #+# */ -/* Updated: 2017/03/26 15:35:02 by jhalford ### ########.fr */ +/* Updated: 2017/03/25 01:53:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,21 +16,26 @@ # include "libft.h" # include -# define DG_PROTO "{inv}{ran}%5i{yel}%21s {bol}{blu}%-3d{eoc}" -# define DG_ARGS getpid(), getpid(), ft_path_notdir(__FILE__), __LINE__ -# define DG(s, ...) ft_dprintf(STDBUG, DG_PROTO s "{eoc}\n", DG_ARGS, ##__VA_ARGS__) +# define DG_MSG "{inv}{ran}%5i{yel}%21s {bol}{blu}%-3d{eoc}" +# define DG_ARGS getpid(), getpid(), ft_path_notdir(__FILE__), __LINE__ +# define DG(s, ...) ft_dprintf(STDBUG,DG_MSG s "{eoc}\n",DG_ARGS,##__VA_ARGS__) -# define ERR_PROTO(s, ...) "{red}%s: " s "{eoc}\n", PROGNAME, ##__VA_ARGS__ +# define ERR_PROTO(u, m) "{red}%s: %s{eoc}\n", u, m +# define ERR_MSG(u, m) ft_dprintf(2, ERR_PROTO(u, m)) # define ERR_SET(n, ...) error_set(n, ##__VA_ARGS__) # define ERRMSG_MAX_SIZE 150 -enum e_errors +enum e_errors { E_NOERR, E_CO_INV, E_CO_INVL, + E_CO_MULT, E_CO_MISS, E_CO_MISSL, + E_SYS_NOFILE, + E_SYS_ISDIR, + E_SYS_NOPERM, E_MAX, }; @@ -40,6 +45,6 @@ extern int g_errnum; extern char **g_argv; int error_set(int n, ...); -int ft_perror(void); +int ft_perror(char *utility); #endif diff --git a/libft/includes/ft_printf.h b/libft/includes/ft_printf.h index 4f6d169d..e9299538 100644 --- a/libft/includes/ft_printf.h +++ b/libft/includes/ft_printf.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:22:54 by jhalford #+# #+# */ -/* Updated: 2017/03/14 18:07:10 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 09:23:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -42,6 +42,7 @@ struct s_fmt char conversion; int valid; t_conv conv; + }; int ft_vdprintf(int fd, const char *format, va_list ap); diff --git a/libft/includes/types.h b/libft/includes/ft_types.h similarity index 73% rename from libft/includes/types.h rename to libft/includes/ft_types.h index 45f81361..a8f001cc 100644 --- a/libft/includes/types.h +++ b/libft/includes/ft_types.h @@ -1,22 +1,22 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* types.h :+: :+: :+: */ +/* ft_types.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/28 10:57:17 by jhalford #+# #+# */ -/* Updated: 2017/03/28 10:57:34 by jhalford ### ########.fr */ +/* Created: 2017/03/25 01:56:58 by jhalford #+# #+# */ +/* Updated: 2017/03/25 02:02:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ -#ifndef TYPES_H -# define TYPES_H +#ifndef FT_TYPES_H +# define FT_TYPES_H typedef struct s_stos t_stos; typedef struct s_stof t_stof; typedef struct s_itof t_itof; -typedef long long t_type; -typedef long long t_flag; +typedef long long int t_flag; +typedef long long int t_type; #endif diff --git a/libft/includes/libft.h b/libft/includes/libft.h index 7daf9464..dbecfc8c 100644 --- a/libft/includes/libft.h +++ b/libft/includes/libft.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */ -/* Updated: 2017/03/28 10:58:15 by jhalford ### ########.fr */ +/* Updated: 2017/03/25 01:56:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,14 +14,13 @@ # define LIBFT_H # include +# include # include # include # include # include -# include -# include -# include "types.h" +# include "ft_types.h" # include "error.h" # include "color.h" # include "cliopts.h" @@ -61,6 +60,7 @@ int ft_vdprintf(int fd, const char *format, va_list ap); int ft_asprintf(char **ret, const char *format, ...); int ft_vasprintf(char **ret, const char *format, va_list ap); +void *ft_malloc(size_t size); 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); diff --git a/libft/includes/lst.h b/libft/includes/lst.h index 4b5eb5c0..2b6a9e24 100644 --- a/libft/includes/lst.h +++ b/libft/includes/lst.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:27:46 by jhalford #+# #+# */ -/* Updated: 2017/03/28 20:34:27 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 20:09:05 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,12 +26,13 @@ typedef struct s_list t_list; int pop(t_list **lst); t_list *push(t_list **stack, int elem); +int top(t_list *top); 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); -int ft_lstiter(t_list *lst, int (*f)(), void *data); +int ft_lstiter(t_list *lst, int (*f)()); t_list *ft_lstmap(t_list *lst, void *(*f)(void *)); t_list *ft_lstnew_range(int a, int b); @@ -75,11 +76,6 @@ t_list *ft_lst_find( t_list *ft_lstpop(t_list **lst); void ft_lst_merge(t_list **begin_list1, t_list *begin_list2); void ft_lst_reverse(t_list **begin_list); -void ft_lst_filterout( - t_list **alst, - void *data_ref, - int (*cmp)(), - void (*del)(void *, size_t)); int ft_diff(void *a, void *b); t_list *ft_id(t_list *a); diff --git a/libft/includes/math.h b/libft/includes/math.h index 6b372f7d..2a54ae68 100644 --- a/libft/includes/math.h +++ b/libft/includes/math.h @@ -1,11 +1,12 @@ -/* ************************************************************************** */ /* */ +/* ************************************************************************** */ +/* */ /* ::: :::::::: */ /* math.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/02/18 13:19:12 by jhalford #+# #+# */ -/* Updated: 2017/02/18 13:19:57 by jhalford ### ########.fr */ +/* Created: 2017/03/20 15:41:59 by jhalford #+# #+# */ +/* Updated: 2017/03/20 15:42:13 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/includes/sstr.h b/libft/includes/sstr.h index ac65cd02..b1f10bc2 100644 --- a/libft/includes/sstr.h +++ b/libft/includes/sstr.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/18 13:16:25 by jhalford #+# #+# */ -/* Updated: 2017/03/07 11:35:11 by ariard ### ########.fr */ +/* Updated: 2017/03/24 17:46:36 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,6 +18,7 @@ void ft_sstrsort(char **list, int (*cmp)()); void ft_sstrprint(char **list, char sep); void ft_sstrprint_fd(int fd, char **list, char sep); char **ft_sstrdup(char **list); +char **ft_sstrmerge(char **s1, char **s2); void ft_sstrdel(char **sstr, int index); void ft_sstrfree(char **sstr); char *ft_sstrcat(char **sstr, char sep); diff --git a/libft/includes/sys.h b/libft/includes/sys.h index 3d883032..b3c42e22 100644 --- a/libft/includes/sys.h +++ b/libft/includes/sys.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 17:24:23 by jhalford #+# #+# */ -/* Updated: 2017/03/14 17:24:24 by jhalford ### ########.fr */ +/* Updated: 2017/03/25 15:12:52 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,12 +19,25 @@ # define STDERR STDERR_FILENO # define STDBUG 3 +# define PIPE_READ 0 +# define PIPE_WRITE 1 + # include # include +# include +# include +# include int ft_xattr_print(char *path); int ft_xattr_count(char *path); + char *ft_getenv(char **env, char *key); + +int open_access(char *file, t_flag a_flag, t_flag o_flag, t_flag o_perm); +int is_directory(const char *path); +char *create_directory(const char *path, const char *old_pathnames); + int dup2_close(int fd1, int fd2); +int fd_replace(int fd1, int fd2); #endif diff --git a/libft/srcs/btree/btree_create_node.c b/libft/srcs/btree/btree_create_node.c index 53a90bf7..cc365537 100644 --- a/libft/srcs/btree/btree_create_node.c +++ b/libft/srcs/btree/btree_create_node.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */ -/* Updated: 2017/03/08 00:35:44 by ariard ### ########.fr */ +/* Updated: 2017/03/21 15:43:50 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,7 @@ t_btree *btree_create_node(void const *item, size_t content_size) { t_btree *new; - if (!(new = (t_btree *)malloc(sizeof(t_btree)))) + if (!(new = (t_btree *)ft_malloc(sizeof(t_btree)))) return (NULL); new->left = 0; new->right = 0; diff --git a/libft/srcs/btree/btree_del.c b/libft/srcs/btree/btree_del.c index f9abecb6..8b72f78a 100644 --- a/libft/srcs/btree/btree_del.c +++ b/libft/srcs/btree/btree_del.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/05 11:43:03 by jhalford #+# #+# */ -/* Updated: 2016/12/05 11:53:24 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 19:43:51 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/srcs/btree/btree_map.c b/libft/srcs/btree/btree_map.c index b7751156..47b92852 100644 --- a/libft/srcs/btree/btree_map.c +++ b/libft/srcs/btree/btree_map.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* btree_map.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 11:50:46 by jhalford #+# #+# */ -/* Updated: 2017/03/15 18:43:15 by ariard ### ########.fr */ +/* Updated: 2017/03/24 15:49:42 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,9 @@ t_btree *btree_map(t_btree *root, void *(*f)(void *)) if (!root) return (NULL); - new = btree_create_node((*f)(root->item), root->content_size); + if (!(new = (t_btree *)ft_malloc(sizeof(*new)))) + return (NULL); + new->item = (*f)(root->item); new->left = btree_map(root->left, f); new->right = btree_map(root->right, f); return (new); diff --git a/libft/srcs/btree/btree_print.c b/libft/srcs/btree/btree_print.c index b7422a99..bc1961dc 100644 --- a/libft/srcs/btree/btree_print.c +++ b/libft/srcs/btree/btree_print.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 18:06:24 by jhalford #+# #+# */ -/* Updated: 2016/12/06 20:10:51 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 21:06:28 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/srcs/cliopts/cliopts_get.c b/libft/srcs/cliopts/cliopts_get.c index 59e5c224..05e8a3f8 100644 --- a/libft/srcs/cliopts/cliopts_get.c +++ b/libft/srcs/cliopts/cliopts_get.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 20:04:04 by jhalford #+# #+# */ -/* Updated: 2017/03/26 16:37:04 by jhalford ### ########.fr */ +/* Updated: 2017/03/25 15:00:35 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -75,7 +75,7 @@ static int cliopts_parse_long( if (map->get) { if (map->arg_required && !(tmp = check_required(av, NULL))) - return (ERR_SET(E_CO_MISSL, arg)); + return (ERR_SET(E_CO_MISS, *arg)); if ((map->get)(tmp, data)) return (ERR_SET(E_CO_MISSL, arg)); } diff --git a/libft/srcs/dlst/ft_dlstnew.c b/libft/srcs/dlst/ft_dlstnew.c index f97ab6fb..411bffca 100644 --- a/libft/srcs/dlst/ft_dlstnew.c +++ b/libft/srcs/dlst/ft_dlstnew.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:27:20 by jhalford #+# #+# */ -/* Updated: 2016/12/07 17:35:12 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 15:43:50 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ t_dlist *ft_dlstnew(void const *content, size_t content_size) if (!content) { - new = malloc(sizeof(*new)); + new = ft_malloc(sizeof(*new)); if (!new) return (NULL); new->content_size = 0; @@ -26,7 +26,7 @@ t_dlist *ft_dlstnew(void const *content, size_t content_size) } else { - new = (t_dlist *)malloc(sizeof(*new)); + new = (t_dlist *)ft_malloc(sizeof(*new)); if (!new) return (NULL); new->content_size = content_size; diff --git a/libft/srcs/error/error.c b/libft/srcs/error/error.c index 7f80f91c..6900c094 100644 --- a/libft/srcs/error/error.c +++ b/libft/srcs/error/error.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* error.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 16:47:00 by jhalford #+# #+# */ -/* Updated: 2017/03/26 16:36:54 by jhalford ### ########.fr */ +/* Updated: 2017/03/25 01:53:25 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,11 +14,15 @@ char g_error_msglist[E_MAX][ERRMSG_MAX_SIZE] = { - "no error", + "unknown error 0", "invalid option -%c", "invalid option --%s", + "option '%c' awaits argument(s): please don't combine", "option '%c': missing argument", "option '%s': missing argument", + "%s: no such file or directory", + "%s: Is a directory", + "%s: Permission denied", }; int g_errnum = 0; @@ -36,8 +40,9 @@ int error_set(int n, ...) return (g_errnum); } -int ft_perror(void) +int ft_perror(char *utility) { - ft_dprintf(2, "{red}%s: %s{eoc}\n", g_argv[0], g_errmsg); + utility = utility ? utility : g_argv[0]; + ERR_MSG(utility, g_errmsg); return (g_errnum); } diff --git a/libft/srcs/ft_printf/ft_conversion.c b/libft/srcs/ft_printf/ft_conversion.c index 0a03d5c5..99f0cc08 100644 --- a/libft/srcs/ft_printf/ft_conversion.c +++ b/libft/srcs/ft_printf/ft_conversion.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:31:48 by jhalford #+# #+# */ -/* Updated: 2017/03/11 13:14:19 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ char *ft_signed_conversion(t_fmt *fmt, va_list ap) { - char base10[] = "0123456789"; + static char base10[] = "0123456789"; long long arg; arg = va_arg(ap, int); @@ -48,7 +48,7 @@ char *ft_char_conversion(t_fmt *fmt, va_list ap) char *ret; (void)fmt; - ret = (char *)malloc(sizeof(char) + 1); + ret = (char *)ft_malloc(sizeof(char) + 1); ret[0] = (char)va_arg(ap, int); ret[1] = '\0'; return (ret); @@ -61,7 +61,7 @@ char *ft_str_conversion(t_fmt *fmt, va_list ap) (void)fmt; ret = va_arg(ap, char *); if (ret == NULL) - return(ft_strdup("NULL")); + return (ft_strdup("NULL")); ret = ft_strdup(ret); if (fmt->precision && fmt->precision < (int)ft_strlen(ret)) ret[fmt->precision] = '\0'; diff --git a/libft/srcs/ft_printf/ft_printf.c b/libft/srcs/ft_printf/ft_printf.c index fb813acd..d81e505b 100644 --- a/libft/srcs/ft_printf/ft_printf.c +++ b/libft/srcs/ft_printf/ft_printf.c @@ -6,25 +6,12 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */ -/* Updated: 2017/03/14 20:24:44 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 15:28:56 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_printf.h" -t_conv g_convs[] = -{ - {'d', "0- +", "0123456789", &ft_signed_conversion, NULL}, - {'i', "0- +", "0123456789", &ft_signed_conversion, NULL}, - {'u', "0-", "0123456789", &ft_unsigned_conversion, NULL}, - {'o', "#0-", "01234567", &ft_unsigned_conversion, &ft_pad_sharp_o}, - {'x', "#0-", "0123456789abcdef", &ft_unsigned_conversion, &ft_pad_sharp_xb}, - {'X', "#0-", "0123456789ABCDEF", &ft_unsigned_conversion, &ft_pad_sharp_xb}, - {'b', "#0-", "01", &ft_unsigned_conversion, &ft_pad_sharp_xb}, - {'s', "-", "", &ft_str_conversion, NULL}, - {'c', "-", "", &ft_char_conversion, NULL}, -}; - int ft_printf(const char *format, ...) { va_list ap; @@ -44,64 +31,7 @@ int ft_dprintf(int fd, const char *format, ...) int ft_asprintf(char **ret, const char *format, ...) { va_list ap; + va_start(ap, format); return (ft_vasprintf(ret, format, ap)); } - -int ft_vdprintf(int fd, const char *format, va_list ap) -{ - char *ret; - - ret = NULL; - if (ft_vasprintf(&ret, format, ap)) - return (1); - ft_putstr_fd(ret, fd); - ft_strdel(&ret); - return (0); -} - -int ft_vasprintf(char **ret, const char *format, va_list ap) -{ - char *str; - char *tmp; - char *final; - - str = (char *)format; - final = ft_strnew(1); - while (*str) - { - tmp = final; - if (*str == '{') - ft_printf_color(&final, &str, ap); - else if (*str == '%') - { - if (ft_fmtcalc(&final, &str, ap)) - return (1); - } - else - final = ft_strjoin(final, (char[]){*str++, 0}); - ft_strdel(&tmp); - } - *ret = final; - return (0); -} - -int ft_fmtcalc(char **final, char **str, va_list ap) -{ - t_fmt *fmt; - char *transform; - - *str += 1; - if (!(fmt = ft_printf_parse(str, ap))) - return (1); - if (!fmt->valid) - ft_strncat(*final, &fmt->conversion, 1); - else - { - transform = ft_transform(fmt, ap); - *final = ft_strjoin(*final, transform); - ft_strdel(&transform); - } - free(fmt); - return (0); -} diff --git a/libft/srcs/ft_printf/ft_printf_color.c b/libft/srcs/ft_printf/ft_printf_color.c index d59547b4..85995f46 100644 --- a/libft/srcs/ft_printf/ft_printf_color.c +++ b/libft/srcs/ft_printf/ft_printf_color.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/06 18:07:39 by jhalford #+# #+# */ -/* Updated: 2017/03/11 14:00:20 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:51:32 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,11 +40,10 @@ void ft_printf_color(char **final, char **str, va_list ap) *str += 5; return ; } - while(g_colors[i].key) + while (g_colors[i].key) { if (ft_strncmp(*str, g_colors[i].key, 5) == 0) { - /* if (isatty(fd)) */ *final = ft_strjoin(*final, g_colors[i].val); *str += 5; return ; diff --git a/libft/srcs/ft_printf/ft_printf_parse.c b/libft/srcs/ft_printf/ft_printf_parse.c index 96108f0d..14797fbf 100644 --- a/libft/srcs/ft_printf/ft_printf_parse.c +++ b/libft/srcs/ft_printf/ft_printf_parse.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:24 by jhalford #+# #+# */ -/* Updated: 2017/02/18 13:08:53 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:55:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -121,4 +121,3 @@ t_fmt *ft_printf_parse(char **format, va_list ap) fmt->valid = ft_fmt_validate_conv(fmt) ? 0 : 1; return (fmt); } - diff --git a/libft/srcs/ft_printf/ft_transform.c b/libft/srcs/ft_printf/ft_transform.c index 6651e619..67abd6e1 100644 --- a/libft/srcs/ft_printf/ft_transform.c +++ b/libft/srcs/ft_printf/ft_transform.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:32 by jhalford #+# #+# */ -/* Updated: 2016/12/13 11:19:29 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 10:26:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/srcs/ft_printf/ft_vprintf.c b/libft/srcs/ft_printf/ft_vprintf.c new file mode 100644 index 00000000..09ba322c --- /dev/null +++ b/libft/srcs/ft_printf/ft_vprintf.c @@ -0,0 +1,85 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_vprintf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/20 15:52:57 by jhalford #+# #+# */ +/* Updated: 2017/03/22 17:22:30 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf.h" + +t_conv g_convs[] = +{ + {'d', "0- +", "0123456789", &ft_signed_conversion, NULL}, + {'i', "0- +", "0123456789", &ft_signed_conversion, NULL}, + {'u', "0-", "0123456789", &ft_unsigned_conversion, NULL}, + {'o', "#0-", "01234567", &ft_unsigned_conversion, &ft_pad_sharp_o}, + {'x', "#0-", "0123456789abcdef", &ft_unsigned_conversion, &ft_pad_sharp_xb}, + {'X', "#0-", "0123456789ABCDEF", &ft_unsigned_conversion, &ft_pad_sharp_xb}, + {'b', "#0-", "01", &ft_unsigned_conversion, &ft_pad_sharp_xb}, + {'s', "-", "", &ft_str_conversion, NULL}, + {'c', "-", "", &ft_char_conversion, NULL}, +}; + +int ft_vdprintf(int fd, const char *format, va_list ap) +{ + char *ret; + char size; + + ret = NULL; + size = ft_vasprintf(&ret, format, ap); + if (size != -1) + ft_putstr_fd(ret, fd); + ft_strdel(&ret); + return (size); +} + +int ft_vasprintf(char **ret, const char *format, va_list ap) +{ + char *str; + char *tmp; + char *final; + + str = (char *)format; + final = ft_strnew(1); + while (*str) + { + tmp = final; + if (*str == '{') + ft_printf_color(&final, &str, ap); + else if (*str == '%') + { + if (ft_fmtcalc(&final, &str, ap)) + return (-1); + } + else if (!(final = ft_strjoin(final, (char[]){*str++, 0}))) + return (-1); + ft_strdel(&tmp); + } + *ret = final; + return (ft_strlen(final)); +} + +int ft_fmtcalc(char **final, char **str, va_list ap) +{ + t_fmt *fmt; + char *transform; + + *str += 1; + if (!(fmt = ft_printf_parse(str, ap))) + return (1); + if (!fmt->valid) + ft_strncat(*final, &fmt->conversion, 1); + else + { + transform = ft_transform(fmt, ap); + *final = ft_strjoin(*final, transform); + ft_strdel(&transform); + } + free(fmt); + return (0); +} diff --git a/libft/srcs/ft_printf/lib_fmt.c b/libft/srcs/ft_printf/lib_fmt.c index 59caf57a..28b7313d 100644 --- a/libft/srcs/ft_printf/lib_fmt.c +++ b/libft/srcs/ft_printf/lib_fmt.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:35 by jhalford #+# #+# */ -/* Updated: 2017/03/10 16:54:40 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,7 @@ t_fmt *ft_fmt_init(void) { t_fmt *fmt; - fmt = (t_fmt *)malloc(sizeof(t_fmt) + 1); + fmt = (t_fmt *)ft_malloc(sizeof(t_fmt) + 1); ft_bzero(fmt->flags, 6); ft_bzero(fmt->modifier, 3); fmt->conversion = '\0'; diff --git a/libft/srcs/ft_printf/lib_pad_sharp.c b/libft/srcs/ft_printf/lib_pad_sharp.c index db6fd9c9..5d065581 100644 --- a/libft/srcs/ft_printf/lib_pad_sharp.c +++ b/libft/srcs/ft_printf/lib_pad_sharp.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:48 by jhalford #+# #+# */ -/* Updated: 2017/03/05 15:19:49 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:54:47 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,8 +24,11 @@ void ft_pad_sharp_o(char *str, t_fmt *fmt) void ft_pad_sharp_xb(char *str, t_fmt *fmt) { - char start[3] = {'0',fmt->conversion, 0}; + char start[3]; + start[0] = '0'; + start[1] = fmt->conversion; + start[2] = 0; if (str[0] == '0') { if (str[1] == '0') diff --git a/libft/srcs/get_next_line/get_next_line.c b/libft/srcs/get_next_line/get_next_line.c index 4a65cb55..3eed0dee 100644 --- a/libft/srcs/get_next_line/get_next_line.c +++ b/libft/srcs/get_next_line/get_next_line.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/15 13:12:06 by jhalford #+# #+# */ -/* Updated: 2017/03/14 17:47:51 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 15:43:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/srcs/lst/ft_lst_delsub.c b/libft/srcs/lst/ft_lst_delsub.c index 441c70d3..b3912fc2 100644 --- a/libft/srcs/lst/ft_lst_delsub.c +++ b/libft/srcs/lst/ft_lst_delsub.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:15 by jhalford #+# #+# */ -/* Updated: 2017/03/26 16:55:52 by jhalford ### ########.fr */ +/* Updated: 2017/01/12 14:33:28 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/srcs/lst/ft_lst_filter.c b/libft/srcs/lst/ft_lst_filter.c index 349cb2e4..f0004126 100644 --- a/libft/srcs/lst/ft_lst_filter.c +++ b/libft/srcs/lst/ft_lst_filter.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:17 by jhalford #+# #+# */ -/* Updated: 2017/03/26 17:11:27 by jhalford ### ########.fr */ +/* Updated: 2017/03/02 17:47:26 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/srcs/lst/ft_lst_order_delsub.c b/libft/srcs/lst/ft_lst_order_delsub.c index de6b61ff..5bf2067c 100644 --- a/libft/srcs/lst/ft_lst_order_delsub.c +++ b/libft/srcs/lst/ft_lst_order_delsub.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:25 by jhalford #+# #+# */ -/* Updated: 2017/03/26 16:55:33 by jhalford ### ########.fr */ +/* Updated: 2016/11/04 12:01:47 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/srcs/lst/ft_lst_removeif.c b/libft/srcs/lst/ft_lst_removeif.c index 78734f1c..b82f57c2 100644 --- a/libft/srcs/lst/ft_lst_removeif.c +++ b/libft/srcs/lst/ft_lst_removeif.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:30 by jhalford #+# #+# */ -/* Updated: 2017/03/26 17:13:28 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 15:31:13 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/srcs/lst/ft_lstdelone.c b/libft/srcs/lst/ft_lstdelone.c index 6c577504..d9743a95 100644 --- a/libft/srcs/lst/ft_lstdelone.c +++ b/libft/srcs/lst/ft_lstdelone.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/05 13:39:33 by jhalford #+# #+# */ -/* Updated: 2017/03/13 15:31:10 by jhalford ### ########.fr */ +/* Updated: 2017/03/18 17:17:50 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/srcs/lst/ft_lstiter.c b/libft/srcs/lst/ft_lstiter.c index 49a96476..217f803c 100644 --- a/libft/srcs/lst/ft_lstiter.c +++ b/libft/srcs/lst/ft_lstiter.c @@ -6,17 +6,19 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:57:19 by jhalford #+# #+# */ -/* Updated: 2017/03/28 11:27:45 by jhalford ### ########.fr */ +/* Updated: 2017/03/11 16:17:43 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -int ft_lstiter(t_list *lst, int (*f)(), void *data) +int ft_lstiter(t_list *lst, int (*f)()) { - if (!lst) - return (0); - if ((*f)(lst->content, data)) - return (1); - return (ft_lstiter(lst->next, f, data)); + while (lst) + { + if ((*f)(lst->content)) + return (1); + lst = lst->next; + } + return (0); } diff --git a/libft/srcs/lst/ft_lstmap.c b/libft/srcs/lst/ft_lstmap.c index 3b422790..e0edbbaa 100644 --- a/libft/srcs/lst/ft_lstmap.c +++ b/libft/srcs/lst/ft_lstmap.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:57:21 by jhalford #+# #+# */ -/* Updated: 2017/03/08 12:03:14 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,9 @@ t_list *ft_lstmap(t_list *lst, void *(*f)(void *)) if (!lst) return (NULL); - elem = ft_lstnew((*f)(lst->content), lst->content_size); + if (!(elem = (t_list *)ft_malloc(sizeof(*elem)))) + return (NULL); + elem->content = (*f)(lst->content); elem->next = ft_lstmap(lst->next, f); return (elem); } diff --git a/libft/srcs/lst/ft_lstnew.c b/libft/srcs/lst/ft_lstnew.c index e85e8c62..e72d9ab7 100644 --- a/libft/srcs/lst/ft_lstnew.c +++ b/libft/srcs/lst/ft_lstnew.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/29 15:57:38 by jhalford #+# #+# */ -/* Updated: 2017/03/13 15:41:27 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 15:43:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,7 @@ t_list *ft_lstnew(void const *content, size_t content_size) { t_list *new; - if (!(new = (t_list *)malloc(sizeof(*new)))) + if (!(new = (t_list *)ft_malloc(sizeof(*new)))) return (NULL); new->next = NULL; new->content_size = content_size; diff --git a/libft/srcs/lst/pop.c b/libft/srcs/lst/pop.c index 148d6d7c..df3be22e 100644 --- a/libft/srcs/lst/pop.c +++ b/libft/srcs/lst/pop.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:56 by jhalford #+# #+# */ -/* Updated: 2017/03/03 16:49:59 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 20:05:13 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/srcs/lst/top.c b/libft/srcs/lst/top.c new file mode 100644 index 00000000..2c3186e2 --- /dev/null +++ b/libft/srcs/lst/top.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* top.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/24 20:04:27 by jhalford #+# #+# */ +/* Updated: 2017/03/24 20:09:06 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int top(t_list *top) +{ + return (top ? *(int*)top->content : 0); +} diff --git a/libft/srcs/math/id.c b/libft/srcs/math/id.c index 938cb5d1..e23a5831 100644 --- a/libft/srcs/math/id.c +++ b/libft/srcs/math/id.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* id.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/20 12:20:59 by jhalford #+# #+# */ +/* Updated: 2017/03/20 12:21:01 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "libft.h" void *id(void *data) diff --git a/libft/srcs/lst/ft_lst_filterout.c b/libft/srcs/mem/ft_malloc.c similarity index 56% rename from libft/srcs/lst/ft_lst_filterout.c rename to libft/srcs/mem/ft_malloc.c index 9a97c09d..bb1b9b54 100644 --- a/libft/srcs/lst/ft_lst_filterout.c +++ b/libft/srcs/mem/ft_malloc.c @@ -1,36 +1,26 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lst_filterout.c :+: :+: :+: */ +/* ft_malloc.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/26 16:56:02 by jhalford #+# #+# */ -/* Updated: 2017/03/26 19:10:03 by jhalford ### ########.fr */ +/* Created: 2017/03/21 15:45:00 by jhalford #+# #+# */ +/* Updated: 2017/03/23 18:31:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -void ft_lst_filterout( - t_list **alst, - void *data_ref, - int (*cmp)(), - void (*del)(void *, size_t)) +void *ft_malloc(size_t size) { - t_list *tmp; - t_list **indirect; + void *ptr; - indirect = alst; - while (*indirect) + ptr = malloc(size); + if (!ptr) { - if ((*cmp)((*indirect)->content, data_ref) == 0) - { - tmp = *indirect; - (*indirect) = (*indirect)->next; - ft_lstdelone(&tmp, del); - } - else - indirect = &(*indirect)->next; + ft_putstr_fd(strerror(errno), 2); + exit(errno); } + return (ptr); } diff --git a/libft/srcs/mem/ft_memalloc.c b/libft/srcs/mem/ft_memalloc.c index e923d08b..6a4a1112 100644 --- a/libft/srcs/mem/ft_memalloc.c +++ b/libft/srcs/mem/ft_memalloc.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:57:25 by jhalford #+# #+# */ -/* Updated: 2017/03/06 15:41:01 by ariard ### ########.fr */ +/* Updated: 2017/03/21 15:43:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,7 @@ void *ft_memalloc(size_t size) void *addr; size_t i; - addr = malloc(size); + addr = ft_malloc(size); if (addr == NULL) return (NULL); i = -1; diff --git a/libft/srcs/mem/ft_memdel.c b/libft/srcs/mem/ft_memdel.c index 52e6508b..59a18066 100644 --- a/libft/srcs/mem/ft_memdel.c +++ b/libft/srcs/mem/ft_memdel.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:57:33 by jhalford #+# #+# */ -/* Updated: 2016/11/16 12:23:13 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 16:19:07 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/srcs/mem/ft_realloc.c b/libft/srcs/mem/ft_realloc.c index 5297a2b6..33f667a8 100644 --- a/libft/srcs/mem/ft_realloc.c +++ b/libft/srcs/mem/ft_realloc.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/11 17:37:53 by jhalford #+# #+# */ -/* Updated: 2016/12/09 18:31:03 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 15:43:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/srcs/path/ft_path_notdir.c b/libft/srcs/path/ft_path_notdir.c index e02c836e..b59044f3 100644 --- a/libft/srcs/path/ft_path_notdir.c +++ b/libft/srcs/path/ft_path_notdir.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:45:07 by jhalford #+# #+# */ -/* Updated: 2016/12/07 15:22:09 by jhalford ### ########.fr */ +/* Updated: 2017/03/25 15:03:39 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/srcs/sstr/ft_sstradd.c b/libft/srcs/sstr/ft_sstradd.c index 58aa0e32..c81a256d 100644 --- a/libft/srcs/sstr/ft_sstradd.c +++ b/libft/srcs/sstr/ft_sstradd.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 18:03:58 by jhalford #+# #+# */ -/* Updated: 2017/03/07 14:28:29 by ariard ### ########.fr */ +/* Updated: 2017/03/21 15:43:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/srcs/sstr/ft_sstrdel.c b/libft/srcs/sstr/ft_sstrdel.c index c0d618ac..403fcf00 100644 --- a/libft/srcs/sstr/ft_sstrdel.c +++ b/libft/srcs/sstr/ft_sstrdel.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 18:04:07 by jhalford #+# #+# */ -/* Updated: 2017/03/14 21:09:17 by jhalford ### ########.fr */ +/* Updated: 2017/03/25 01:38:51 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,9 +17,10 @@ void ft_sstrdel(char **sstr, int index) int i; i = index; - while (sstr[i]) + ft_strdel(&sstr[index]); + while (i == index || sstr[i]) { sstr[i] = sstr[i + 1]; - i++; + ++i; } } diff --git a/libft/srcs/sstr/ft_sstrdup.c b/libft/srcs/sstr/ft_sstrdup.c index e68e0d35..8517a125 100644 --- a/libft/srcs/sstr/ft_sstrdup.c +++ b/libft/srcs/sstr/ft_sstrdup.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/07 14:25:45 by jhalford #+# #+# */ -/* Updated: 2017/03/07 19:58:12 by ariard ### ########.fr */ +/* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ char **ft_sstrdup(char **list) size = 0; while (list[size]) size++; - cpy = (char **)malloc(sizeof(char *) * (size + 1)); + cpy = (char **)ft_malloc(sizeof(char *) * (size + 1)); while (*list) { cpy[i++] = ft_strdup(*list); diff --git a/libft/srcs/sstr/ft_sstrfree.c b/libft/srcs/sstr/ft_sstrfree.c index 1e10d105..7855228d 100644 --- a/libft/srcs/sstr/ft_sstrfree.c +++ b/libft/srcs/sstr/ft_sstrfree.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/05 11:53:36 by jhalford #+# #+# */ -/* Updated: 2017/01/11 14:42:45 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 23:19:24 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/srcs/sstr/ft_sstrmerge.c b/libft/srcs/sstr/ft_sstrmerge.c new file mode 100644 index 00000000..2705a285 --- /dev/null +++ b/libft/srcs/sstr/ft_sstrmerge.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sstrmerge.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/24 17:40:50 by jhalford #+# #+# */ +/* Updated: 2017/03/24 18:05:08 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char **ft_sstrmerge(char **s1, char **s2) +{ + char **out; + + out = ft_sstrdup(s1); + if (!s2) + return (out); + while (*s2) + { + out = ft_sstradd(out, *s2); + s2++; + } + return (out); +} diff --git a/libft/srcs/sstr/ft_sstrprint_fd.c b/libft/srcs/sstr/ft_sstrprint_fd.c index dd427ca3..42225b7c 100644 --- a/libft/srcs/sstr/ft_sstrprint_fd.c +++ b/libft/srcs/sstr/ft_sstrprint_fd.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 15:17:29 by jhalford #+# #+# */ -/* Updated: 2016/11/28 15:23:52 by jhalford ### ########.fr */ +/* Updated: 2017/03/18 03:37:16 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,8 @@ void ft_sstrprint_fd(int fd, char **list, char sep) int i; i = 0; + if (!list || !*list) + return ; while (list[i]) { ft_putstr_fd(list[i++], fd); diff --git a/libft/srcs/sstr/ft_sstrsort.c b/libft/srcs/sstr/ft_sstrsort.c index 180d4ea0..25cf4134 100644 --- a/libft/srcs/sstr/ft_sstrsort.c +++ b/libft/srcs/sstr/ft_sstrsort.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ft_sstrsort.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 18:03:37 by jhalford #+# #+# */ -/* Updated: 2016/11/23 14:46:54 by jhalford ### ########.fr */ +/* Updated: 2017/03/23 14:40:25 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/srcs/sstr/ft_sstrstr.c b/libft/srcs/sstr/ft_sstrstr.c index 53a82346..d6618563 100644 --- a/libft/srcs/sstr/ft_sstrstr.c +++ b/libft/srcs/sstr/ft_sstrstr.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 11:29:54 by ariard #+# #+# */ -/* Updated: 2017/03/07 12:44:17 by ariard ### ########.fr */ +/* Updated: 2017/03/22 21:54:40 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,9 +21,6 @@ char *ft_sstrstr(char **sstr, char *find) size = ft_strlen(find); while ((*sstr)) { - DG("size : %d", size); - DG("sstr : %s", *sstr); - DG("find : %s", find); if (ft_strncmp(*sstr, find, size) == 0) return (*sstr); sstr++; diff --git a/libft/srcs/str/ft_atoi.c b/libft/srcs/str/ft_atoi.c index 711e3d68..546c58f6 100644 --- a/libft/srcs/str/ft_atoi.c +++ b/libft/srcs/str/ft_atoi.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/08/03 16:17:21 by jhalford #+# #+# */ -/* Updated: 2016/11/03 15:13:04 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 22:21:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,6 +27,8 @@ int ft_atoi(const char *str) int res; int sign; + if (!str || !*str) + return (0); i = 0; res = 0; sign = 1; diff --git a/libft/srcs/str/ft_split_whitespaces.c b/libft/srcs/str/ft_split_whitespaces.c index 6cba8e7d..ed744d0d 100644 --- a/libft/srcs/str/ft_split_whitespaces.c +++ b/libft/srcs/str/ft_split_whitespaces.c @@ -6,13 +6,13 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/03 16:07:17 by jhalford #+# #+# */ -/* Updated: 2017/02/03 16:12:40 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -char *ft_strdupi_w(char const *s) +char *ft_strdupi_w(char const *s) { int i; char *str; @@ -20,7 +20,7 @@ char *ft_strdupi_w(char const *s) i = 0; while (s[i] && s[i] != ' ' && s[i] != '\t') i++; - str = (char *)malloc(sizeof(char) * (i + 1)); + str = (char *)ft_malloc(sizeof(char) * (i + 1)); if (str) { str[i--] = '\0'; @@ -59,7 +59,7 @@ char **ft_split_whitespaces(char const *s) str = NULL; if (!(s)) return (str); - str = (char **)malloc(sizeof(char *) * (ft_len_words(s) + 1)); + str = (char **)ft_malloc(sizeof(char *) * (ft_len_words(s) + 1)); i = 0; j = 0; if (!(str)) diff --git a/libft/srcs/str/ft_strcat.c b/libft/srcs/str/ft_strcat.c index d0d028ef..76f6f25c 100644 --- a/libft/srcs/str/ft_strcat.c +++ b/libft/srcs/str/ft_strcat.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/08/07 10:56:53 by jhalford #+# #+# */ -/* Updated: 2016/12/09 19:11:20 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 14:21:22 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/srcs/str/ft_strcatf.c b/libft/srcs/str/ft_strcatf.c index 0656d6b0..8caa7036 100644 --- a/libft/srcs/str/ft_strcatf.c +++ b/libft/srcs/str/ft_strcatf.c @@ -14,7 +14,7 @@ char *ft_strcatf(char *s1, const char *s2) { - char buf[ft_strlen(s2)]; + char buf[ft_strlen(s1) + 1]; ft_strcpy(buf, s1); ft_strcpy(s1, s2); diff --git a/libft/srcs/str/ft_strcspn.c b/libft/srcs/str/ft_strcspn.c index fe535487..d55d8081 100644 --- a/libft/srcs/str/ft_strcspn.c +++ b/libft/srcs/str/ft_strcspn.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcspn.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/20 15:55:33 by jhalford #+# #+# */ +/* Updated: 2017/03/20 16:00:37 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "libft.h" size_t ft_strcspn(char *s, const char *delim) @@ -5,8 +17,8 @@ size_t ft_strcspn(char *s, const char *delim) char *str; str = s; - while(*str) - if(ft_strchr(delim,*str)) + while (*str) + if (ft_strchr(delim, *str)) return (str - s); else str++; diff --git a/libft/srcs/str/ft_strdup.c b/libft/srcs/str/ft_strdup.c index 429692cc..556558f4 100644 --- a/libft/srcs/str/ft_strdup.c +++ b/libft/srcs/str/ft_strdup.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/07 14:25:41 by jhalford #+# #+# */ -/* Updated: 2017/03/07 14:27:58 by ariard ### ########.fr */ +/* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,7 @@ char *ft_strdup(const char *s1) { char *dup; - if (!s1 || !(dup = (char*)malloc(sizeof(*dup) * (ft_strlen(s1) + 1)))) + if (!s1 || !(dup = (char*)ft_malloc(sizeof(*dup) * (ft_strlen(s1) + 1)))) return (NULL); ft_strcpy(dup, s1); return (dup); diff --git a/libft/srcs/str/ft_strdupchr.c b/libft/srcs/str/ft_strdupchr.c index 97340f13..3fd5d0d5 100644 --- a/libft/srcs/str/ft_strdupchr.c +++ b/libft/srcs/str/ft_strdupchr.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 11:01:15 by ariard #+# #+# */ -/* Updated: 2017/03/07 11:24:27 by ariard ### ########.fr */ +/* Updated: 2017/03/22 23:12:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/srcs/str/ft_strduptr.c b/libft/srcs/str/ft_strduptr.c index ca2f1180..59cfd835 100644 --- a/libft/srcs/str/ft_strduptr.c +++ b/libft/srcs/str/ft_strduptr.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/06 13:37:12 by ariard #+# #+# */ -/* Updated: 2017/03/07 12:41:20 by ariard ### ########.fr */ +/* Updated: 2017/03/21 15:43:52 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/srcs/str/ft_stris.c b/libft/srcs/str/ft_stris.c index 3fc93a3b..ba809f85 100644 --- a/libft/srcs/str/ft_stris.c +++ b/libft/srcs/str/ft_stris.c @@ -6,16 +6,16 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/02 15:11:28 by ariard #+# #+# */ -/* Updated: 2017/03/07 11:44:29 by ariard ### ########.fr */ +/* Updated: 2017/03/20 16:01:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -int ft_stris(char *str, int (*f)()) +int ft_stris(char *str, int (*f)()) { while (*str) if (!(f)(*str++)) return (0); return (1); -} +} diff --git a/libft/srcs/str/ft_strlen.c b/libft/srcs/str/ft_strlen.c index 6b6f4269..9b65ad39 100644 --- a/libft/srcs/str/ft_strlen.c +++ b/libft/srcs/str/ft_strlen.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ft_strlen.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:58:22 by jhalford #+# #+# */ -/* Updated: 2017/03/07 11:06:41 by ariard ### ########.fr */ +/* Updated: 2017/03/18 14:25:09 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/srcs/str/ft_strlenchr.c b/libft/srcs/str/ft_strlenchr.c index 34882af2..1ea82cfa 100644 --- a/libft/srcs/str/ft_strlenchr.c +++ b/libft/srcs/str/ft_strlenchr.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 16:10:54 by ariard #+# #+# */ -/* Updated: 2017/03/07 11:30:02 by ariard ### ########.fr */ +/* Updated: 2017/03/22 22:12:03 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/srcs/str/ft_strmap.c b/libft/srcs/str/ft_strmap.c index 295214f0..5c0353ae 100644 --- a/libft/srcs/str/ft_strmap.c +++ b/libft/srcs/str/ft_strmap.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:58:24 by jhalford #+# #+# */ -/* Updated: 2016/11/03 14:58:25 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,7 @@ char *ft_strmap(char const *s, char (*f)(char)) char *out; size = ft_strlen(s); - out = (char *)malloc(sizeof(char) * (size + 1)); + out = (char *)ft_malloc(sizeof(char) * (size + 1)); if (out == NULL) return (NULL); i = -1; diff --git a/libft/srcs/str/ft_strmapi.c b/libft/srcs/str/ft_strmapi.c index 0d6fab4c..7cc6d089 100644 --- a/libft/srcs/str/ft_strmapi.c +++ b/libft/srcs/str/ft_strmapi.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:58:28 by jhalford #+# #+# */ -/* Updated: 2016/11/03 14:58:29 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,7 @@ char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) char *out; size = ft_strlen(s); - out = (char *)malloc(sizeof(char) * (size + 1)); + out = (char *)ft_malloc(sizeof(char) * (size + 1)); if (out == NULL) return (NULL); i = -1; diff --git a/libft/srcs/str/ft_strnew.c b/libft/srcs/str/ft_strnew.c index 56742a50..2e2ae1d6 100644 --- a/libft/srcs/str/ft_strnew.c +++ b/libft/srcs/str/ft_strnew.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:58:34 by jhalford #+# #+# */ -/* Updated: 2017/01/11 16:37:53 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,7 @@ char *ft_strnew(size_t size) char *addr; size_t i; - addr = (char *)malloc(size + 1); + addr = (char *)ft_malloc(size + 1); if (addr == NULL) return (NULL); i = -1; diff --git a/libft/srcs/str/ft_strsplit.c b/libft/srcs/str/ft_strsplit.c index a44c4ca1..049aa7ed 100644 --- a/libft/srcs/str/ft_strsplit.c +++ b/libft/srcs/str/ft_strsplit.c @@ -6,13 +6,13 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:58:40 by jhalford #+# #+# */ -/* Updated: 2016/12/05 17:20:45 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -static int ft_countwords(char const *s, char c) +static int ft_countwords(char const *s, char c) { if (c == '\0') return ((*s == '\0') ? 0 : 1); @@ -36,9 +36,9 @@ static int get_word_len(char const *str, char c) i++; while (str[i] != c && str[i] != '\0') { - i++; - len++; - } + i++; + len++; + } return (len); } @@ -49,22 +49,22 @@ char **ft_strsplit(char const *s, char c) int k; char **str2; - if (!s || !(str2 = (char **)malloc(sizeof(*str2) * - (ft_countwords(s, c) + 1)))) + if (!s || !(str2 = (char **)ft_malloc(sizeof(*str2) * + (ft_countwords(s, c) + 1)))) return (NULL); i = -1; j = 0; while (++i < ft_countwords(s, c)) { - k = 0; - if (!(str2[i] = ft_strnew(get_word_len(&s[j], c) + 1))) - str2[i] = NULL; - while (s[j] == c) - j++; - while (s[j] != c && s[j]) - str2[i][k++] = s[j++]; - str2[i][k] = '\0'; - } + k = 0; + if (!(str2[i] = ft_strnew(get_word_len(&s[j], c) + 1))) + str2[i] = NULL; + while (s[j] == c) + j++; + while (s[j] != c && s[j]) + str2[i][k++] = s[j++]; + str2[i][k] = '\0'; + } str2[i] = 0; return (str2); } diff --git a/libft/srcs/str/ft_strsub.c b/libft/srcs/str/ft_strsub.c index f4259a58..0c3fb11b 100644 --- a/libft/srcs/str/ft_strsub.c +++ b/libft/srcs/str/ft_strsub.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ft_strsub.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:58:43 by jhalford #+# #+# */ -/* Updated: 2016/11/25 11:31:36 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,7 @@ char *ft_strsub(char const *s, unsigned int start, size_t len) char *out; size_t i; - if (!(out = (char *)malloc(sizeof(char) * (len + 1)))) + if (!(out = (char *)ft_malloc(sizeof(char) * (len + 1)))) return (NULL); i = -1; while (++i < len) diff --git a/libft/srcs/str/ft_strtok.c b/libft/srcs/str/ft_strtok.c index 044ff3f3..dbb73ed9 100644 --- a/libft/srcs/str/ft_strtok.c +++ b/libft/srcs/str/ft_strtok.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 18:08:31 by jhalford #+# #+# */ -/* Updated: 2017/03/07 18:18:30 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 22:23:33 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,10 +19,11 @@ char *ft_strtok(char *s, const char *delim) if (s == 0) s = lasts; - do { + if ((ch = *s++) == 0) + return (0); + while (ft_strchr(delim, ch)) if ((ch = *s++) == 0) return (0); - } while (ft_strchr(delim, ch)); --s; lasts = s + ft_strcspn(s, delim); if (*lasts != 0) diff --git a/libft/srcs/sys/create_directory.c b/libft/srcs/sys/create_directory.c new file mode 100644 index 00000000..6a8967ca --- /dev/null +++ b/libft/srcs/sys/create_directory.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* create_directory.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/25 03:18:18 by ariard #+# #+# */ +/* Updated: 2017/03/25 15:12:34 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *create_directory(const char *path, const char *old_pathnames) +{ + char *new_pathnames; + char *newdir; + char *temp; + char *semi; + + new_pathnames = ft_strdup(old_pathnames); + temp = new_pathnames; + while (new_pathnames) + { + if ((semi = ft_strchr(new_pathnames, ':'))) + *semi = 0; + if (!is_directory(newdir = ft_str3join(new_pathnames, "/", path))) + ft_strdel(&newdir); + else + break ; + new_pathnames += ft_strlen(new_pathnames) + 1; + } + ft_strdel(&temp); + return (newdir); +} diff --git a/libft/srcs/sys/dup2_close.c b/libft/srcs/sys/dup2_close.c index 5a7924a6..c1c10bcd 100644 --- a/libft/srcs/sys/dup2_close.c +++ b/libft/srcs/sys/dup2_close.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/07 16:07:28 by jhalford #+# #+# */ -/* Updated: 2017/02/07 16:15:52 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 19:33:48 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,9 +14,9 @@ int dup2_close(int fd1, int fd2) { - if (dup2(fd1, fd2)) + if (dup2(fd1, fd2) < 0) return (-1); - if (close(fd1)) + if (close(fd1) < 0) return (-1); return (0); } diff --git a/libft/srcs/sys/fd_replace.c b/libft/srcs/sys/fd_replace.c new file mode 100644 index 00000000..495ae484 --- /dev/null +++ b/libft/srcs/sys/fd_replace.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* fd_replace.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/21 16:32:26 by jhalford #+# #+# */ +/* Updated: 2017/03/24 22:59:28 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int fd_replace(int fd1, int fd2) +{ + if (fd1 != fd2) + return (dup2_close(fd1, fd2)); + return (0); +} diff --git a/libft/srcs/sys/ft_getenv.c b/libft/srcs/sys/ft_getenv.c index 2b47fc5b..83cebdaa 100644 --- a/libft/srcs/sys/ft_getenv.c +++ b/libft/srcs/sys/ft_getenv.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:15:45 by jhalford #+# #+# */ -/* Updated: 2016/12/01 12:29:25 by jhalford ### ########.fr */ +/* Updated: 2017/03/18 03:09:57 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,8 @@ char *ft_getenv(char **env, char *key) return (NULL); while (*env) { - if (ft_strcmp(*env, key) == '=') + if (ft_strcmp(*env, key) == '=' + && ft_strlen(key) == ft_strlenchr(*env, '=')) return (*env + ft_strlen(key) + 1); env++; } diff --git a/libft/srcs/sys/is_directory.c b/libft/srcs/sys/is_directory.c new file mode 100644 index 00000000..accd92a4 --- /dev/null +++ b/libft/srcs/sys/is_directory.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* is_directory.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/25 01:40:31 by jhalford #+# #+# */ +/* Updated: 2017/03/25 01:42:02 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int is_directory(const char *path) +{ + struct stat path_stat; + + stat(path, &path_stat); + return (S_ISDIR(path_stat.st_mode)); +} diff --git a/libft/srcs/sys/open_access.c b/libft/srcs/sys/open_access.c new file mode 100644 index 00000000..40811fe7 --- /dev/null +++ b/libft/srcs/sys/open_access.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* open_access.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/25 01:10:56 by jhalford #+# #+# */ +/* Updated: 2017/03/25 15:07:42 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int open_access(char *file, t_flag a_flag, t_flag o_flag, t_flag o_perm) +{ + int fd; + + if (a_flag & F_OK && access(file, F_OK) != 0) + return (-ERR_SET(E_SYS_NOFILE, file)); + if (is_directory(file)) + return (-ERR_SET(E_SYS_ISDIR, file)); + if (access(file, F_OK) == 0 && access(file, a_flag) != 0) + return (-ERR_SET(E_SYS_NOPERM, file)); + if ((fd = open(file, o_flag, o_perm)) < 0) + { + exit(1); + } + return (fd); +} diff --git a/libft/srcs/time/ft_mytime_get.c b/libft/srcs/time/ft_mytime_get.c index f222530e..ab8f25b3 100644 --- a/libft/srcs/time/ft_mytime_get.c +++ b/libft/srcs/time/ft_mytime_get.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/25 11:34:56 by jhalford #+# #+# */ -/* Updated: 2016/12/03 11:54:16 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,7 @@ t_mytime *ft_mytime_get(time_t epoch) char *date; t_mytime *time; - time = (t_mytime*)malloc(sizeof(*time)); + time = (t_mytime*)ft_malloc(sizeof(*time)); date = ctime(&epoch); date[ft_strlen(date) - 1] = 0; time->year = ft_isdigit(date[20]) ? diff --git a/libft/srcs/time/ft_time_isrecent.c b/libft/srcs/time/ft_time_isrecent.c index 04712152..ec195653 100644 --- a/libft/srcs/time/ft_time_isrecent.c +++ b/libft/srcs/time/ft_time_isrecent.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 18:01:04 by jhalford #+# #+# */ -/* Updated: 2016/11/25 11:43:52 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 15:44:24 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */