Functions to handle version numbers / version strings.
More...
#include "versionutils.h"
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <glib.h>
#include <string.h>
Go to the source code of this file.
|
static gchar * | prepare_version_string (const char *version) |
| Prepare the version string for comparison.
|
|
static int | get_release_state (const char *version, int index) |
| Gets the release state of a specified part of the version string if any.
|
|
static char * | get_part (const char *version, int index) |
| Gets the part of the version string that is specified by index.
|
|
static gboolean | is_text (const char *part) |
| Checks if a given part of the version string is plain text.
|
|
static char * | str_cpy (char *source, int size) |
| Copy size characters of a string to an newly allocated new string.
|
|
int | cmp_versions (const char *version1, const char *version2) |
| Compare two version strings representing a software version to decide which version is newer.
|
|
Functions to handle version numbers / version strings.
Up to now this library provides a function to compare two version numbers / two version strings to decide which version is the newer one.
◆ G_LOG_DOMAIN
#define G_LOG_DOMAIN "libgvm util" |
◆ cmp_versions()
int cmp_versions |
( |
const char * | version1, |
|
|
const char * | version2 ) |
Compare two version strings representing a software version to decide which version is newer.
- Parameters
-
[in] | version1 | The first version string to compare. |
[in] | version2 | The second version string to compare. |
- Returns
- Returns a value > 0 if version1 is newer than version2. Returns 0 if version1 is the same than version2. Returns a value between -1 and -4 if version2 is newer than version1. Returns -5 if the result is undefined.
◆ get_part()
static char * get_part |
( |
const char * | version, |
|
|
int | index ) |
|
static |
Gets the part of the version string that is specified by index.
- Parameters
-
[in] | version | The version string to get the part from. |
[in] | index | The part of the version string to return. |
- Returns
- Returns a copy of the specified part of the version string.
◆ get_release_state()
static int get_release_state |
( |
const char * | version, |
|
|
int | index ) |
|
static |
Gets the release state of a specified part of the version string if any.
- Parameters
-
[in] | version | The version string to get the release state from. |
[in] | index | The part of the version string to check. |
- Returns
- Returns 0 if there is no release state, returns 4 if the release state is "development" (dev), returns 3 if the state is "alpha", 2 if the state is beta and 1 if the state is release candidate (rc).
◆ is_text()
static gboolean is_text |
( |
const char * | part | ) |
|
|
static |
Checks if a given part of the version string is plain text.
- Parameters
-
[in] | part | The part of the version string to check. |
- Returns
- Returns TRUE if part contains only plain text, FALSE otherwise.
◆ prepare_version_string()
static gchar * prepare_version_string |
( |
const char * | version | ) |
|
|
static |
Prepare the version string for comparison.
- Parameters
-
[in] | version | The version string to generate the prepared version string from. |
- Returns
- Returns a prepared copy of the version string version.
◆ str_cpy()
static char * str_cpy |
( |
char * | source, |
|
|
int | size ) |
|
static |
Copy size characters of a string to an newly allocated new string.
- Parameters
-
[in] | src | The string the first size characters are to be copied from. |
[in] | size | The number of characters to copy. |
- Returns
- The copy of the first size characters of src as a new string.