---
name: "libressl-BIO_s_fd"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-BIO_s_fd"
---

# libressl-BIO\_s\_fd(3)

file descriptor BIO

## NAME

**BIO\_s\_fd**, **BIO\_set\_fd**, **BIO\_get\_fd**, **BIO\_new\_fd**, **BIO\_fd\_non\_fatal\_error**, **BIO\_fd\_should\_retry** – file descriptor BIO

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

**#include \<openssl/bio.h\>**

*const* *BIO\_METHOD* *\**\

**BIO\_s\_fd**(*void*);

*long*\

**BIO\_set\_fd**(*BIO \*b*, *int fd*, *long close\_flag*);

*long*\

**BIO\_get\_fd**(*BIO \*b*, *int \*c*);

*BIO* *\**\

**BIO\_new\_fd**(*int fd*, *int close\_flag*);

*int*\

**BIO\_fd\_non\_fatal\_error**(*int errnum*);

*int*\

**BIO\_fd\_should\_retry**(*int retval*);

## DESCRIPTION

**BIO\_s\_fd**() returns the file descriptor BIO method. This is a wrapper around the platform's file descriptor routines such as [read(2)](/read/2.md) and [write(2)](/write/2.md).

BIO\_read(3) and BIO\_write(3) read or write the underlying descriptor. BIO\_puts(3) is supported but BIO\_gets(3) is not.

If the close flag is set, [close(2)](/close/2.md) is called on the underlying file descriptor when the *BIO* is freed.

BIO\_reset(3) attempts to set the file pointer to the start of the file using **lseek**(*fd*, *0*, *0*).

BIO\_seek(3) sets the file pointer to position *ofs* from start of file using **lseek**(*fd*, *ofs*, *0*).

BIO\_tell(3) returns the current file position by calling **lseek**(*fd*, *0*, *1*).

**BIO\_set\_fd**() sets the file descriptor of *BIO* *b* to *fd* and the close flag to *close\_flag*.

**BIO\_get\_fd**() places the file descriptor in *c* if it is not NULL and also returns the file descriptor.

**BIO\_new\_fd**() returns a file descriptor BIO using *fd* and *close\_flag*.

**BIO\_fd\_non\_fatal\_error**() determines whether the error status code *errnum* represents a recoverable error. **BIO\_fd\_should\_retry**() determines whether a recoverable error occurred by inspecting both [errno(2)](/errno/2.md) and *retval*, which is supposed to usually be the return value of a previously called function like BIO\_read(3) or BIO\_write(3). These two functions are mostly used internally; in application code, it is usually easier and more robust to use BIO\_should\_retry(3), which works for any BIO type.

The behaviour of BIO\_read(3) and BIO\_write(3) depends on the behavior of the platform's [read(2)](/read/2.md) and [write(2)](/write/2.md) calls on the descriptor. If the underlying file descriptor is in a non-blocking mode, then the BIO will behave in the manner described in the BIO\_read(3) and BIO\_should\_retry(3) manual pages.

File descriptor BIOs should not be used for socket I/O. Use socket BIOs instead.

BIO\_ctrl(3) *cmd* arguments correspond to macros as follows:

| | |
| --- | --- |
| *cmd* constant | corresponding macro |
| BIO\_C\_FILE\_SEEK | BIO\_seek(3) |
| BIO\_C\_FILE\_TELL | BIO\_tell(3) |
| BIO\_C\_GET\_FD | **BIO\_get\_fd**() |
| BIO\_C\_SET\_FD | **BIO\_set\_fd**() |
| BIO\_CTRL\_GET\_CLOSE | BIO\_get\_close(3) |
| BIO\_CTRL\_RESET | BIO\_reset(3) |
| BIO\_CTRL\_SET\_CLOSE | BIO\_set\_close(3) |

## RETURN VALUES

**BIO\_s\_fd**() returns the file descriptor BIO method.

When called on a file descriptor BIO object, BIO\_method\_type(3) returns the constant BIO\_TYPE\_FD and BIO\_method\_name(3) returns a pointer to the static string "file descriptor".

**BIO\_set\_fd**() always returns 1.

**BIO\_get\_fd**() returns the file descriptor or -1 if the *BIO* has not been initialized.

**BIO\_new\_fd**() returns the newly allocated *BIO* or NULL if an error occurred.

**BIO\_fd\_non\_fatal\_error**() returns 1 if *errnum* is EAGAIN, EALREADY, EINPROGRESS, EINTR, or ENOTCONN and 0 otherwise, even if *errnum* is 0.

**BIO\_fd\_should\_retry**() returns 1 if **BIO\_fd\_non\_fatal\_error**(*errno*) is 1 and *retval* is either 0 or -1, or 0 otherwise.

## EXAMPLES

This is a file descriptor BIO version of "Hello World":

```
BIO *out;
out = BIO_new_fd(fileno(stdout), BIO_NOCLOSE);
BIO_printf(out, "Hello World\n");
BIO_free(out);
```

## SEE ALSO

BIO\_new(3), BIO\_read(3), BIO\_s\_socket(3), BIO\_seek(3), BIO\_should\_retry(3)

## HISTORY

**BIO\_s\_fd**(), **BIO\_set\_fd**(), and **BIO\_get\_fd**() first appeared in SSLeay 0.6.0, **BIO\_fd\_should\_retry**() in SSLeay 0.6.5, and **BIO\_new\_fd**() and **BIO\_fd\_non\_fatal\_error**() in SSLeay 0.8.0. All these functions have been available since OpenBSD 2.4.
