---
name: "libressl-BIO_dup_chain"
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_dup_chain"
---

# libressl-BIO\_dup\_chain(3)

copy a BIO chain

## NAME

**BIO\_dup\_chain**, **BIO\_dup\_state** – copy a BIO chain

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

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

*BIO* *\**\

**BIO\_dup\_chain**(*BIO \*b*);

*long*\

**BIO\_dup\_state**(*BIO \*b*, *BIO \*new\_bio*);

## DESCRIPTION

**BIO\_dup\_chain**() copies the chain starting at *b* by iteratively copying *b* and all the BIOs following it and joining the copies in the same order as in the original chain. The copying operation is neither a deep copy nor a shallow copy.

Some parts of the state of each BIO are copied, in particular with respect to the values returned by BIO\_get\_init(3), BIO\_test\_flags(3), and BIO\_get\_shutdown(3). Other parts of the state of the BIOs are not copied but instead initialized to 0, in particular with respect to the values returned by BIO\_number\_read(3), BIO\_number\_written(3), and BIO\_get\_retry\_reason(3). The custom data pointer that can be used by custom BIO types and that can be retrieved with BIO\_get\_data(3) is set to NULL in the copied BIO objects rather than copied. The reference count of each BIO in the copied chain is set to 1.

For each BIO in the chain, copying the data that was set with BIO\_set\_ex\_data(3) is attempted, which may involve calling application-defined callback functions.

The following pointers are copied rather than creating deep copies of the objects pointed to:

- The *type* pointer used for creating each BIO with BIO\_new(3), implying that functions like BIO\_method\_name(3) return pointers to the same strings for the BIOs in the copied chain, and that these strings are not copied.

- All function pointers, in particular those installed with BIO\_set\_callback\_ex(3) and BIO\_get\_callback\_ex(3).

- The pointer installed with BIO\_set\_callback\_arg(3), which implies that for BIOs using BIO\_debug\_callback(3), those in the copied chain use the same BIOs for debugging output as the corresponding ones in the original chain, and none of the debugging output BIOs are copied.

**BIO\_dup\_state**() is a macro that calls BIO\_ctrl(3) with a *cmd* argument of BIO\_CTRL\_DUP. It is automatically called for each BIO during **BIO\_dup\_chain**() after the copied BIO is initialized and data copied into it, but before the data set with BIO\_set\_ex\_data(3) is copied into the new BIO and before it is linked into the new chain.

This control operation may modify the operation of **BIO\_dup\_chain**() for particular types of BIOs contained in the chain, for example initializing or copying additional data. For BIO types provided by the library, such additional effects are documented in the respective manual pages, in particular in BIO\_f\_buffer(3), BIO\_f\_cipher(3), BIO\_f\_md(3), BIO\_f\_ssl(3), BIO\_s\_bio(3), and BIO\_s\_connect(3).

## RETURN VALUES

**BIO\_dup\_chain**() returns a pointer to the newly allocated copy of the BIO *b* on success or NULL on failure .

**BIO\_dup\_state**() returns 1 on success or a value less than or equal to zero on failure.

## SEE ALSO

BIO\_get\_data(3), BIO\_new(3), BIO\_next(3), BIO\_push(3)

## HISTORY

**BIO\_dup\_chain**() and **BIO\_dup\_state**() first appeared in SSLeay 0.8.0 and have been available since OpenBSD 2.4.
