--- ray/src/common/fgetline.c 2003/02/25 02:47:21 2.3 +++ ray/src/common/fgetline.c 2004/04/29 14:36:49 2.6 @@ -1,17 +1,21 @@ #ifndef lint -static const char RCSid[] = "$Id: fgetline.c,v 2.3 2003/02/25 02:47:21 greg Exp $"; +static const char RCSid[] = "$Id: fgetline.c,v 2.6 2004/04/29 14:36:49 greg Exp $"; #endif /* * fgetline.c - read line with escaped newlines. * - * External symbols declared in standard.h + * External symbols declared in rtio.h */ #include "copyright.h" -#include +#include "rtio.h" +#ifdef getc_unlocked /* avoid horrendous overhead of flockfile */ +#define getc getc_unlocked +#endif + char * fgetline(s, n, fp) /* read in line with escapes, elide final newline */ char *s; @@ -22,8 +26,10 @@ register FILE *fp; register int c = EOF; while (--n > 0 && (c = getc(fp)) != EOF) { - if (c == '\r') - continue; + if (c == '\r' && (c = getc(fp)) != '\n') { + ungetc(c, fp); /* must be Apple file */ + c = '\n'; + } if (c == '\n' && (cp == s || cp[-1] != '\\')) break; *cp++ = c;