Debian Version API

The wpkg libdebpackages library includes an API to handle Debian versions. This API is written to work in C or C++ programs or any other language that supports C or C++ binding.

struct debian_version_t;
typedef struct debian_version_t    *debian_version_handle_t;

int validate_debian_version(
	const char *string,
	char *error_string,
	size_t error_size);

debian_version_handle_t string_to_debian_version(
	const char *string,
	char *error_string,
	size_t error_size);

int debian_version_to_string(
	const debian_version_handle_t debian_version,
	char *string,
	size_t string_size);

int debian_versions_compare(
	const debian_version_handle_t left,
	const debian_version_handle_t right);

void delete_debian_version(
	debian_version_handle_t debian_version);

Use the string_to_debian_version() to transform a string to a debian_version_handle_t pointer that you can then use to compare or canonicalize a version.

Once done with that handle, call the delete_debian_version() to delete it.

The validate_debian_version() can be used to check out a version without having to convert it in a Debian version handle.

Validation Example:

char err[256];
validate_debian_version("1.3", err, sizeof(err));

Comparison Example:

char err[256];
debian_version_handle_t *v1;
debian_version_handle_t *v2;
int r;

v1 = string_to_debian_version(vers1, err, sizeof(err));
v2 = string_to_debian_version(vers2, err, sizeof(err));
r = debian_versions_compare(v1, v2);
if(r == 0) // v1 == v2
if(r < 0) // v1 < v2
if(r > 0) // v1 > v2

Canonicalization Example:

char err[256];
debian_version_handle_t *v;
char out[256];

v = string_to_debian_version(vers, err, sizeof(err));
debian_version_to_string(v, out, sizeof(out));

Note that the debian_version_to_string() function ensures that out is always null terminated. If the size of the output buffer is at least as long as the input version string it should always fit.