oki dsl voila tt :
void *malloc(unsigned int size);
#include <fcntl.h>
#define BUFF_SIZE 42
static char buff[BUFF_SIZE];
static int count = 0;
static int Rbuf = 0;
//static int start;
static int Cread = 0;
static char *more_line(char *line,int cur)
{
char *str;
int len;
str = malloc((len =(line ? my_strlen(line) : 0)) + cur + 1);
my_strcpy(str,line ? line : "" );
my_strncpy(str + len, buff + count, cur);
str[len + cur] = 0;
if (line)
free(line);
count += cur + 1;
return (str);
}
static int read_f(int fd)
{
Rbuf = read(fd, buff, BUFF_SIZE);
count = 0;
if (Rbuf != BUFF_SIZE)
Cread = Rbuf;
}
char *get_next_line(const int fd)
{
int tmp;
char *str;
for (str = 0tmp = 0; ; tmp++)
{
if (count >= Rbuf)
{
if (Cread)
return (0);
read_f(fd);
tmp = 0;
}
if (buff[count + tmp] == '\n'
{
str = more_line(str, tmp);
return (str);
}
if (count + tmp == Rbuf - 1)
str = more_line(str, tmp + 1);
}
}
//char *get_next_line(const int fd);
int main()
{
char *s;
int fd;
fd = open ("test", O_RDONLY);
//s = get_next_line(fd);
while ((s = get_next_line(0)))
{
my_putstr(s);
close (fd);
free(s);
}
return (0);
}