~ubuntu-branches/ubuntu/trusty/util-linux/trusty-proposed

« back to all changes in this revision

Viewing changes to libmount/src/version.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2011-11-03 15:38:23 UTC
  • mto: (4.5.5 sid) (1.6.4)
  • mto: This revision was merged to the branch mainline in revision 85.
  • Revision ID: package-import@ubuntu.com-20111103153823-10sx16jprzxlhkqf
ImportĀ upstreamĀ versionĀ 2.20.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * version.c - Return the version of the blkid library
 
3
 *
 
4
 * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
 
5
 * [Based on libblkid/version.c by Theodore Ts'o]
 
6
 *
 
7
 * See COPYING.libmount for the License of this software.
 
8
 */
 
9
 
 
10
/**
 
11
 * SECTION: version
 
12
 * @title: Version functions
 
13
 * @short_description: functions to get library version.
 
14
 */
 
15
 
 
16
#include <ctype.h>
 
17
 
 
18
#include "mountP.h"
 
19
 
 
20
static const char *lib_version = LIBMOUNT_VERSION;
 
21
 
 
22
/**
 
23
 * mnt_parse_version_string:
 
24
 * @ver_string: version string (e.g "2.18.0")
 
25
 *
 
26
 * Returns: release version code.
 
27
 */
 
28
int mnt_parse_version_string(const char *ver_string)
 
29
{
 
30
        const char *cp;
 
31
        int version = 0;
 
32
 
 
33
        for (cp = ver_string; *cp; cp++) {
 
34
                if (*cp == '.')
 
35
                        continue;
 
36
                if (!isdigit(*cp))
 
37
                        break;
 
38
                version = (version * 10) + (*cp - '0');
 
39
        }
 
40
        return version;
 
41
}
 
42
 
 
43
/**
 
44
 * mnt_get_library_version:
 
45
 * @ver_string: return pointer to the static library version string
 
46
 *
 
47
 * Returns: release version number.
 
48
 */
 
49
int mnt_get_library_version(const char **ver_string)
 
50
{
 
51
        if (ver_string)
 
52
                *ver_string = lib_version;
 
53
 
 
54
        return mnt_parse_version_string(lib_version);
 
55
}
 
56
 
 
57
#ifdef TEST_PROGRAM
 
58
int test_version(struct libmnt_test *ts, int argc, char *argv[])
 
59
{
 
60
        const char *ver;
 
61
 
 
62
        mnt_get_library_version(&ver);
 
63
 
 
64
        printf("Library version: %s\n", ver);
 
65
        printf("Library API version: " LIBMOUNT_VERSION "\n");
 
66
 
 
67
        if (mnt_get_library_version(NULL) ==
 
68
                        mnt_parse_version_string(LIBMOUNT_VERSION))
 
69
                return 0;
 
70
 
 
71
        return -1;
 
72
}
 
73
 
 
74
int main(int argc, char *argv[])
 
75
{
 
76
        struct libmnt_test ts[] = {
 
77
                { "--print", test_version, "print versions" },
 
78
                { NULL }
 
79
        };
 
80
 
 
81
        return mnt_run_test(ts, argc, argv);
 
82
}
 
83
#endif