dmi_attribute_name

Synopsis

#include <opendmi/attribute.h>

const char *dmi_attribute_name(const dmi_attribute_t *attr, const char *owner);

Description

The dmi_attribute_name function returns the printable name of the attribute attr, e.g. Data bus width, translated to the locale set by dmi_set_locale if the library has a translation for it, and the .name the attribute is declared with otherwise, see DMI_ATTRIBUTE.

Translations are keyed by the code of the attribute, .code, and are looked up in the attribute table of the structure the attribute belongs to, named by owner, and then in the shared attribute table, which holds the names common to all structures, e.g. manufacturer. The name of the structure takes precedence, so that a common name may be overridden where it does not fit. An attribute with no code is never translated.

The string belongs to the attribute or to the translation, and must not be freed. A translated name is valid until the locale is changed by dmi_set_locale.

Parameters

attr

Attribute to name.

owner

Code of the structure the attribute belongs to, e.g. the code of its specification, dmi_entity_spec_t, or nullptr to look the name up in the shared table only.

Return value

Returns the printable name of the attribute, or nullptr if attr is nullptr, or if the attribute has neither a translation nor a .name.

Errors

DMI_ERROR_ARGUMENT_NULL

Raised if attr is nullptr. The function takes no context, so the error reaches no error queue.

Example

static dmi_attribute_walk_t print_member(void *context, const dmi_attribute_node_t *node)
{
    const dmi_entity_t *entity = context;

    puts(dmi_attribute_name(node->member, entity->spec->code));

    return DMI_ATTRIBUTE_WALK_SKIP;
}