---
name: "genders_testattrval"
section: "3"
platform: "linux"
package: "libgenders0-dev"
version: "1.27-3-3.1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/genders_testattr"
---

# genders\_testattrval(3)

test if a node has an attribute

Part of [genders\_testattr(3)](/genders_testattr/3.md).

## NAME

genders\_testattr - test if a node has an attribute

## SYNOPSIS

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

**int genders\_testattr(genders\_t handle, const char \*node, const char \*attr, char \*val, int len);**

**int genders\_testattrval(genders\_t handle, const char \*node, const char \*attr, const char \*val);**\

## DESCRIPTION

**genders\_testattr()** tests if the node pointed to by *node* contains the attribute pointed to by *attr*.  If *node* is NULL, the current node is tested.  If the attribute is found, its value is stored in the buffer pointed to by *val*.  *len* should indicate the length of the buffer.  If the attribute value is not needed, *val* can be set to NULL.

To avoid passing in an attribute value buffer that is not large enough to store the attribute value, [**genders\_getmaxvallen**(3)](/genders_getmaxvallen/3.md) should be used to determine the minimum buffer size that should be used.

**genders\_testattrval()** tests if the node pointed to by *node* contains the attribute pointed to by *attr* and if that attribute is equal to the attribute value pointed to by *val*.  If *val* is NULL, only the attribute is tested.\

## RETURN VALUES

For **genders\_testattr()**, if the node contains the attribute, 1 is returned.  0 is returned if the node does not contain the attribute.

For **genders\_testattrval()**, if the node contains the attribute and it is equal to the attribute value, 1 is returned.  0 is returned if the node does not contain the attribute, or if the attribute is not equal to the attribute value.

For both **genders\_testattr()** and **genders\_testattrval()**, -1 is returned on error, and an error code is returned in *handle*. The error code can be retrieved via [**genders\_errnum**(3)](/genders_errnum/3.md) , and a description of the error code can be retrieved via  [**genders\_strerror**(3)](/genders_strerror/3.md). Error codes are defined in genders.h.\

## ERRORS

- **GENDERS\_ERR\_NULLHANDLE**

  The *handle* parameter is NULL.  The genders handle must be created with [**genders\_handle\_create**(3)](/genders_handle_create/3.md).

- **GENDERS\_ERR\_NOTLOADED**

  [**genders\_load\_data**(3)](/genders_load_data/3.md) has not been called to load genders data.

- **GENDERS\_ERR\_OVERFLOW**

  The buffer pointed to by *val* is not large enough to store the attribute value.

- **GENDERS\_ERR\_PARAMETERS**

  An incorrect parameter has been passed in.

- **GENDERS\_ERR\_NOTFOUND**

  The node pointed to by *node* cannot be found in the genders file or if *node*=NULL, the machine genders is running on is not listed in the genders database.

- **GENDERS\_ERR\_MAGIC**

  *handle* has an incorrect magic number.  *handle* does not point to a genders handle or *handle* has been destroyed by [**genders\_handle\_destroy**(3)](/genders_handle_destroy/3.md).\

## FILES

/usr/include/genders.h

## SEE ALSO

[libgenders(3)](/libgenders/3.md), [genders\_handle\_create(3)](/genders_handle_create/3.md), [genders\_load\_data(3)](/genders_load_data/3.md), [genders\_getmaxvallen(3)](/genders_getmaxvallen/3.md), [genders\_errnum(3)](/genders_errnum/3.md), [genders\_strerror(3)](/genders_strerror/3.md)
