---
name: "fileno"
section: "3"
platform: "linux"
package: "man-pages"
version: "6.19-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/fileno"
---

# fileno(3)

obtain file descriptor of a stdio stream

## NAME

fileno - 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)](/feature_test_macros/7.md)):

**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)](/fclose/3.md) is called. Duplicate the file descriptor with [**dup**(2)](/dup/2.md) before passing it to code that might close it.

For the nonlocking counterpart, see [**unlocked\_stdio**(3)](/unlocked_stdio/3.md).

## 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)](/attributes/7.md).

| | | |
| --- | --- | --- |
| **Interface** | **Attribute** | **Value** |
| **fileno**() | Thread safety | MT-Safe |

## STANDARDS

POSIX.1-2008.

## HISTORY

POSIX.1-2001.

## SEE ALSO

[**open**(2)](/open/2.md), [**fdopen**(3)](/fdopen/3.md), [**stdio**(3)](/stdio/3.md), [**unlocked\_stdio**(3)](/unlocked_stdio/3.md)
