t_spaces files_getspaces(t_spaces global, t_file *current_file) { t_spaces spaces; spaces.slks = global.slks - ft_sizeofnbr(current_file->st->st_nlink) + 1; spaces.sun = global.sun - ft_strlen(current_file->pwd->pw_name) + 1; spaces.gn = global.gn - ft_strlen(current_file->grp->gr_name) + 2; spaces.nb = global.nb - ft_sizeofnbr(current_file->st->st_size) + 2; return (spaces); }
t_spaces files_setspaces(t_list *files) { t_spaces spaces; spaces.slks = ft_sizeofnbr(((t_file*)(ft_lstgrtest(files, cmpslks)->content))->st->st_nlink); spaces.sun = ft_strlen(((t_file*)(ft_lstgrtest(files, cmpsun)->content))->pwd->pw_name); spaces.gn = ft_strlen(((t_file*)(ft_lstgrtest(files, cmpgn)->content))->grp->gr_name); spaces.nb = ft_sizeofnbr(((t_file*)(ft_lstgrtest(files, cmpnb)->content))->st->st_size); return (spaces); }
char *ft_itoa(int n) { int i; char *res; i = 0; res = (char *)malloc(sizeof(char) * BUF); if (res == NULL) return (NULL); i = ft_ifneg(res, &n, i); if (n >= 0 && n < 10) { res[i] = n + '0'; res[i + 1] = '\0'; return (res); } else { i = ft_sizeofnbr(res, &n, i); while (n > 0) { res[i] = n % 10 + '0'; n /= 10; i--; } } return (res); }
double ft_atod(char const *str) { int ent_part; int dec_part; ent_part = ft_atoi(str); while (ft_isdigit(*str)) str++; if (*str++ == '.') dec_part = ft_atoi(str); else dec_part = 0; return ((double)ent_part + (dec_part / (double)ft_sizeofnbr(dec_part))); }