void create_file(t_header *cor, t_cmd *cmd, t_env *e) { t_cmd *tmp; int fd; int i; tmp = cmd; if ((fd = open(e->name, O_CREAT | O_RDWR | O_TRUNC, 0664)) == -1) ft_errors("ERROR : Files .cor not create.", 1, 0); cor->prog_size = invert(e->pos_rel); if (cor->prog_size == 0) ft_errors("ERROR : size = 0", 1, 0); write(fd, cor, PROG_NAME_LENGTH + COMMENT_LENGTH + 2 + 8); write(fd, "\0\0\0\0\0\0", 6); while (tmp) { i = -1; while (++i < tmp->size) ft_putchar_fd(tmp->octet[i], fd); tmp = tmp->next; } ft_printf("file : %s -> done.\n", e->name); if (close(fd) == -1) ft_errors("ERROR : close fail. wesh alors ?", 1, 0); }
void exec_cmd_father(int i) { wait(&status()->status); if (close(fd()->fd[i][1]) < 0) ft_errors(ERR42_CLOSE); if (dup2(fd()->fd[i][0], 0) < 0) ft_errors(ERR42_DUP2); }
int main(int argc, char **argv) { t_coord *cd; t_etri *tetri; int i; i = -1; cd = (t_coord *)malloc(sizeof(t_coord)); TAB = NULL; BUF = (char *)malloc(sizeof(char) * BUFF_SIZE); if (argc == 2) { ft_read_count(argv[1], cd); TAB = ft_bufcpy(BUF, cd); ft_errors(RET, BUF, TAB); BUF = ft_sub_trim(TAB, BUF); TAB = ft_bufcpy(BUF, cd); tetri = ft_make_list(cd); ft_prepare_algo(cd, tetri); while (++i < COTE) ft_putstr(MAP[i]); free(tetri); } else ft_putstr("error\n"); free(cd); return (0); }
static int add_opt(int pos, int opt) { int tmp; if (pos == -1) ft_errors("ERROR : Illegal option.", 1, 0); tmp = 1; tmp = tmp << pos; opt = opt | tmp; return (opt); }
void exec_cmd(int i) { pid_t pid; pid = fork(); if (pid > 0) exec_cmd_father(i); else if (pid == 0) exec_cmd_son(i); else ft_errors(ERR42_FORK); }
void exec_cmd_son(int i) { if (fd()->nb_cmds > 1 || fd()->file_out) { if (close(fd()->fd[i][0]) < 0) ft_errors(ERR42_CLOSE); if (dup2(fd()->fd[i][1], 1) < 0) ft_errors(ERR42_DUP2); } if (fd()->file_in) { fd()->nb_forks *= -1; if (fd()->nb_forks == 1) { if (i > 0) exec_cmd(i); exec_read_file_in(fd()->file_in); } } execve(fd()->cmds[0], fd()->cmds, g()->env); ft_errors(ERR42_EXECVE); }
int main(int ac, char **av) { t_coord **coord; t_varf v; (ac != 2) ? (ft_exit()) : (0); v.tab = NULL; v.file = ft_strnew(1); ((v.fd = open(av[1], O_RDONLY)) == -1) ? (ft_exit()) : (0); ft_check_tetri(v.fd); (close(v.fd) == -1) ? (ft_exit()) : (0); ((v.fd = open(av[1], O_RDONLY)) == -1) ? (ft_exit()) : (0); ft_errors(v.fd, &v.file); (close(v.fd) == -1) ? (ft_exit()) : (0); v.file = ft_letters(v.file); coord = ft_store(v.file); free(v.file); v.tab = ft_result(*coord, ft_nbr_blk(*coord)); free(coord); ft_display(v.tab); free(v.tab); return (0); }