int child_fork(t_opt *opt) { char *shell; shell = opt->shell; if (setsid() == -1) ft_errorexit("fail setsid"); if ((opt->fd_slave = open((char *)(&opt->fds_name), O_RDWR)) < 0) ft_errorexit("fail to open slave fd"); if (ioctl(opt->fd_slave, TIOCSCTTY, 0)) ft_errorexit("liaison fail"); if ((ioctl(opt->fd_slave, TIOCSETA, &opt->orig))) ft_errorexit("imposible de set les atibues du term"); if (ioctl(opt->fd_slave, TIOCSWINSZ, &opt->winsize) == -1) ft_errorexit("imposible de set les atibues winsize du term"); if (dup2(opt->fd_slave, 0) != 0) ft_errorexit("impossible de dupliquer le l'entrer standard"); if (dup2(opt->fd_slave, 1) != 1) ft_errorexit("impossible de dupliquer la sortie stendard"); if (dup2(opt->fd_slave, 2) != 2) ft_errorexit("impossible de dupliquer la sortie d erreur"); execute(opt); exit(0); return (0); }
int checklines(char *buffer) { int i; i = 0; while (buffer[i]) { if (buffer[i] == '\n' && buffer[i + 1] == '\n') ft_errorexit("ERROR : Extra line in file"); i++; } return (0); }
int checkdata(char *buffer) { int i; int j; i = 0; j = 0; while (buffer[i]) { if (ft_isdigit(buffer[i]) == 1 || buffer[i] == 45 || buffer[i] == ' ' \ || buffer[i] == '\n') { if (ft_isdigit(buffer[i]) == 1) j++; i++; } else ft_errorexit("ERROR : Bad character in file"); } if (j == 0) ft_errorexit("ERROR : Empty file or no points in file"); return (0); }
int fork_pty(t_opt *opt) { int pid; if ((pid = fork()) < 0) { close(opt->fd_master); ft_errorexit("fork have fail"); } if (pid > 0) { return ((opt->pid_c = pid)); } else child_fork(opt); return (0); }
char *ft_buffing(int fd) { char *buffer; char *nbuffer; char *tempbuf; int endbuf; endbuf = 1; buffer = ft_strnew(100); nbuffer = ft_strnew(100); while (endbuf != 0) { tempbuf = ft_strdup(buffer); ft_strclr(buffer); buffer = ft_strnew(ft_strlen(tempbuf) + 100); endbuf = read(fd, nbuffer, 100); if (endbuf < 0) ft_errorexit("ERROR : Bad type of file or error in reading"); buffer = ft_strjoin(tempbuf, nbuffer); ft_strclr(tempbuf); ft_strclr(nbuffer); } return (buffer); }