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

« back to all changes in this revision

Viewing changes to shlibs/mount/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 <unistd.h>
17
 
#include <string.h>
18
 
#include <stdio.h>
19
 
#include <ctype.h>
20
 
 
21
 
#include "mountP.h"
22
 
 
23
 
static const char *lib_version = LIBMOUNT_VERSION;
24
 
 
25
 
/**
26
 
 * mnt_parse_version_string:
27
 
 * @ver_string: version string (e.g "2.18.0")
28
 
 *
29
 
 * Returns: release version code.
30
 
 */
31
 
int mnt_parse_version_string(const char *ver_string)
32
 
{
33
 
        const char *cp;
34
 
        int version = 0;
35
 
 
36
 
        for (cp = ver_string; *cp; cp++) {
37
 
                if (*cp == '.')
38
 
                        continue;
39
 
                if (!isdigit(*cp))
40
 
                        break;
41
 
                version = (version * 10) + (*cp - '0');
42
 
        }
43
 
        return version;
44
 
}
45
 
 
46
 
/**
47
 
 * mnt_get_library_version:
48
 
 * @ver_string: return pointer to the static library version string
49
 
 *
50
 
 * Returns: release version number.
51
 
 */
52
 
int mnt_get_library_version(const char **ver_string)
53
 
{
54
 
        if (ver_string)
55
 
                *ver_string = lib_version;
56
 
 
57
 
        return mnt_parse_version_string(lib_version);
58
 
}
59
 
 
60
 
#ifdef TEST_PROGRAM
61
 
int test_version(struct libmnt_test *ts, int argc, char *argv[])
62
 
{
63
 
        const char *ver;
64
 
 
65
 
        mnt_get_library_version(&ver);
66
 
 
67
 
        printf("Library version: %s\n", ver);
68
 
        printf("Library API version: " LIBMOUNT_VERSION "\n");
69
 
 
70
 
        if (mnt_get_library_version(NULL) ==
71
 
                        mnt_parse_version_string(LIBMOUNT_VERSION))
72
 
                return 0;
73
 
 
74
 
        return -1;
75
 
}
76
 
 
77
 
int main(int argc, char *argv[])
78
 
{
79
 
        struct libmnt_test ts[] = {
80
 
                { "--print", test_version, "print versions" },
81
 
                { NULL }
82
 
        };
83
 
 
84
 
        return mnt_run_test(ts, argc, argv);
85
 
}
86
 
#endif