@@ -239,13 +239,7 @@ _PyLong_FileDescriptor_Converter(PyObject *o, void *ptr)
239
239
** Py_UniversalNewlineFgets is an fgets variation that understands
240
240
** all of \r, \n and \r\n conventions.
241
241
** The stream should be opened in binary mode.
242
- ** If fobj is NULL the routine always does newline conversion, and
243
- ** it may peek one char ahead to gobble the second char in \r\n.
244
- ** If fobj is non-NULL it must be a PyFileObject. In this case there
245
- ** is no readahead but in stead a flag is used to skip a following
246
- ** \n on the next read. Also, if the file is open in binary mode
247
- ** the whole conversion is skipped. Finally, the routine keeps track of
248
- ** the different types of newlines seen.
242
+ ** The fobj parameter exists solely for legacy reasons and must be NULL.
249
243
** Note that we need no error handling: fgets() treats error and eof
250
244
** identically.
251
245
*/
@@ -254,32 +248,22 @@ Py_UniversalNewlineFgets(char *buf, int n, FILE *stream, PyObject *fobj)
254
248
{
255
249
char * p = buf ;
256
250
int c ;
257
- int newlinetypes = 0 ;
258
251
int skipnextlf = 0 ;
259
252
260
253
if (fobj ) {
261
254
errno = ENXIO ; /* What can you do... */
262
255
return NULL ;
263
256
}
264
257
FLOCKFILE (stream );
265
- c = 'x' ; /* Shut up gcc warning */
266
258
while (-- n > 0 && (c = GETC (stream )) != EOF ) {
267
- if (skipnextlf ) {
259
+ if (skipnextlf ) {
268
260
skipnextlf = 0 ;
269
261
if (c == '\n' ) {
270
262
/* Seeing a \n here with skipnextlf true
271
263
** means we saw a \r before.
272
264
*/
273
- newlinetypes |= NEWLINE_CRLF ;
274
265
c = GETC (stream );
275
266
if (c == EOF ) break ;
276
- } else {
277
- /*
278
- ** Note that c == EOF also brings us here,
279
- ** so we're okay if the last char in the file
280
- ** is a CR.
281
- */
282
- newlinetypes |= NEWLINE_CR ;
283
267
}
284
268
}
285
269
if (c == '\r' ) {
@@ -289,26 +273,15 @@ Py_UniversalNewlineFgets(char *buf, int n, FILE *stream, PyObject *fobj)
289
273
*/
290
274
skipnextlf = 1 ;
291
275
c = '\n' ;
292
- } else if ( c == '\n' ) {
293
- newlinetypes |= NEWLINE_LF ;
294
276
}
295
277
* p ++ = c ;
296
278
if (c == '\n' ) break ;
297
279
}
298
- /* if ( c == EOF && skipnextlf )
299
- newlinetypes |= NEWLINE_CR; */
300
280
FUNLOCKFILE (stream );
301
281
* p = '\0' ;
302
- if ( skipnextlf ) {
303
- /* If we have no file object we cannot save the
304
- ** skipnextlf flag. We have to readahead, which
305
- ** will cause a pause if we're reading from an
306
- ** interactive stream, but that is very unlikely
307
- ** unless we're doing something silly like
308
- ** exec(open("/dev/tty").read()).
309
- */
310
- c = GETC (stream );
311
- if ( c != '\n' )
282
+ if (skipnextlf ) {
283
+ int c = GETC (stream );
284
+ if (c != '\n' )
312
285
ungetc (c , stream );
313
286
}
314
287
if (p == buf )
0 commit comments