Changes: Ready for 5.13
[man-pages.git] / man3 / fileno.3
blobbb8ed60eacf79caabb747389de59bcb1dfafe3e7
1 .\" Copyright (c) 1990, 1991 The Regents of the University of California.
2 .\" and Copyright (C) 2021 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" All rights reserved.
4 .\"
5 .\" This code is derived from software contributed to Berkeley by
6 .\" Chris Torek and the American National Standards Committee X3,
7 .\" on Information Processing Systems.
8 .\"
9 .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
10 .\" Redistribution and use in source and binary forms, with or without
11 .\" modification, are permitted provided that the following conditions
12 .\" are met:
13 .\" 1. Redistributions of source code must retain the above copyright
14 .\"    notice, this list of conditions and the following disclaimer.
15 .\" 2. Redistributions in binary form must reproduce the above copyright
16 .\"    notice, this list of conditions and the following disclaimer in the
17 .\"    documentation and/or other materials provided with the distribution.
18 .\" 3. All advertising materials mentioning features or use of this software
19 .\"    must display the following acknowledgement:
20 .\"     This product includes software developed by the University of
21 .\"     California, Berkeley and its contributors.
22 .\" 4. Neither the name of the University nor the names of its contributors
23 .\"    may be used to endorse or promote products derived from this software
24 .\"    without specific prior written permission.
25 .\"
26 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 .\" SUCH DAMAGE.
37 .\" %%%LICENSE_END
38 .\"
39 .\" Converted for Linux, Mon Nov 29 14:24:40 1993, faith@cs.unc.edu
40 .\" Added remark on EBADF for fileno, aeb, 2001-03-22
41 .\"
42 .TH FILENO 3  2021-03-22 "" "Linux Programmer's Manual"
43 .SH NAME
44 fileno \- obtain file descriptor of a stdio stream
45 .SH SYNOPSIS
46 .nf
47 .B #include <stdio.h>
48 .PP
49 .BI "int fileno(FILE *" stream );
50 .fi
51 .PP
52 .RS -4
53 Feature Test Macro Requirements for glibc (see
54 .BR feature_test_macros (7)):
55 .RE
56 .PP
57 .BR fileno ():
58 .nf
59     _POSIX_C_SOURCE
60 .fi
61 .SH DESCRIPTION
62 .PP
63 The function
64 .BR fileno ()
65 examines the argument
66 .I stream
67 and returns the integer file descriptor used to implement this stream.
68 The file descriptor is still owned by
69 .I stream
70 and will be closed when
71 .BR fclose (3)
72 is called.
73 Duplicate the file descriptor with
74 .BR dup (2)
75 before passing it to code that might close it.
76 .PP
77 For the nonlocking counterpart, see
78 .BR unlocked_stdio (3).
79 .SH RETURN VALUE
80 On success,
81 .BR fileno ()
82 returns the file descriptor associated with
83 .IR stream .
84 On failure, \-1 is returned and
85 .I errno
86 is set to indicate the error.
87 .SH ERRORS
88 .TP
89 .B EBADF
90 .I stream
91 is not associated with a file.
92 .SH ATTRIBUTES
93 For an explanation of the terms used in this section, see
94 .BR attributes (7).
95 .ad l
96 .nh
97 .TS
98 allbox;
99 lbx lb lb
100 l l l.
101 Interface       Attribute       Value
103 .BR fileno ()
104 T}      Thread safety   MT-Safe
108 .sp 1
109 .SH CONFORMING TO
110 The function
111 .BR fileno ()
112 conforms to POSIX.1-2001 and POSIX.1-2008.
113 .SH SEE ALSO
114 .BR open (2),
115 .BR fdopen (3),
116 .BR stdio (3),
117 .BR unlocked_stdio (3)