[Python-Dev] Rehabilitating fgets

Tim Peters tim.one@home.com
Sun, 7 Jan 2001 23:13:26 -0500


The "Win32" readline() hack is now checked in, but there's really nothing
Win32-specific about it anymore.  It makes one mild assumption about what
the C std doesn't clearly address but may have intended:  that in case of a
non-NULL return, fgets doesn't overwrite any of the buffer positions beyond
the terminating null byte (the std is clear that it doesn't overwrite
anything at all in case of a NULL-because-EOF return, but I can't say
whether they're pointing that out as a consequence, or pointing that out as
an exception).

I'm curious about how it performs (relative to the getc_unlocked hack) on
other platforms.  If you'd like to try that, just recompile fileobject.c
with

    USE_MS_GETLINE_HACK

#define'd.  It should *work* on any platform with fgets() meeting the
assumption.  The new test_bufio.py std test gives it a pretty good
correctness workout, if you're worried about that.