Skip to content

Commit 9390fc1

Browse files
ZeroIntensitymiss-islington
authored andcommitted
gh-141004: Document Py_UniversalNewlineFgets (GH-159713)
(cherry picked from commit 6297f8d) Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
1 parent 81fe70e commit 9390fc1

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
@@ -33,8 +33,6 @@ PyCFunction_GET_CLASS
3333
PyDescr_NAME
3434
PyDescr_TYPE
3535
PyWrapperFlag_KEYWORDS
36-
# cpython/fileobject.h
37-
Py_UniversalNewlineFgets
3836
# cpython/pylifecycle.h
3937
Py_FrozenMain
4038
# cpython/objimpl.h

0 commit comments

Comments
 (0)