]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/fileno.3
man*/: ffix (un-bracket tables)
[thirdparty/man-pages.git] / man3 / fileno.3
1 '\" t
2 .\" Copyright (c) 1990, 1991 The Regents of the University of California.
3 .\" and Copyright (C) 2021 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" All rights reserved.
5 .\"
6 .\" This code is derived from software contributed to Berkeley by
7 .\" Chris Torek and the American National Standards Committee X3,
8 .\" on Information Processing Systems.
9 .\"
10 .\" SPDX-License-Identifier: BSD-4-Clause-UC
11 .\"
12 .\" Converted for Linux, Mon Nov 29 14:24:40 1993, faith@cs.unc.edu
13 .\" Added remark on EBADF for fileno, aeb, 2001-03-22
14 .\"
15 .TH fileno 3 (date) "Linux man-pages (unreleased)"
16 .SH NAME
17 fileno \- obtain file descriptor of a stdio stream
18 .SH LIBRARY
19 Standard C library
20 .RI ( libc ", " \-lc )
21 .SH SYNOPSIS
22 .nf
23 .B #include <stdio.h>
24 .PP
25 .BI "int fileno(FILE *" stream );
26 .fi
27 .PP
28 .RS -4
29 Feature Test Macro Requirements for glibc (see
30 .BR feature_test_macros (7)):
31 .RE
32 .PP
33 .BR fileno ():
34 .nf
35 _POSIX_C_SOURCE
36 .fi
37 .SH DESCRIPTION
38 The function
39 .BR fileno ()
40 examines the argument
41 .I stream
42 and returns the integer file descriptor used to implement this stream.
43 The file descriptor is still owned by
44 .I stream
45 and will be closed when
46 .BR fclose (3)
47 is called.
48 Duplicate the file descriptor with
49 .BR dup (2)
50 before passing it to code that might close it.
51 .PP
52 For the nonlocking counterpart, see
53 .BR unlocked_stdio (3).
54 .SH RETURN VALUE
55 On success,
56 .BR fileno ()
57 returns the file descriptor associated with
58 .IR stream .
59 On failure, \-1 is returned and
60 .I errno
61 is set to indicate the error.
62 .SH ERRORS
63 .TP
64 .B EBADF
65 .I stream
66 is not associated with a file.
67 .SH ATTRIBUTES
68 For an explanation of the terms used in this section, see
69 .BR attributes (7).
70 .TS
71 allbox;
72 lbx lb lb
73 l l l.
74 Interface Attribute Value
75 T{
76 .na
77 .nh
78 .BR fileno ()
79 T} Thread safety MT-Safe
80 .TE
81 .sp 1
82 .SH STANDARDS
83 POSIX.1-2008.
84 .SH HISTORY
85 POSIX.1-2001.
86 .SH SEE ALSO
87 .BR open (2),
88 .BR fdopen (3),
89 .BR stdio (3),
90 .BR unlocked_stdio (3)