static int ft_run_cmd(char *name, char **av) { static char *env; char *str; int i; pid_t father; i = 0; if (!env) env = ft_get_line(*environ); str = ft_joinstr(name, env, &i); while (access(str, X_OK) && str) { free(str); str = ft_joinstr(name, env, &i); } if (!str) return (0); father = fork(); if (father > 0) { wait(&father); return (1); } if (father == 0) execve(str, av, NULL); return (1); }
int get_next_line(int const fd, char **line) { static t_list *next = NULL; t_list *begin; char buf[BUFF_SIZE]; int nbr; char *d; d = NULL; if (fd < 0 || !line || read(fd, buf, 0) < 0) return (-1); if (next) begin = next; else begin = NULL; next = ft_search_fd(&begin, fd); while ((nbr = read(fd, buf, BUFF_SIZE)) > 0 && !(ft_strchr(buf, '\n'))) next->content = ft_passkip((next->content), buf, nbr); next->content = ft_passkip((next->content), buf, nbr); *line = ft_get_line(next->content, *line); if (!*((char *)next->content) && (next = begin)) return (0); d = next->content; next->content = ft_strdup(ft_skype_n(next->content)); free(d); next = begin; return (1); }
int get_next_line(int const fd, char **line) { char buf[BUFF_SIZE + 1]; int ret; static char *tmp; if (!tmp) tmp = ft_strnew(0); if (!line) return (-1); ret = 0; while (!(ft_strchr(tmp, '\n')) && (ret = read(fd, buf, BUFF_SIZE)) > 0) ft_get_line(ret, buf, &tmp); if (ret == -1) return (-1); if (ret == 0 && !(ft_strchr(tmp, '\n'))) { *line = tmp; tmp = NULL; return (0); } ft_get_bis(line, &tmp); return (1); }