File: [Development] / xfs-cmds / attr / libmisc / next_line.c (download)
Revision 1.1, Tue Feb 22 02:49:39 2005 UTC (12 years, 7 months ago) by nathans.longdrop.melbourne.sgi.com
Branch: MAIN
Updated next_line fix from AndreasG
Merge of master-melb:xfs-cmds:21594a by kenmcd.
|
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include "misc.h"
char *next_line(FILE *file)
{
static char *line;
static size_t line_size;
char *c;
int eol = 0;
if (!line) {
if (high_water_alloc((void **)&line, &line_size, PATH_MAX))
return NULL;
}
c = line;
do {
if (!fgets(c, line_size - (c - line), file))
return NULL;
c = strrchr(c, '\0');
while (c > line && (*(c-1) == '\n' || *(c-1) == '\r')) {
c--;
*c = '\0';
eol = 1;
}
if (feof(file))
break;
if (!eol) {
if (high_water_alloc((void **)&line, &line_size,
2 * line_size))
return NULL;
c = strrchr(line, '\0');
}
} while (!eol);
return line;
}