---
name: "mansearch"
section: "3"
platform: "linux"
package: "libmandoc-dev"
version: "1.14.6-4"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/mansearch"
---

# mansearch(3)

search manual page databases

## NAME

**mansearch** – search manual page databases

## SYNOPSIS

**#include \<stdint.h\>**

**#include \<manconf.h\>**

**#include \<mansearch.h\>**

*int*\

**mansearch**(*const struct mansearch \*search*, *const struct manpaths \*paths*, *int argc*, *char \*argv\[\]*, *struct manpage \*\*res*, *size\_t \*sz*);

## DESCRIPTION

The **mansearch**() function returns information about manuals matching a search query from a [mandoc.db(5)](/mandoc.db/5.md) database.

The query arguments are as follows:

- *const struct mansearch \*search*

  Search options, defined in ⟨mansearch.h⟩.

- *const struct manpaths \*paths*

  Directories to be searched, defined in ⟨manconf.h⟩.

- *int argc*, *char \*argv\[\]*,

  Search criteria, usually taken from the command line.

The output arguments are as follows:

- *struct manpage \*\*res*

  Returns a pointer to an array of result structures defined in ⟨mansearch.h⟩. The user is expected to call [free(3)](/free/3.md) on the *file*, *names*, and *output* fields of all structures, as well as the *res* array itself.

- *size\_t \*sz*

  Returns the number of result structures contained in *res*.

## IMPLEMENTATION NOTES

For each manual page tree, the search is done in two steps. In the first step, a list of pages matching the search criteria is built. In the second step, the requested information about these pages is retrieved from the database and assembled into the *res* array.

All function mentioned here are defined in the file *mansearch.c*.

### Finding matches

Command line parsing is done by the function **exprcomp**() building a singly linked list of *expr* structures, using the helper functions **expr\_and**() and **exprterm**().

### Assembling the results

The names, sections, and architectures of the manuals found are assembled into the *names* field of the result structure by the function **buildnames**().

## FILES

- *mandoc.db*

  The manual page database.

## SEE ALSO

[apropos(1)](/apropos/1.md), [mandoc.db(5)](/mandoc.db/5.md), [makewhatis(8)](/makewhatis/8.md)

## HISTORY

The **mansearch**() subsystem first appeared in OpenBSD 5.6.

## AUTHORS

A module to search manual page databases was first written by Kristaps Dzonsons ⟨*kristaps@bsd.lv*⟩ in 2011, at first using the Berkeley DB; he rewrote it for SQLite3 in 2012, and Ingo Schwarze ⟨*schwarze@openbsd.org*⟩ removed the dependency on SQLite3 in 2016.
