--- ray/src/common/fgetline.c 1989/10/04 16:36:55 1.2 +++ ray/src/common/fgetline.c 2004/04/29 14:36:49 2.6 @@ -1,29 +1,35 @@ -/* Copyright (c) 1989 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +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. * - * 10/4/89 + * External symbols declared in rtio.h */ -#include +#include "copyright.h" +#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; int n; register FILE *fp; { - int escape = 0; register char *cp = s; register int c = EOF; while (--n > 0 && (c = getc(fp)) != EOF) { + 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;