Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to check run-time version of the library #637

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ NULL =
AM_CPPFLAGS = \
-I$(top_srcdir) \
-I$(top_srcdir)/common \
-I$(top_builddir) \
-I$(top_builddir)/common \
-DBINDIR=\"$(bindir)\" \
-DBUILDDIR=\"$(abs_builddir)\" \
Expand Down
16 changes: 14 additions & 2 deletions p11-kit/test-version.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include "test.h"

static void
test_check (void)
test_check_compile_time (void)
{
#if !P11_KIT_CHECK_VERSION (P11_KIT_VERSION_MAJOR, P11_KIT_VERSION_MINOR, P11_KIT_VERSION_MICRO)
assert_not_reached ();
Expand All @@ -66,13 +66,25 @@ test_check (void)
#endif
}

static void
test_check_run_time (void)
{
assert_num_eq (1, p11_kit_check_version (P11_KIT_VERSION_MAJOR, P11_KIT_VERSION_MINOR, P11_KIT_VERSION_MICRO));
assert_num_eq (1, p11_kit_check_version (P11_KIT_VERSION_MAJOR, P11_KIT_VERSION_MINOR, 0));
assert_num_eq (1, p11_kit_check_version (P11_KIT_VERSION_MAJOR, 0, 0));
assert_num_eq (0, p11_kit_check_version (P11_KIT_VERSION_MAJOR + 1, P11_KIT_VERSION_MINOR, P11_KIT_VERSION_MICRO));
assert_num_eq (0, p11_kit_check_version (P11_KIT_VERSION_MAJOR, P11_KIT_VERSION_MINOR + 1, P11_KIT_VERSION_MICRO));
assert_num_eq (0, p11_kit_check_version (P11_KIT_VERSION_MAJOR, P11_KIT_VERSION_MINOR, P11_KIT_VERSION_MICRO + 1));
}

int
main (int argc,
char *argv[])
{
p11_library_init ();

p11_test (test_check, "/version/test_check");
p11_test (test_check_compile_time, "/version/test_check_compile_time");
p11_test (test_check_run_time, "/version/test_check_run_time");

return p11_test_run (argc, argv);
}
19 changes: 19 additions & 0 deletions p11-kit/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "message.h"
#include "p11-kit.h"
#include "private.h"
#include <p11-kit/version.h>

#include <assert.h>
#include <stdarg.h>
Expand Down Expand Up @@ -236,3 +237,21 @@ _p11_get_progname_unlocked (void)
return NULL;
return p11_my_progname;
}

/**
* p11_kit_check_version:
* @major: major version
* @minor: minor version
* @micro: micro version
*
* Check if the run-time version of p11-kit meets the requirement
* given by a triple: @major, @minor, and @micro.
*
* Returns: 1 if the version requirement meets; 0 otherwise.
* Since: 0.25.4
*/
int
p11_kit_check_version (int major, int minor, int micro)
{
return P11_KIT_CHECK_VERSION (major, minor, micro);
}
2 changes: 2 additions & 0 deletions p11-kit/version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ extern "C" {
P11_KIT_VERSION_MINOR == (minor) && \
P11_KIT_VERSION_MICRO >= (micro)))

int p11_kit_check_version (int major, int minor, int micro);

#ifdef __cplusplus
} /* extern "C" */
#endif
Expand Down
Loading