1fileno(3) Library Functions Manual fileno(3)
2
3
4
6 fileno - obtain file descriptor of a stdio stream
7
9 Standard C library (libc, -lc)
10
12 #include <stdio.h>
13
14 int fileno(FILE *stream);
15
16 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
17
18 fileno():
19 _POSIX_C_SOURCE
20
22 The function fileno() examines the argument stream and returns the in‐
23 teger file descriptor used to implement this stream. The file descrip‐
24 tor is still owned by stream and will be closed when fclose(3) is
25 called. Duplicate the file descriptor with dup(2) before passing it to
26 code that might close it.
27
28 For the nonlocking counterpart, see unlocked_stdio(3).
29
31 On success, fileno() returns the file descriptor associated with
32 stream. On failure, -1 is returned and errno is set to indicate the
33 error.
34
36 EBADF stream is not associated with a file.
37
39 For an explanation of the terms used in this section, see at‐
40 tributes(7).
41
42 ┌────────────────────────────────────────────┬───────────────┬─────────┐
43 │Interface │ Attribute │ Value │
44 ├────────────────────────────────────────────┼───────────────┼─────────┤
45 │fileno() │ Thread safety │ MT-Safe │
46 └────────────────────────────────────────────┴───────────────┴─────────┘
47
49 POSIX.1-2008.
50
52 POSIX.1-2001.
53
55 open(2), fdopen(3), stdio(3), unlocked_stdio(3)
56
57
58
59Linux man-pages 6.04 2023-03-30 fileno(3)