@@ -239,13 +239,7 @@ _PyLong_FileDescriptor_Converter(PyObject *o, void *ptr)
239239** Py_UniversalNewlineFgets is an fgets variation that understands
240240** all of \r, \n and \r\n conventions.
241241** 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.
249243** Note that we need no error handling: fgets() treats error and eof
250244** identically.
251245*/
@@ -254,32 +248,22 @@ Py_UniversalNewlineFgets(char *buf, int n, FILE *stream, PyObject *fobj)
254248{
255249 char * p = buf ;
256250 int c ;
257- int newlinetypes = 0 ;
258251 int skipnextlf = 0 ;
259252
260253 if (fobj ) {
261254 errno = ENXIO ; /* What can you do... */
262255 return NULL ;
263256 }
264257 FLOCKFILE (stream );
265- c = 'x' ; /* Shut up gcc warning */
266258 while (-- n > 0 && (c = GETC (stream )) != EOF ) {
267- if (skipnextlf ) {
259+ if (skipnextlf ) {
268260 skipnextlf = 0 ;
269261 if (c == '\n' ) {
270262 /* Seeing a \n here with skipnextlf true
271263 ** means we saw a \r before.
272264 */
273- newlinetypes |= NEWLINE_CRLF ;
274265 c = GETC (stream );
275266 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 ;
283267 }
284268 }
285269 if (c == '\r' ) {
@@ -289,26 +273,15 @@ Py_UniversalNewlineFgets(char *buf, int n, FILE *stream, PyObject *fobj)
289273 */
290274 skipnextlf = 1 ;
291275 c = '\n' ;
292- } else if ( c == '\n' ) {
293- newlinetypes |= NEWLINE_LF ;
294276 }
295277 * p ++ = c ;
296278 if (c == '\n' ) break ;
297279 }
298- /* if ( c == EOF && skipnextlf )
299- newlinetypes |= NEWLINE_CR; */
300280 FUNLOCKFILE (stream );
301281 * 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' )
312285 ungetc (c , stream );
313286 }
314287 if (p == buf )
0 commit comments