---
name: "mdb_compat"
section: "3"
platform: "linux"
package: "lmdb-doc"
version: "0.9.31-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/mdb_compat"
---

# mdb\_compat(3)

Compatibility Macros

## NAME

compat - Compatibility Macros

## SYNOPSIS

### Macros

\#define **MDB\_DEVEL**   0\
 \#define **mdb\_func\_**   '\<mdb\_unknown\>'\
 \#define **MDB\_NO\_ROOT**   (**MDB\_LAST\_ERRCODE** + 10)\
 \#define **MDB\_USE\_ROBUST**   1\
 \#define **THREAD\_RET**   void \*\
 \#define **THREAD\_CREATE**(thr,  start,  arg)   pthread\_create(&thr,NULL,start,arg)\
 \#define **THREAD\_FINISH**(thr)   pthread\_join(thr,NULL)\
 \#define **Z**   'z'\
 \#define **MDB\_PIDLOCK**   1\
 \#define **LOCK\_MUTEX0**(mutex)   pthread\_mutex\_lock(mutex)\
 \#define **UNLOCK\_MUTEX**(mutex)   pthread\_mutex\_unlock(mutex)\
 \#define **mdb\_mutex\_consistent**(mutex)   pthread\_mutex\_consistent(mutex)\
 \#define **ErrCode**()   errno\
 \#define **HANDLE**   int\
 \#define **INVALID\_HANDLE\_VALUE**   (-1)\
 \#define **GET\_PAGESIZE**(x)   ((x) = sysconf(\_SC\_PAGE\_SIZE))\
 \#define **MNAME\_LEN**   (sizeof(pthread\_mutex\_t))\

### Typedefs

typedef pthread\_mutex\_t **mdb\_mutex\_t**\[1\]\
 typedef pthread\_mutex\_t \* **mdb\_mutexref\_t**\

## Detailed Description

A bunch of macros to minimize the amount of platform-specific ifdefs needed throughout the rest of the code. When the features this library needs are similar enough to POSIX to be hidden in a one-or-two line replacement, this macro approach is used.

## Macro Definition Documentation

### #define MDB\_DEVEL 0

Features under development

### #define mdb\_func\_ '\<mdb\_unknown\>'

Wrapper around **func**, which is a C99 feature

### #define MDB\_USE\_ROBUST 1

Some platforms define the EOWNERDEAD error code even though they don't support Robust Mutexes. Compile with -DMDB\_USE\_ROBUST=0, or use some other mechanism like -DMDB\_USE\_POSIX\_SEM instead of -DMDB\_USE\_POSIX\_MUTEX. (Posix semaphores are not robust.)

### #define Z 'z'

printf format modifier for size\_t

### #define MDB\_PIDLOCK 1

For MDB\_LOCK\_FORMAT: True if readers take a pid lock in the lockfile

### #define LOCK\_MUTEX0(mutex) pthread\_mutex\_lock(mutex)

Lock the reader or writer mutex. Returns 0 or a code to give mdb\_mutex\_failed(), as in LOCK\_MUTEX().

### #define UNLOCK\_MUTEX(mutex) pthread\_mutex\_unlock(mutex)

Unlock the reader or writer mutex.

### #define mdb\_mutex\_consistent(mutex) pthread\_mutex\_consistent(mutex)

Mark mutex-protected data as repaired, after death of previous owner.

### #define ErrCode() errno

Get the error code for the last failed system function.

### #define HANDLE int

An abstraction for a file handle. On POSIX systems file handles are small integers. On Windows they're opaque pointers.

### #define INVALID\_HANDLE\_VALUE (-1)

A value for an invalid file handle. Mainly used to initialize file variables and signify that they are unused.

### #define GET\_PAGESIZE(x) ((x) = sysconf(\_SC\_PAGE\_SIZE))

Get the size of a memory page for the system. This is the basic size that the platform's memory manager uses, and is fundamental to the use of memory-mapped files.

## Typedef Documentation

### typedef pthread\_mutex\_t mdb\_mutex\_t\[1\]

Shared mutex/semaphore as the original is stored.

Not for copies. Instead it can be assigned to an **mdb\_mutexref\_t**. When mdb\_mutexref\_t is a pointer and mdb\_mutex\_t is not, then it is array\[size 1\] so it can be assigned to the pointer.

### typedef pthread\_mutex\_t\* mdb\_mutexref\_t

Reference to an **mdb\_mutex\_t**

## Author

Generated automatically by Doxygen for LMDB from the source code.
