Skip to content

Commit

Permalink
Add function to check run-time version of the library
Browse files Browse the repository at this point in the history
This adds p11_kit_check_version function, which can be used to check
the run-time version of p11-kit.

Signed-off-by: Daiki Ueno <[email protected]>
  • Loading branch information
ueno committed May 9, 2024
1 parent 652927d commit e4cf037
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
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

0 comments on commit e4cf037

Please sign in to comment.