Skip to content

Commit 22a6215

Browse files
[3.14] gh-141004: Document Py_UniversalNewlineFgets (GH-159713) (GH-159798)
(cherry picked from commit 6297f8d) Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
1 parent 3beccbe commit 22a6215

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

‎Doc/c-api/file.rst‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,29 @@ the :mod:`io` APIs instead.
6060
raised if the end of the file is reached immediately.
6161
6262
63+
.. c:function:: char* Py_UniversalNewlineFgets(char *buf, int n, FILE *stream, PyObject *fobj)
64+
65+
Read a line from the C stream *stream* into the buffer *buf*, like the
66+
C standard library function :c:func:`!fgets`, but treating all of ``\n``,
67+
``\r`` and ``\r\n`` as line endings (see :term:`universal newlines`).
68+
Any ``\r`` or ``\r\n`` read from the stream is stored in *buf* as a
69+
single ``\n``.
70+
71+
At most ``n - 1`` characters are stored in *buf*; reading stops after a
72+
newline has been stored or when the end of the file is reached.
73+
The result is always null-terminated.
74+
*stream* should be opened in binary mode, so that the C library does not
75+
perform its own newline translation.
76+
77+
Return *buf* on success.
78+
Return ``NULL`` if no characters could be read, because *stream* is at
79+
end of file, a read error occurred, or *n* is less than 2.
80+
Like :c:func:`!fgets`, this function does not distinguish between end of
81+
file and a read error, and it does not set an exception.
82+
83+
*fobj* exists only for backward compatibility and must be ``NULL``.
84+
85+
6386
.. c:function:: int PyFile_SetOpenCodeHook(Py_OpenCodeHookFunction handler)
6487
6588
Overrides the normal behavior of :func:`io.open_code` to pass its parameter

‎Tools/check-c-api-docs/ignored_c_api.txt‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ PyDescr_COMMON
5656
PyDescr_NAME
5757
PyDescr_TYPE
5858
PyWrapperFlag_KEYWORDS
59-
# cpython/fileobject.h
60-
Py_UniversalNewlineFgets
6159
# cpython/pylifecycle.h
6260
Py_FrozenMain
6361
# cpython/objimpl.h

0 commit comments

Comments
 (0)