int get_next_line(int const fd, char **dest) { static t_fd *current_fd = NULL; char buffer[BUFF_SIZE + 1]; char *line; int len; int ret; ret = 0; current_fd = ft_get_fd(current_fd, fd); if ((fd < 0 || fd == 1 || fd == 2) || dest == NULL) return (-1); while (fd >= 0 && ((len = ft_check_endofline(current_fd->text)) || (ret = ft_read_fd(fd, buffer)) > 0) && len <= 0) current_fd->text = ft_strfreejoin(current_fd->text, buffer, 2); if (ret == -1) return (-1); if (len > 0) current_fd->text[len - 1] = '\0'; *dest = ft_strdup(current_fd->text); line = current_fd->text; current_fd->text = ((len > 0) ? ft_strdup(current_fd->text + len) : ft_strdup("")); free(line); current_fd = current_fd->begin_list; return ((len || **dest) ? 1 : 0); }
int client(int ac, char **av) { int port; int sock; fd_set fd_read; if (ac == 1) s_wait_server(&port, &sock); else if (ac == 3 && ft_isnumber(av[2])) { port = ft_atoi(av[2]); sock = ft_connect(av[1], port); } else return (ft_putendl(USAGE), 1); if (sock == -1) return (1); while (1) { if (ft_get_fd(&fd_read, sock) <= 0) break ; } close(sock); return (0); }
static int ft_pipe0(int fd[2], t_list *arg, int *fdpipe, int count) { if (count != 0) ft_dup2(fdpipe[count - 2], 0); else { fd[0] = ft_get_fd(arg->dir); ft_dup2(fd[0], 0); } return (fd[0]); }
static int ft_pipe1(int fd[2], t_list *arg, int *fdpipe, int count) { if (ft_strcmp(arg->valeure, ";") != 0) ft_dup2(fdpipe[count + 1], 1); else { fd[1] = ft_get_fd(arg->dir); ft_dup2(fd[1], 1); } return (fd[1]); }
int ft_check_size(t_ctx *ctx) { struct winsize w; int fd; if (ERR == (fd = ft_get_fd())) return (ERR); if (-1 == ioctl(fd, TIOCGWINSZ, &w)) return (ft_strerror()); if (ctx->cols * 2 + 6 > w.ws_col) return (ft_error("The window is too small to display this grid")); return (OK); }
static int *ft_init_fd(t_list *arg) { int *fd; fd = (int *)malloc(sizeof(int) * 2); fd[0] = 0; fd[1] = 1; while (arg->dir) { if (ft_strcmp(arg->dir->mot, ">>") == 0 || ft_strcmp(arg->dir->mot, ">") == 0) fd[1] = ft_get_fd(arg->dir); if (ft_strcmp(arg->dir->mot, "<<") == 0 || ft_strcmp(arg->dir->mot, "<") == 0) fd[0] = ft_get_fd(arg->dir); arg->dir = arg->dir->next; } if (fd[0] == -1 || fd[1] == -1) return (NULL); ft_dup2(fd[0], 0); ft_dup2(fd[1], 1); return (fd); }