fileno - Man Page

obtain file descriptor of a stdio stream

Library

Standard C library (libc, -lc)

Synopsis

#include <stdio.h>

int fileno(FILE *stream);

Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

fileno():

    _POSIX_C_SOURCE

Description

The function fileno() examines the argument stream and returns the integer file descriptor used to implement this stream. The file descriptor is still owned by stream and will be closed when fclose(3) is called. Duplicate the file descriptor with dup(2) before passing it to code that might close it.

For the nonlocking counterpart, see unlocked_stdio(3).

Return Value

On success, fileno() returns the file descriptor associated with stream. On failure, -1 is returned and errno is set to indicate the error.

Errors

EBADF

stream is not associated with a file.

Attributes

For an explanation of the terms used in this section, see attributes(7).

InterfaceAttributeValue
fileno()Thread safetyMT-Safe

Standards

POSIX.1-2008.

History

POSIX.1-2001.

See Also

open(2), fdopen(3), stdio(3), unlocked_stdio(3)

Referenced By

fclose(3), ferror(3), fflush(3), fmemopen(3), fopen(3), fsync(2), open_memstream(3), pcap_file.3pcap(3), stdio(3).

2024-05-02 Linux man-pages 6.9.1