int ft_join_move(char **line, char *buff, char *next_line, int nbread) { *next_line = '\0'; if (!(*line = ft_join_free(line, buff))) return (-1); buff = ft_memmove(buff, &next_line[1], ft_strlen(&next_line[1]) + 1); if (buff == NULL) return (-1); return (nbread); }
int ft_buff_leftover(char *buff, char **line) { char *next_line; if ((next_line = ft_strchr(buff, '\n'))) { next_line[0] = '\0'; if (!(*line = ft_join_free(line, buff))) return (-1); buff = ft_memmove(buff, &next_line[1], (ft_strlen(&next_line[1]) + 1)); return (1); } else { if (!(*line = ft_join_free(line, buff))) return (-1); ft_strclr(buff); return (0); } }
char *ft_lftoa(long double nbr) { char *str; str = ft_first((long double)((long long int)nbr)); nbr = nbr - (long long int)nbr; if (nbr < 0) nbr *= -1; str = ft_join_free(str, ft_second(nbr)); return (str); }
int get_next_line(int const fd, char **line) { static char *str[256]; char *tmp; int ret; if (BUFF_SIZE == 0) return (0); if (fd < 0 || line == NULL || fd > 256) return (-1); str[fd] = str[fd] ? str[fd] : ft_strnew(0); tmp = (char *)malloc(sizeof(char) * (BUFF_SIZE + 1)); while ((ret = read(fd, tmp, BUFF_SIZE)) > 0) { tmp[ret] = '\0'; str[fd] = ft_join_free(str[fd], tmp); if (ft_strchr(str[fd], '\n')) break ; } free(tmp); return (ft_find_line(ret, &str[fd], line)); }
int ft_readfile(int const fd, char **line, char *buff) { char *next_line; ssize_t nbread; while ((nbread = read(fd, (void *)buff, (size_t)BUFF_SIZE))) { if (nbread == -1) { ft_strdel(&buff); return (-1); } buff[nbread] = '\0'; if (!(next_line = ft_strchr(buff, '\n'))) { if (!(*line = ft_join_free(line, buff))) return (-1); ft_strclr(buff); } else return (ft_join_move(line, buff, next_line, nbread)); } return (nbread); }