---
name: "tdb_open"
section: "3"
platform: "linux"
package: "libtdb-dev"
version: "2:1.4.13+samba4.22.11+dfsg-0+deb13u1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/tdb_open"
---

# tdb\_open(3)

Open a tdb database.

## NAME

tdb\_open - Open a tdb database.

## SYNOPSIS

```
#include <tdb.h>

TDB_CONTEXT *tdb_open(const char *pathname, int hash_size,
        int tdb_flags, int open_flags, mode_t mode );

```

## DESCRIPTION

Open the database, creating it if necessary. The *hash* size is advisory, use zero for a default value. *tdb\_flags* can be one of

- **TDB\_CLEAR\_IF\_FIRST**

  Clear database if we are the only one with it open.

- **TDB\_INTERNAL**

  Don't use a file, instead store the data in memory. The *pathname* , *open\_flags* , and *mode* are ignored in this case. This is useful if you need a quick associative array or map.

- **TDB\_NOLOCK**

  Don't do any locking (this is always turned on for read-only file descriptors)

- **TDB\_NOMMAP**

  Don't use mmap.

- **TDB\_CONVERT**

  Create a database in the reverse of native endian: normally when the database is created (or cleared with TDB\_CLEAR\_IF\_FIRST), it is created in native endian order.  This flag is set (or unset) automatically for existing databases.

The *open\_flags* and *mode* are passed straight to the open call on the database file. A flags value of O\_WRONLY is invalid.

## RETURN VALUE

On success a pointer to an opaque data structure, a TDB\_CONTEXT is returned. On error a NULL is returned.

## AUTHORS

Software: Andrew Tridgell \<tridge@linuxcare.com\> and Luke Kenneth Casson Leighton Man page: Ben Woodard \<ben@valinux.com\>

## SEE ALSO

[**open**(2)](/open/2.md), [**gdbm**(3)](/gdbm/3.md), **[tdb(3)](/tdb/3.md)**
