]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - libmount/src/version.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 * This file is part of libmount from util-linux project.
5 * Copyright (C) 2008-2018 Karel Zak <kzak@redhat.com>
7 * libmount is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation; either version 2.1 of the License, or
10 * (at your option) any later version.
14 * SECTION: version-utils
15 * @title: Version functions
16 * @short_description: functions to get the library version.
23 static const char *lib_version
= LIBMOUNT_VERSION
;
24 static const char *lib_features
[] = {
25 #ifdef HAVE_LIBSELINUX
31 #ifdef HAVE_BTRFS_SUPPORT
34 #ifdef USE_LIBMOUNT_SUPPORT_MTAB
37 #ifdef USE_LIBMOUNT_SUPPORT_NAMESPACES
41 "assert", /* libc assert.h stuff */
43 "debug", /* always enabled */
48 * mnt_parse_version_string:
49 * @ver_string: version string (e.g "2.18.0")
51 * Returns: release version code.
53 int mnt_parse_version_string(const char *ver_string
)
60 for (cp
= ver_string
; *cp
; cp
++) {
65 version
= (version
* 10) + (*cp
- '0');
71 * mnt_get_library_version:
72 * @ver_string: return pointer to the static library version string if not NULL
74 * Returns: release version number.
76 int mnt_get_library_version(const char **ver_string
)
79 *ver_string
= lib_version
;
81 return mnt_parse_version_string(lib_version
);
85 * mnt_get_library_features:
86 * @features: returns a pointer to the static array of strings, the array is
89 * Returns: number of items in the features array not including the last NULL,
90 * or less than zero in case of error
95 * const char **features;
97 * mnt_get_library_features(&features);
98 * while (features && *features)
99 * printf("%s\n", *features++);
104 int mnt_get_library_features(const char ***features
)
109 *features
= lib_features
;
110 return ARRAY_SIZE(lib_features
) - 1;
114 static int test_version(struct libmnt_test
*ts
, int argc
, char *argv
[])
117 const char **features
;
120 printf("Your version: %d\n",
121 mnt_parse_version_string(argv
[1]));
123 mnt_get_library_version(&ver
);
125 printf("Library version: %s\n", ver
);
126 printf("Library API version: " LIBMOUNT_VERSION
"\n");
127 printf("Library features:");
129 mnt_get_library_features(&features
);
130 while (features
&& *features
)
131 printf(" %s", *features
++);
135 if (mnt_get_library_version(NULL
) ==
136 mnt_parse_version_string(LIBMOUNT_VERSION
))
142 int main(int argc
, char *argv
[])
144 struct libmnt_test ts
[] = {
145 { "--print", test_version
, "print versions" },
149 return mnt_run_test(ts
, argc
, argv
);