1FILENO(3) Linux Programmer's Manual FILENO(3)
2
3
4
6 fileno - obtain file descriptor of a stdio stream
7
9 #include <stdio.h>
10
11 int fileno(FILE *stream);
12
13 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
14
15 fileno():
16 _POSIX_C_SOURCE
17
19 The function fileno() examines the argument stream and returns the in‐
20 teger file descriptor used to implement this stream. The file descrip‐
21 tor is still owned by stream and will be closed when fclose(3) is
22 called. Duplicate the file descriptor with dup(2) before passing it to
23 code that might close it.
24
25 For the nonlocking counterpart, see unlocked_stdio(3).
26
28 On success, fileno() returns the file descriptor associated with
29 stream. On failure, -1 is returned and errno is set to indicate the
30 error.
31
33 EBADF stream is not associated with a file.
34
36 For an explanation of the terms used in this section, see at‐
37 tributes(7).
38
39 ┌────────────────────────────────────────────┬───────────────┬─────────┐
40 │Interface │ Attribute │ Value │
41 ├────────────────────────────────────────────┼───────────────┼─────────┤
42 │fileno() │ Thread safety │ MT-Safe │
43 └────────────────────────────────────────────┴───────────────┴─────────┘
44
46 The function fileno() conforms to POSIX.1-2001 and POSIX.1-2008.
47
49 open(2), fdopen(3), stdio(3), unlocked_stdio(3)
50
52 This page is part of release 5.12 of the Linux man-pages project. A
53 description of the project, information about reporting bugs, and the
54 latest version of this page, can be found at
55 https://www.kernel.org/doc/man-pages/.
56
57
58
59 2021-03-22 FILENO(3)