---
name: "freebsd::fd_up"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/freebsd::fd_up"
---

# freebsd::fd\_up(3)

own a file descriptor

## NAME

**freebsd::fd\_up** – own a file descriptor

## LIBRARY

library “libutil++”

## SYNOPSIS

**#include \<libutil++.hh\>**

*class* *freebsd::fd\_up* {

**fd\_up**();

**fd\_up**(*int fd*);

**fd\_up**(*fd\_up &&other*);

**~fd\_up**();

*int*\

**get**();

*int*\

**release**();

*void*\

**reset**(*int newfd = -1*);

*fd\_up &*\

**operator=**(*fd\_up &&other*);

*fd\_up &*\

**operator=**(*int fd*);

**explicit operator bool**();

**operator int**();

};

## DESCRIPTION

Each instance of this class owns a file descriptor. This class is patterned on std::unique\_ptr, but instead of owning a pointer to an object, this class owns a file descriptor. The currently-owned file descriptor is disposed by invoking [close(2)](/close/2.md) when an instance of this class is destroyed. The currently-owned file descriptor is also disposed if it is replaced by the **reset**() method or assignment operators.

The **get**() method returns the current file descriptor value while retaining ownership.

The **release**() method relinquishes ownership of the current file descriptor and returns the value of the previously-owned file descriptor.

The explicit *bool* conversion operator permits testing the validity of an object. The operator returns true if the instance owns a valid file descriptor.

The implicit *int* conversion operator permits passing an instance of this class directly as an argument to existing functions which expect a file descriptor.

## EXAMPLES

```
freebsd::fd_up fd(open("/dev/null", O_RDWR));
if (!fd)
	err(1, "open");
write(fd, "test", 4);
// `fd' is implicitly closed on destruction
```

## SEE ALSO

[close(2)](/close/2.md)
