# <search.h> The <search.h> header file contains functions to manipulate binary search tables and manage hash search tables. > > > #include <search.h> > > > int hcreate(size\_t nel); [POSIX] > > > void hdestroy(void); [POSIX] > > > ENTRY \*hsearch(ENTRY item, ACTION action); [POSIX] > > > void tdelete(const void \* restrict key, void \*\* restrict rootp, > int (\*compar) (const void \*, const void \*)); [POSIX] > > > void \*tfind(const void \*key, const void \* const \*rootp, int > (\*compar) (const void \*, const void \*)); [POSIX] > > > void \*tsearch(const void \*key, void \*\*rootp, int (\*compar) (const > void \*, const void \*)); [POSIX] > > > void twalk(const void \*root, void (\*action) (const void \*, VISIT, > int)); [POSIX] ## hcreate > > > int hcreate(size\_t nel); [POSIX] The function allocates and initializes the hash search table. The nel argument specifies an estimate of the maximum number of entries to be held by the table. Unless further memory allocation fails, supplying an insufficient nel value will not result in functional harm, although a performance degradation may occur. Initialization using the hcreate function is mandatory prior to any access operations using > > > hsearch. If successful, hcreate returns a nonzero value. Otherwise, a value of 0 is returned and errno is set to indicate the error. ## hdestroy > > > void hdestroy(void); [POSIX] The function destroys a table previously created using hcreate. After a call to hdestroy, the data can no longer be accessed. > > > The hdestroy function returns no value. ## hsearch > > > ENTRY \*hsearch(ENTRY item, ACTION action); [POSIX] Use this function to search the hash table. It returns a pointer into the hash table indicating the address of an item. The item argument is of type ENTRY, a structural type which contains the following members: - char \*key – Comparison key - void \*data – Pointer to data associated with the key The key comparison function used by hsearch is strcmp The action argument is of type ACTION, an enumeration type which defines the following values: - ENTER – Insert item into the hash table. If an existing item with the same key is found, it is not replaced. The key and data elements of item are used directly by the new table entry. The storage for the key must not be modified during the lifetime of the hash table. - FIND – Search the hash table without inserting item. If successful, hsearch returns a pointer to the hash table entry matching the provided key. If the action is FIND and the item was not found, or if the action is ENTER and the insertion failed, NULL is returned and errno is set to indicate the error. If the action is ENTER and an entry already exists in the table matching the given key, the existing entry is returned and is not replaced. ## tdelete > > > void tdelete(const void \* restrict key, void \*\* restrict rootp, > int (\*compar) (const void \*, const void \*)); [POSIX] The function manages binary search trees based on algorithms T and D from Knuth (6.2.2). The comparison function passed in by the user has the same style of return values as strcmp. The tdelete function deletes a node from the specified binary search tree and returns a pointer to the parent of the node to be deleted. It takes the same arguments as tfind and tsearch. If the node to be deleted is the root of the binary search tree, rootp will be adjusted. > > > tdelete returns NULL if rootp is NULL or the datum cannot be found. ## tfind > > > void \*tfind(const void \*key, const void \* const \*rootp, int > (\*compar) (const void \*, const void \*)); [POSIX] The function manages binary search trees based on algorithms T and D from Knuth (6.2.2). The comparison function passed in by the user has the same style of return values as strcmp. The tfind function searches for the datum matched by the argument key in the binary tree rooted at rootp. It returns a pointer to the datum if it is found and NULL if it is not. It also returns NULL if rootp is NULL or the datum cannot be found. ## tsearch > > > void \*tsearch(const void \*key, void \*\*rootp, int (\*compar) (const > void \*, const void \*)); [POSIX] The function manages binary search trees based on algorithms T and D from Knuth (6.2.2). The comparison function passed in by the user has the same style of return values as strcmp. The tsearch function is identical to tfind except that if no match is found, key is inserted into the tree and a pointer to it is returned. If rootp points to a NULL value a new binary search tree is created. The function returns NULL if allocation of a new node fails (typically due to a lack of free memory). It also returns NULL if rootp is NULL or the datum cannot be found. ## twalk > > > void twalk(const void \*root, void (\*action) (const void \*, VISIT, > int)); [POSIX] The function manages binary search trees based on algorithms T and D from Knuth (6.2.2). The comparison function passed in by the user has the same style of return values as strcmp. The twalk function walks the binary search tree rooted in root and calls the function action on each node. Action is called with three arguments: - A pointer to the current node - A value from the typedef enum {preorder, postorder, endorder, leaf } VISIT; specifying the traversal type - A node level (where level zero is the root of the tree) The function has no return value. # <setjmp.h> Include the standard header <setjmp.h> to perform control transfers that bypass the normal function call and return protocol. > > > #define setjmp(jmp\_buf env) <int rvalue> > > > typedef a-type jmp\_buf; > > > void longjmp(jmp\_buf env, int val); jmp\_buf > > > typedef a-type jmp\_buf; The type is the array type a-type of an object that you declare to hold the context information stored by setjmp and accessed by longjmp. ## longjmp > > > void longjmp(jmp\_buf env, int val); The function causes a second return from the execution of setjmp that stored the current context value in env. If val is nonzero, the return value is val; otherwise, it is 1. The function that was active when setjmp stored the current context value must not have returned control to its caller. An object with dynamic duration that does not have a volatile type and whose stored value has changed since the current context value was stored will have a stored value that is indeterminate. ## setjmp > > > #define setjmp(jmp\_buf env) <int rvalue> The macro stores the current context value in the array designated by env and returns zero. A later call to longjmp that accesses the same context value causes setjmp to again return, this time with a nonzero value. You can use the macro setjmp only in an expression that: - Has no operators - Has only the unary operator, ! - Has one of the relational or equality operators (==, !=, <, <=, >, or >=) with the other operand an integer constant expression You can write such an expression only as the expression part of a do, expression, for, if, if-else, switch, or while statement. Last Published: Oct 06, 2026 [Previous Topic Posix APIs](https://docs.qualcomm.com/bundle/publicresource/80-N3040-23/topics/index_c_posix.md) Next Topic