Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 9 additions & 23 deletions Objects/fileobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,42 +248,28 @@ Py_UniversalNewlineFgets(char *buf, int n, FILE *stream, PyObject *fobj)
{
char *p = buf;
int c;
int skipnextlf = 0;

if (fobj) {
errno = ENXIO; /* What can you do... */
return NULL;
}
FLOCKFILE(stream);
while (--n > 0 && (c = GETC(stream)) != EOF ) {
if (skipnextlf) {
skipnextlf = 0;
if (c == '\n') {
/* Seeing a \n here with skipnextlf true
** means we saw a \r before.
*/
c = GETC(stream);
if (c == EOF) break;
}
}
if (c == '\r') {
/* A \r is translated into a \n, and we skip
** an adjacent \n, if any. We don't set the
** newlinetypes flag until we've seen the next char.
*/
skipnextlf = 1;
c = '\n';
// A \r is translated into a \n, and we skip an adjacent \n, if any.
c = GETC(stream);
if (c != '\n') {
ungetc(c, stream);
c = '\n';
}
}
*p++ = c;
if (c == '\n') break;
if (c == '\n') {
break;
}
}
FUNLOCKFILE(stream);
*p = '\0';
if (skipnextlf) {
int c = GETC(stream);
if (c != '\n')
ungetc(c, stream);
}
if (p == buf)
return NULL;
return buf;
Expand Down