Document limitations on streams passed to freopen

Message ID 3889717-62fc-7bcb-2f3e-bde77b7a9d6a@redhat.com
State Superseded
Headers
Series Document limitations on streams passed to freopen |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Build passed
redhat-pt-bot/TryBot-32bit success Build for i686
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Test passed
redhat-pt-bot/TryBot-still_applies warning Patch no longer applies to master

Commit Message

Joseph Myers Sept. 5, 2024, 9:50 p.m. UTC
  As recently discussed, document that freopen does not work with
streams opened with functions such as popen, fmemopen, open_memstream
or fopencookie.  I've filed
<https://austingroupbugs.net/view.php?id=1855> to clarify this issue
in POSIX.

Tested with "make info" and "make html".
  

Comments

Florian Weimer Sept. 6, 2024, 6:43 a.m. UTC | #1
* Joseph Myers:

> As recently discussed, document that freopen does not work with
> streams opened with functions such as popen, fmemopen, open_memstream
> or fopencookie.  I've filed
> <https://austingroupbugs.net/view.php?id=1855> to clarify this issue
> in POSIX.
>
> Tested with "make info" and "make html".
>
> diff --git a/manual/stdio.texi b/manual/stdio.texi
> index 29888a361f..d07b3e5ad6 100644
> --- a/manual/stdio.texi
> +++ b/manual/stdio.texi
> @@ -330,6 +330,14 @@ this ability, so using @code{freopen} is more portable.
>  When the sources are compiled with @code{_FILE_OFFSET_BITS == 64} on a
>  32 bit machine this function is in fact @code{freopen64} since the LFS
>  interface replaces transparently the old interface.
> +
> +@Theglibc{} only supports use of @code{freopen} on streams opened with
> +@code{fopen} or @code{fopen64} and on the standard streams
> +@code{stdin}, @code{stdout}, and @code{stderr}; such a stream may be
> +reopened multiple times with @code{freopen}.  If it is called on
> +another kind of stream (opened with functions such as @code{popen},
> +@code{fmemopen}, @code{open_memstream}, and @code{fopencookie}),
> +@code{freopen} fails and returns a null pointer.
>  @end deftypefun

We support reassignment of stdin etc., so please say something like “the
original values of the standatd streams @code{stdin}”.  Assignment to
stdin does not magically make freopen valid.

Thanks,
Florian
  

Patch

diff --git a/manual/stdio.texi b/manual/stdio.texi
index 29888a361f..d07b3e5ad6 100644
--- a/manual/stdio.texi
+++ b/manual/stdio.texi
@@ -330,6 +330,14 @@  this ability, so using @code{freopen} is more portable.
 When the sources are compiled with @code{_FILE_OFFSET_BITS == 64} on a
 32 bit machine this function is in fact @code{freopen64} since the LFS
 interface replaces transparently the old interface.
+
+@Theglibc{} only supports use of @code{freopen} on streams opened with
+@code{fopen} or @code{fopen64} and on the standard streams
+@code{stdin}, @code{stdout}, and @code{stderr}; such a stream may be
+reopened multiple times with @code{freopen}.  If it is called on
+another kind of stream (opened with functions such as @code{popen},
+@code{fmemopen}, @code{open_memstream}, and @code{fopencookie}),
+@code{freopen} fails and returns a null pointer.
 @end deftypefun
 
 @deftypefun {FILE *} freopen64 (const char *@var{filename}, const char *@var{opentype}, FILE *@var{stream})