summaryrefslogtreecommitdiffstats
path: root/libblkid/src/version.c
blob: ed92db960cf5e075c52dfe64a3af9a8781f1d8ad (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * version.c --- Return the version of the blkid library
 *
 * Copyright (C) 2004 Theodore Ts'o.
 *
 * %Begin-Header%
 * This file may be redistributed under the terms of the GNU Lesser General
 * Public License.
 * %End-Header%
 */

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <string.h>
#include <stdio.h>
#include <ctype.h>

#include "blkid.h"

/* LIBBLKID_* defined in the global config.h */
static const char *lib_version = LIBBLKID_VERSION;	/* release version */
static const char *lib_date = LIBBLKID_DATE;

/**
 * blkid_parse_version_string:
 * @ver_string:  version string (e.g. "2.16.0")
 *
 * Returns: release version code.
 */
int blkid_parse_version_string(const char *ver_string)
{
	const char *cp;
	int version = 0;

	for (cp = ver_string; *cp; cp++) {
		if (*cp == '.')
			continue;
		if (!isdigit(*cp))
			break;
		version = (version * 10) + (*cp - '0');
	}
	return version;
}

/**
 * blkid_get_library_version:
 * @ver_string: returns release version (!= SONAME version)
 * @date_string: returns date
 *
 * Returns: release version code.
 */
int blkid_get_library_version(const char **ver_string,
			       const char **date_string)
{
	if (ver_string)
		*ver_string = lib_version;
	if (date_string)
		*date_string = lib_date;

	return blkid_parse_version_string(lib_version);
}