Re: [PATCH] ferror.3: Warn about closing the result of fileno()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Elliot,

On 10/1/18 7:33 PM, enh wrote:
> Since adding checking to Android's bionic for file descriptor double-closes,
> we've found that the most common cause of these bugs is incorrect use of
> fileno(3). There appears to be a common misconception that it transfers
> ownership of the file descriptor to the caller.

Thanks. Patch applied.

Cheers,

Michael

> ---
>  man3/ferror.3 | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/man3/ferror.3 b/man3/ferror.3
> index b45eb5559..609e10cf8 100644
> --- a/man3/ferror.3
> +++ b/man3/ferror.3
> @@ -89,7 +89,15 @@ The function
>  .BR fileno ()
>  examines the argument
>  .I stream
> -and returns its integer file descriptor.
> +and returns the integer file descriptor used to implement this stream.
> +The file descriptor is still owned by
> +.I stream
> +and will be closed when
> +.BR fclose (3)
> +is called.
> +Duplicate the file descriptor with
> +.BR dup (2)
> +before passing it to code that might close it.
>  .PP
>  For nonlocking counterparts, see
>  .BR unlocked_stdio (3).
> 


-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/



[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux