Add runtime version checking functions
This patch adds two new exported functions: * `jansson_version_str` - Returns a human-readable version number * `jansson_version_cmp` - Returns an integer less than, equal to, or greater than zero if the runtime version of Jansson is found, respectively, to be less than, to match, or be greater than the provided major, minor, and micro.
This commit is contained in:
@@ -20,7 +20,8 @@ libjansson_la_SOURCES = \
|
||||
strconv.c \
|
||||
utf.c \
|
||||
utf.h \
|
||||
value.c
|
||||
value.c \
|
||||
version.c
|
||||
libjansson_la_LDFLAGS = \
|
||||
-no-undefined \
|
||||
-export-symbols-regex '^json_' \
|
||||
|
||||
@@ -72,4 +72,6 @@ EXPORTS
|
||||
json_vunpack_ex
|
||||
json_set_alloc_funcs
|
||||
json_get_alloc_funcs
|
||||
jansson_version_str
|
||||
jansson_version_cmp
|
||||
|
||||
|
||||
@@ -360,6 +360,11 @@ typedef void (*json_free_t)(void *);
|
||||
void json_set_alloc_funcs(json_malloc_t malloc_fn, json_free_t free_fn);
|
||||
void json_get_alloc_funcs(json_malloc_t *malloc_fn, json_free_t *free_fn);
|
||||
|
||||
/* runtime version checking */
|
||||
|
||||
const char *jansson_version_str(void);
|
||||
int jansson_version_cmp(int major, int minor, int micro);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
32
src/version.c
Normal file
32
src/version.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2019 Sean Bright <sean.bright@gmail.com>
|
||||
*
|
||||
* Jansson is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include "jansson.h"
|
||||
|
||||
const char *jansson_version_str(void)
|
||||
{
|
||||
return JANSSON_VERSION;
|
||||
}
|
||||
|
||||
int jansson_version_cmp(int major, int minor, int micro)
|
||||
{
|
||||
int diff;
|
||||
|
||||
if ((diff = JANSSON_MAJOR_VERSION - major)) {
|
||||
return diff;
|
||||
}
|
||||
|
||||
if ((diff = JANSSON_MINOR_VERSION - minor)) {
|
||||
return diff;
|
||||
}
|
||||
|
||||
return JANSSON_MICRO_VERSION - micro;
|
||||
}
|
||||
Reference in New Issue
Block a user