summaryrefslogtreecommitdiffstats
path: root/libmount/src/version.c
diff options
context:
space:
mode:
authorKarel Zak2011-06-09 21:59:52 +0200
committerKarel Zak2011-06-09 21:59:52 +0200
commit2aefc0a8f267ddb57804755af9095d3cd5ceb0d7 (patch)
tree8601dca144fccbb9b6a895708868a520caccaddf /libmount/src/version.c
parentbuild-sys: use top-level directory for libuuid rather than shlibs/uuid (diff)
downloadkernel-qcow2-util-linux-2aefc0a8f267ddb57804755af9095d3cd5ceb0d7.tar.gz
kernel-qcow2-util-linux-2aefc0a8f267ddb57804755af9095d3cd5ceb0d7.tar.xz
kernel-qcow2-util-linux-2aefc0a8f267ddb57804755af9095d3cd5ceb0d7.zip
build-sys: use top-level directory for libmount rather than shlibs/mount
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/version.c')
-rw-r--r--libmount/src/version.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/libmount/src/version.c b/libmount/src/version.c
new file mode 100644
index 000000000..a3b6d0bcd
--- /dev/null
+++ b/libmount/src/version.c
@@ -0,0 +1,86 @@
+/*
+ * version.c - Return the version of the blkid library
+ *
+ * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
+ * [Based on libblkid/version.c by Theodore Ts'o]
+ *
+ * See COPYING.libmount for the License of this software.
+ */
+
+/**
+ * SECTION: version
+ * @title: Version functions
+ * @short_description: functions to get library version.
+ */
+
+#include <unistd.h>
+#include <string.h>
+#include <stdio.h>
+#include <ctype.h>
+
+#include "mountP.h"
+
+static const char *lib_version = LIBMOUNT_VERSION;
+
+/**
+ * mnt_parse_version_string:
+ * @ver_string: version string (e.g "2.18.0")
+ *
+ * Returns: release version code.
+ */
+int mnt_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;
+}
+
+/**
+ * mnt_get_library_version:
+ * @ver_string: return pointer to the static library version string
+ *
+ * Returns: release version number.
+ */
+int mnt_get_library_version(const char **ver_string)
+{
+ if (ver_string)
+ *ver_string = lib_version;
+
+ return mnt_parse_version_string(lib_version);
+}
+
+#ifdef TEST_PROGRAM
+int test_version(struct libmnt_test *ts, int argc, char *argv[])
+{
+ const char *ver;
+
+ mnt_get_library_version(&ver);
+
+ printf("Library version: %s\n", ver);
+ printf("Library API version: " LIBMOUNT_VERSION "\n");
+
+ if (mnt_get_library_version(NULL) ==
+ mnt_parse_version_string(LIBMOUNT_VERSION))
+ return 0;
+
+ return -1;
+}
+
+int main(int argc, char *argv[])
+{
+ struct libmnt_test ts[] = {
+ { "--print", test_version, "print versions" },
+ { NULL }
+ };
+
+ return mnt_run_test(ts, argc, argv);
+}
+#endif