fu-common-version: fwupd Reference Manual

## fu-common-version fu-common-version |

## Functions

gint | fu_common_vercmp_full ()
gchar * | fu_common_version_from_uint64 ()
gchar * | fu_common_version_from_uint32 ()
gchar * | fu_common_version_from_uint16 ()
gchar * | fu_common_version_parse_from_format ()
gchar * | fu_common_version_ensure_semver ()
gchar * | fu_common_version_ensure_semver_full ()
FwupdVersionFormat | fu_common_version_guess_format ()
gboolean | fu_common_version_verify_format ()

## Description

## Functions

### fu_common_vercmp_full ()

    gint
    fu_common_vercmp_full (const gchar *version_a,
                           const gchar *version_b,
                           FwupdVersionFormat fmt);

Compares version numbers for sorting taking into account the version format if required.

#### Parameters

version_a | the semver release version, e.g. `1.2.3`. | [nullable]
version_b | the semver release version, e.g. `1.2.3.1`. | [nullable]
fmt | a version format, e.g. `FWUPD_VERSION_FORMAT_PLAIN` |

#### Returns

-1 if a < b, +1 if a > b, 0 if they are equal, and `G_MAXINT` on error

Since: 1.3.9

### fu_common_version_from_uint64 ()

    gchar *
    fu_common_version_from_uint64 (guint64 val,
                                   FwupdVersionFormat kind);

Returns a dotted decimal version string from a 64 bit number.

#### Parameters

val | a raw version number |
kind | version kind used for formatting, e.g. `FWUPD_VERSION_FORMAT_QUAD` |

#### Returns

a version number, e.g. `1.2.3.4`, or `NULL` if not supported

Since: 1.3.6

### fu_common_version_from_uint32 ()

    gchar *
    fu_common_version_from_uint32 (guint32 val,
                                   FwupdVersionFormat kind);

Returns a dotted decimal version string from a 32 bit number.

#### Parameters

val | a uint32le version number |
kind | version kind used for formatting, e.g. `FWUPD_VERSION_FORMAT_TRIPLET` |

#### Returns

a version number, e.g. `1.0.3`, or `NULL` if not supported

Since: 1.2.0

### fu_common_version_from_uint16 ()

    gchar *
    fu_common_version_from_uint16 (guint16 val,
                                   FwupdVersionFormat kind);

Returns a dotted decimal version string from a 16 bit number.

#### Parameters

val | a uint16le version number |
kind | version kind used for formatting, e.g. `FWUPD_VERSION_FORMAT_TRIPLET` |

#### Returns

a version number, e.g. `1.3`, or `NULL` if not supported

Since: 1.2.0

### fu_common_version_parse_from_format ()

    gchar *
    fu_common_version_parse_from_format (const gchar *version,
                                         FwupdVersionFormat fmt);

Returns a dotted decimal version string from a version string using `fmt` . The supported formats are:

- Dotted decimal, e.g. `1.2.3`

- Base 16, a hex number *with* a 0x prefix, e.g. `0x10203`

- Base 10, a string containing just [0-9], e.g. `66051`

- Date in YYYYMMDD format, e.g. `20150915`

Anything with a `.` or that doesn't match `[0-9]` or `0x[a-f,0-9]` is considered a string and returned without modification.

#### Parameters

version | a version number. | [nullable]
fmt | a version format, e.g. `FWUPD_VERSION_FORMAT_TRIPLET` |

#### Returns

a version number, e.g. `1.0.3`, or `NULL` on error

Since: 1.3.3

### fu_common_version_ensure_semver ()

    gchar *
    fu_common_version_ensure_semver (const gchar *version);

Builds a semver from the possibly crazy version number.

#### Parameters

version | a version number, e.g. `V1.2.3` . | [nullable]

#### Returns

a version number, e.g. `1.2.3`, or `NULL` if the version was not valid

Since: 1.2.9

### fu_common_version_ensure_semver_full ()

    gchar *
    fu_common_version_ensure_semver_full (const gchar *version,
                                          FwupdVersionFormat fmt);

Builds a semver from the possibly crazy version number. Depending on the `semver` value the string will be split and a string in the correct format will be returned.

#### Parameters

version | a version number, e.g. `V1.2.3` . | [nullable]
fmt | a version format, e.g. `FWUPD_VERSION_FORMAT_TRIPLET` |

#### Returns

a version number, e.g. `1.2.3`, or `NULL` if the version was not valid

Since: 1.7.6

### fu_common_version_guess_format ()

    FwupdVersionFormat
    fu_common_version_guess_format (const gchar *version);

Guesses the version format from the version number. This is only a heuristic and plugins and components should explicitly set the version format whenever possible.

If the version format cannot be guessed with any degree of accuracy, the `FWUPD_VERSION_FORMAT_UNKNOWN` constant is returned.

#### Parameters

version | a version number, e.g. `1.2.3`. | [nullable]

#### Returns

a version format, e.g. `FWUPD_VERSION_FORMAT_QUAD`

Since: 1.2.0

### fu_common_version_verify_format ()

    gboolean
    fu_common_version_verify_format (const gchar *version,
                                     FwupdVersionFormat fmt,
                                     GError **error);

Verifies if a version matches the input format.

#### Parameters

version | a string, e.g. `0x1234`. | [not nullable]
fmt | a version format |
error | optional return location for an error. | [nullable]

#### Returns

TRUE or FALSE

Since: 1.2.9