1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| /*lecture d'une ligne de fichier*/
int get_line (FILE *stream, char **pp_line)
{
void *line = NULL;
char tmp[BUFSIZ] = "";
size_t size = 1;
/* Bug Integration sur fichier > 10 Mo */
/* 17/12/2008 BLE Release memory allocation */
/*free (*pp_line);*/
if (stream != NULL && pp_line != NULL)
{
*pp_line = NULL;
while (fgets (tmp, BUFSIZ, stream) != NULL)
{
/* printf("After fgets, BUFSIZ : %d\n", BUFSIZ); */
/* printf("%s\n", tmp); */
size += BUFSIZ;
line = realloc (*pp_line, sizeof (**pp_line) * size);
if (line != NULL)
{
/* printf("Begin line != NULL\n"); */
if (*pp_line == NULL)
{
/* printf("Begin *pp_line == NULL\n"); */
((char *)line)[0] = '\0';
}
*pp_line = line;
line = NULL;
strcat (*pp_line, tmp);
if ((*pp_line)[strlen (*pp_line)-1] == '\n')
{
(*pp_line)[strlen (*pp_line)-1] = '\n';
break;
}
}
else
{
/* printf("Begin else *pp_line == NULL\n"); */
/*free (*pp_line);*/
*pp_line = NULL;
}
}
}
return **pp_line;
} |
Partager