static void loop_listen(socklen_t lg, int sockfd) { int newsockfd; struct sockaddr_in that; pid_t pid; int ret; while (1) { ret = -1; newsockfd = accept(sockfd, (struct sockaddr *)(&that), &lg); if (newsockfd < 0) ft_print_error("Fail to accept new connection\n", 0); else { if ((pid = fork()) < 0) ft_print_error("fork error\n", 1); if (pid == 0) v_child(newsockfd, sockfd); else new_file_for_norme(newsockfd, &ret); ft_printf("Compute end with status: %d\n", ret); } } close(sockfd); }
static void improper_path(int ret, char *path) { if (ret == -1) ft_print_error("cd: no such file or directory: ", path); else if (ret == -2) ft_print_error("cd: permission denied: ", path); }
void ft_cd(char *buf, t_params *p) { char **av; char *new_dir; int ret; int size; ret = 0; av = ft_split(buf); new_dir = NULL; size = av_size(av); if (size > 2) ft_putendl("cd: syntax error"); else if (size == 1 || (size == 2 && !ft_strcmp(av[1], "~"))) new_dir = ft_strdup(p->home); else new_dir = get_newdir(p, av[1]); if (new_dir && !(ret = check_path(new_dir)) && !chdir(new_dir)) update_env(p, new_dir); else if (new_dir && !(ret = check_path(new_dir)) && chdir(new_dir) == -1) ft_print_error("cd: not a directory: ", av[1]); if (new_dir && ret && av[1]) improper_path(ret, av[1]); ft_strdel(&new_dir); del_av(av); }
int ft_check_consistency(const char *s, int pos) { char c[2]; if (!ft_charexist(FLAGS, s[pos])) { if (ft_charexist(ID, s[pos])) { c[0] = s[pos]; c[1] = 0; ft_print_error("unknown conversion type character ", c); } else ft_print_error("unknown conversion type character ", "0xa"); } return (0); }
int ftls_get_terminal_width(t_env *e) { struct winsize s_winsz; if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &s_winsz) == -1) { ft_print_error(e->progname, "ioctl()", errno); return (-1); } return (s_winsz.ws_col); }
void ftls_copy_details(t_entry *dst, struct stat *src, char *name, char *prefix) { char **buf; ft_bzero(dst, sizeof(t_entry)); buf = ft_memalloc(sizeof(char**)); if (!buf) exit(ft_print_error(NULL, NULL, errno)); *buf = ft_strdup(name); if (!*(buf)) exit(ft_print_error(NULL, NULL, errno)); dst->name = buf; ftls_copy_details_sub1(dst, src); if (prefix) { buf = ft_memalloc(sizeof(char**)); *buf = ft_strdup(prefix); dst->prefix = buf; } }
int is_infos(t_e *e, int i) { under(e, i); if (e->last_acq && e->last_acq->str[0] == '#') { e->last_acq = e->last_acq->next; if (e->end == 1) is_infos(e, 2); if (e->start == 1) is_infos(e, 1); } if (!e->last_acq) ft_print_error(e); return (1); }
t_ddata *ft_cpy_data(t_ddata *dest, char *src) { int ret; dest->name = ft_strdup(src); if (!dest->name) { ft_del_ddata(&dest); return (NULL); } ret = stat(dest->name, dest->dstat); if (ret == -1) { ft_print_error(dest->name); ft_del_ddata(&dest); return (NULL); } return (dest); }
int ftls_init_env(t_env *e, char **av) { int i; ft_bzero(e, sizeof(*e)); e->sort_time_val = 't'; if (!(e->progname = ft_strdup(av[0]))) { ft_print_error(av[0], NULL, errno); return (1); } i = -1; while (++i < OPT_ARRAY_SIZE) e->supported_option[i] = ft_strnew(2); ftls_define_options(e); if (isatty(1)) e->termwidth = ftls_get_terminal_width(e); e->maxcol[5] = 1; return (0); }
static void under(t_e *e, int i) { if (!e->last_acq) ft_print_error(e); if (e->last_acq->str[0] == 'L') ft_print_error(e); if (ft_strcmp("##start", e->last_acq->str) == 0 && i == 2) ft_print_error(e); if (ft_strcmp("##start", e->last_acq->str) == 0 && e->start != 0) ft_print_error(e); if (ft_strcmp("##start", e->last_acq->str) == 0) e->start = 1; if (ft_strcmp("##end", e->last_acq->str) == 0 && i == 1) ft_print_error(e); if (ft_strcmp("##end", e->last_acq->str) == 0 && e->end != 0) ft_print_error(e); if (ft_strcmp("##end", e->last_acq->str) == 0) e->end = 1; }