---
name: "sd_hwdb_unref"
section: "3"
platform: "linux"
package: "libsystemd-dev"
version: "257.13-1~deb13u1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/sd_hwdb_new"
---

# sd\_hwdb\_unref(3)

Create a new hwdb object and create or destroy references to it

Part of [sd\_hwdb\_new(3)](/sd_hwdb_new/3.md).

## NAME

sd\_hwdb\_new, sd\_hwdb\_new\_from\_path, sd\_hwdb\_ref, sd\_hwdb\_unref - Create a new hwdb object and create or destroy references to it

## SYNOPSIS

```
#include <systemd/sd-hwdb.h>
```

**int sd\_hwdb\_new(sd\_hwdb \*\****hwdb***);**

**int sd\_hwdb\_new\_from\_path(const char \****path***, sd\_hwdb \*\****hwdb***);**

**sd\_hwdb\* sd\_hwdb\_ref(sd\_hwdb \****hwdb***);**

**sd\_hwdb\* sd\_hwdb\_unref(sd\_hwdb \****hwdb***);**

## DESCRIPTION

**sd\_hwdb\_new()** creates a new hwdb object to access the binary hwdb database. Upon initialization, the file containing the binary representation of the hardware database is located and opened. The new object is returned in *hwdb*.

**sd\_hwdb\_new\_from\_path()** may be used to specify the path from which the binary hardware database should be opened.

The *hwdb* object is reference counted. **sd\_hwdb\_ref()** and **sd\_hwdb\_unref()** may be used to get a new reference or destroy an existing reference to an object. The caller must dispose of the reference acquired with **sd\_hwdb\_new()** by calling **sd\_hwdb\_unref()** when done with the object.

Use [**sd\_hwdb\_seek**(3)](/sd_hwdb_seek/3.md), [**sd\_hwdb\_get**(3)](/sd_hwdb_get/3.md), and [**sd\_hwdb\_enumerate**(3)](/sd_hwdb_enumerate/3.md) to access entries.

## RETURN VALUE

On success, **sd\_hwdb\_new()** and **sd\_hwdb\_new\_from\_path()** return a non-negative integer. On failure, a negative errno-style error code is returned.

**sd\_hwdb\_ref()** always returns the argument.

**sd\_hwdb\_unref()** always returns **NULL**.

### Errors

Returned errors may indicate the following problems:

**-ENOENT**

The binary hardware database file could not be located. See [**systemd-hwdb**(8)](/systemd-hwdb/8.md) for more information.

Added in version 246.

**-EINVAL**

The located binary hardware database file is in an incompatible format.

Added in version 246.

**-ENOMEM**

Memory allocation failed.

Added in version 246.

## NOTES

Functions described here are available as a shared library, which can be compiled against and linked to with the **libsystemd** [**pkg-config**(1)](/pkg-config/1.md) file.

The code described here uses [**getenv**(3)](/getenv/3.md), which is declared to be not multi-thread-safe. This means that the code calling the functions described here must not call [**setenv**(3)](/setenv/3.md) from a parallel thread. It is recommended to only do calls to **setenv()** from an early phase of the program when no other threads have been started.

## HISTORY

**sd\_hwdb\_new()**, **sd\_hwdb\_ref()**, and **sd\_hwdb\_unref()** were added in version 246.

**sd\_hwdb\_new\_from\_path()** was added in version 252.

## SEE ALSO

[**systemd**(1)](/systemd/1.md), [**systemd-udevd.service**(8)](/systemd-udevd.service/8.md), [**sd-hwdb**(3)](/sd-hwdb/3.md), [**systemd-hwdb**(8)](/systemd-hwdb/8.md)
