"/dev/random #125 #126 #131
This commit is contained in:
Antoine Riard 2017-03-21 16:42:34 +01:00
commit 634d498b03
42 changed files with 119 additions and 82 deletions

View file

@ -121,6 +121,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\
@ -190,6 +191,7 @@ str/ft_strsub.c\
str/ft_strtok.c\
str/ft_strtrim.c\
sys/dup2_close.c\
sys/fd_replace.c\
sys/ft_getenv.c\
sys/ft_xattr_count.c\
sys/ft_xattr_print.c\

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */
/* Updated: 2017/03/20 09:37:38 by jhalford ### ########.fr */
/* Updated: 2017/03/21 16:32:40 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,6 +14,7 @@
# define LIBFT_H
# include <string.h>
# include <errno.h>
# include <unistd.h>
# include <stdio.h>
# include <stdlib.h>
@ -64,6 +65,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);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/14 17:24:23 by jhalford #+# #+# */
/* Updated: 2017/03/20 09:38:36 by jhalford ### ########.fr */
/* Updated: 2017/03/21 16:33:01 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -29,5 +29,6 @@ int ft_xattr_print(char *path);
int ft_xattr_count(char *path);
char *ft_getenv(char **env, char *key);
int dup2_close(int fd1, int fd2);
int fd_replace(int fd1, int fd2);
#endif

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 11:50:46 by jhalford #+# #+# */
/* Updated: 2017/03/20 14:09:06 by jhalford ### ########.fr */
/* Updated: 2017/03/21 15:42:18 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,7 +18,7 @@ t_btree *btree_map(t_btree *root, void *(*f)(void *))
if (!root)
return (NULL);
if (!(new = (t_btree *)malloc(sizeof(*new))))
if (!(new = (t_btree *)ft_malloc(sizeof(*new))))
return (NULL);
new->item = (*f)(root->item);
new->left = btree_map(root->left, f);

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:31:48 by jhalford #+# #+# */
/* Updated: 2017/03/20 15:50:57 by jhalford ### ########.fr */
/* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -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);

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */
/* Updated: 2017/03/21 15:20:08 by jhalford ### ########.fr */
/* Updated: 2017/03/21 15:28:56 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/20 15:52:57 by jhalford #+# #+# */
/* Updated: 2017/03/21 15:19:56 by jhalford ### ########.fr */
/* Updated: 2017/03/21 16:34:06 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -56,8 +56,8 @@ int ft_vasprintf(char **ret, const char *format, va_list ap)
if (ft_fmtcalc(&final, &str, ap))
return (-1);
}
else
final = ft_strjoin(final, (char[]){*str++, 0});
else if (!(final = ft_strjoin(final, (char[]){*str++, 0})))
return (-1);
ft_strdel(&tmp);
}
*ret = final;

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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';

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/15 13:12:06 by jhalford #+# #+# */
/* Updated: 2017/03/21 13:16:15 by jhalford ### ########.fr */
/* Updated: 2017/03/21 15:43:51 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:21 by jhalford #+# #+# */
/* Updated: 2017/03/20 14:06:55 by jhalford ### ########.fr */
/* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,7 +18,7 @@ t_list *ft_lstmap(t_list *lst, void *(*f)(void *))
if (!lst)
return (NULL);
if (!(elem = (t_list *)malloc(sizeof(*elem))))
if (!(elem = (t_list *)ft_malloc(sizeof(*elem))))
return (NULL);
elem->content = (*f)(lst->content);
elem->next = ft_lstmap(lst->next, f);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/29 15:57:38 by jhalford #+# #+# */
/* Updated: 2017/03/20 12:23:44 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;

View file

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_malloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/21 15:45:00 by jhalford #+# #+# */
/* Updated: 2017/03/21 16:34:03 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_malloc(size_t size)
{
void *ptr;
ptr = malloc(size);
if (!ptr)
{
ft_dprintf(2, "{red}%s{eoc}", strerror(errno));
exit(errno);
}
return (ptr);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/03 16:07:17 by jhalford #+# #+# */
/* Updated: 2017/03/20 15:55:29 by jhalford ### ########.fr */
/* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -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))

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/07 14:25:41 by jhalford #+# #+# */
/* Updated: 2017/03/20 08:27:05 by jhalford ### ########.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);

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 11:01:15 by ariard #+# #+# */
/* Updated: 2017/03/07 11:24:27 by ariard ### ########.fr */
/* Updated: 2017/03/21 15:43:51 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:40 by jhalford #+# #+# */
/* Updated: 2017/03/20 16:10:24 by jhalford ### ########.fr */
/* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -49,7 +49,7 @@ char **ft_strsplit(char const *s, char c)
int k;
char **str2;
if (!s || !(str2 = (char **)malloc(sizeof(*str2) *
if (!s || !(str2 = (char **)ft_malloc(sizeof(*str2) *
(ft_countwords(s, c) + 1))))
return (NULL);
i = -1;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:43 by jhalford #+# #+# */
/* Updated: 2017/03/21 11:38:40 by gwojda ### ########.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)

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fd_replace.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/21 16:32:26 by jhalford #+# #+# */
/* Updated: 2017/03/21 16:40:17 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int fd_replace(int fd1, int fd2)
{
if (fd1 != fd2)
return(dup2_close(fd1, fd2));
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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]) ?

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/21 18:00:03 by jhalford #+# #+# */
/* Updated: 2017/03/20 08:41:18 by jhalford ### ########.fr */
/* Updated: 2017/03/21 15:52:26 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 11:57:53 by jhalford #+# #+# */
/* Updated: 2017/03/21 15:23:49 by jhalford ### ########.fr */
/* Updated: 2017/03/21 15:28:51 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:28:41 by jhalford #+# #+# */
/* Updated: 2017/03/21 14:48:13 by jhalford ### ########.fr */
/* Updated: 2017/03/21 15:51:03 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -25,8 +25,7 @@ int builtin_exit(const char *path, char *const av[], char *const envp[])
{
notified = 1;
if (has_stopped_job() || has_running_job())
SH_ERR("There are running and/or stopped jobs");
return (0);
return (SH_ERR("There are running and/or stopped jobs"));
}
if (av && av[1] && !ft_stris(av[1], ft_isdigit))
SH_ERR(EXITERR_0);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */
/* Updated: 2017/03/20 18:14:20 by gwojda ### ########.fr */
/* Updated: 2017/03/21 16:24:41 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -20,7 +20,7 @@ static int c_addnode(t_comp *c, char *value)
{
t_clst *tmp;
if (!(tmp = (t_clst *)malloc(sizeof(t_clst))))
if (!(tmp = (t_clst *)ft_malloc(sizeof(t_clst))))
return (-1);
tmp->name = value;
tmp->len = ft_strlen(tmp->name);

View file

@ -82,7 +82,7 @@ void c_init(t_data *s, long int input)
{
int len_trail;
if (!(s->comp = (t_comp *)malloc((sizeof(t_comp)))))
if (!(s->comp = (t_comp *)ft_malloc((sizeof(t_comp)))))
return ;
c_init_base(s->comp);
s->comp->rcmd = c_trimmer(s->line.input, s->line.pos, s->line.pos);

View file

@ -52,7 +52,7 @@ static int c_storing(t_comp *c, char *value, unsigned char type)
return (0);
if (c->match && ft_strnequ(c->match, value, ft_strlen(c->match)) != 1)
return (0);
if (!(tmp = (t_clst *)malloc(sizeof(t_clst))))
if (!(tmp = (t_clst *)ft_malloc(sizeof(t_clst))))
return (-1);
tmp->name = ft_strdup(value);
tmp->len = ft_strlen(tmp->name);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 22:32:43 by jhalford #+# #+# */
/* Updated: 2017/03/20 10:24:40 by jhalford ### ########.fr */
/* Updated: 2017/03/21 16:24:33 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,7 +14,6 @@
int bad_fd(int fd)
{
ft_dprintf(2, "{red}%s: %i: Bad file descriptor{eoc}\n",
SHELL_NAME, fd);
SH_ERR("%i: Bad file descriptor", fd);
return (1);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */
/* Updated: 2017/03/20 18:38:13 by gwojda ### ########.fr */
/* Updated: 2017/03/21 16:40:13 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -23,12 +23,6 @@ t_itof g_redirmap[] =
{0, NULL},
};
static void process_close(int fd1, int fd2)
{
if (fd1 != fd2)
dup2_close(fd1, fd2);
}
int process_redirect(t_process *p)
{
t_list *redirs;
@ -38,6 +32,8 @@ int process_redirect(t_process *p)
redirs = p->redirs;
if (p->to_close != STDIN)
close(p->to_close);
fd_replace(p->fdin, STDIN);
fd_replace(p->fdout, STDOUT);
while (redirs)
{
redir = redirs->content;
@ -53,7 +49,5 @@ int process_redirect(t_process *p)
}
redirs = redirs->next;
}
process_close(p->fdin, STDIN);
process_close(p->fdout, STDOUT);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 22:12:31 by jhalford #+# #+# */
/* Updated: 2017/03/20 12:36:22 by jhalford ### ########.fr */
/* Updated: 2017/03/21 16:35:42 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,18 +24,15 @@ int redirect_greatand(t_redir *redir)
}
if (!ft_stris(redir->word, ft_isdigit))
{
ft_dprintf(2, "{red}%s: %s: can only be digits{eoc}\n",
data_singleton()->argv[0], redir->word);
SH_ERR("%s: can only be digits{eoc}\n", redir->word);
return (1);
}
fdold = ft_atoi(redir->word);
fdnew = redir->n;
if (fdold == fdnew)
return (0);
if (fdold > 9)
return (bad_fd(fdold));
if (fd_is_valid(fdold, O_WRONLY | O_RDWR))
dup2_close(fdold, fdnew);
fd_replace(fdold, fdnew);
else
return (bad_fd(fdold));
return (0);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 22:11:18 by jhalford #+# #+# */
/* Updated: 2017/03/20 12:36:38 by jhalford ### ########.fr */
/* Updated: 2017/03/21 16:33:43 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,18 +24,15 @@ int redirect_lessand(t_redir *redir)
}
if (!ft_stris(redir->word, ft_isdigit))
{
ft_dprintf(2, "{red}%s: %s: can only be digits{eoc}\n",
data_singleton()->argv[0], redir->word);
SH_ERR("%s: can only be digits{eoc}\n", redir->word);
return (1);
}
fdold = ft_atoi(redir->word);
fdnew = redir->n;
if (fdold == fdnew)
return (0);
if (fdold > 9)
return (bad_fd(fdold));
if (fd_is_valid(fdold, O_RDONLY | O_RDWR))
dup2_close(fdold, fdnew);
fd_replace(fdold, fdnew);
else
return (bad_fd(fdold));
return (0);

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 18:57:44 by ariard #+# #+# */
/* Updated: 2017/03/20 10:35:11 by jhalford ### ########.fr */
/* Updated: 2017/03/21 15:46:51 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */