dmi_version_format_ex
Synopsis
#include <opendmi/utils/version.h>
char *dmi_version_format_ex(
dmi_version_t version,
dmi_version_level_t level);
Description
The dmi_version_format_ex function formats an SMBIOS version number as a
human-readable, dynamically allocated string. The level parameter controls
how many components are included in the output:
DMI_VERSION_LEVEL_MAJOR-
Format as "major" (e.g., "3").
DMI_VERSION_LEVEL_MINOR-
Format as "major.minor" (e.g., "3.4").
DMI_VERSION_LEVEL_REVISION-
Format as "major.minor.revision" (e.g., "3.4.1").
The caller is responsible for freeing the returned string.
Parameters
version-
SMBIOS version number constructed with
dmi_versionor theDMI_VERSIONmacro. level-
Detail level that determines how many version components are included in the formatted string.
Return value
On success, returns a newly allocated null-terminated string containing the
formatted version. On failure (e.g., allocation error or invalid level),
returns nullptr.
Errors
DMI_ERROR_ARGUMENT_INVALID-
Raised if
levelis not a detail level. The function takes no context, so the error reaches no error queue.
Examples
dmi_version_t ver = dmi_version(3, 4, 1);
char *full = dmi_version_format_ex(ver, DMI_VERSION_LEVEL_REVISION);
if (full != nullptr) {
printf("Full version: %s\n", full); // "3.4.1"
free(full);
}
char *short_ver = dmi_version_format_ex(ver, DMI_VERSION_LEVEL_MAJOR);
if (short_ver != nullptr) {
printf("Major only: %s\n", short_ver); // "3"
free(short_ver);
}