summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSimon Josefsson <simon@josefsson.org>2006-11-07 11:19:16 +0000
committerSimon Josefsson <simon@josefsson.org>2006-11-07 11:19:16 +0000
commit32890471444a0c11bf5ee5c3ead80418d08058f4 (patch)
tree50666df0dbb291d44c21f93e52be7db44d35358c /lib
parentae1bb92d5d01347733e4f9e4d06c5bc7c53fcbc7 (diff)
downloadgnutls-32890471444a0c11bf5ee5c3ead80418d08058f4.tar.gz
Use strverscmp.
Diffstat (limited to 'lib')
-rw-r--r--lib/gnutls_global.c73
1 files changed, 10 insertions, 63 deletions
diff --git a/lib/gnutls_global.c b/lib/gnutls_global.c
index c2f05d7ee0..dc1aa419e6 100644
--- a/lib/gnutls_global.c
+++ b/lib/gnutls_global.c
@@ -381,44 +381,7 @@ gnutls_transport_set_push_function (gnutls_session_t session,
session->internals._gnutls_push_func = push_func;
}
-
-/* Taken from libgcrypt. Needed to configure scripts.
- */
-
-static const char *
-parse_version_number (const char *s, int *number)
-{
- int val = 0;
-
- if (*s == '0' && isdigit (s[1]))
- return NULL; /* leading zeros are not allowed */
- for (; isdigit (*s); s++)
- {
- val *= 10;
- val += *s - '0';
- }
- *number = val;
- return val < 0 ? NULL : s;
-}
-
-/* The parse version functions were copied from libgcrypt.
- */
-static const char *
-parse_version_string (const char *s, int *major, int *minor, int *micro)
-{
- s = parse_version_number (s, major);
- if (!s || *s != '.')
- return NULL;
- s++;
- s = parse_version_number (s, minor);
- if (!s || *s != '.')
- return NULL;
- s++;
- s = parse_version_number (s, micro);
- if (!s)
- return NULL;
- return s; /* patchlevel */
-}
+#include <strverscmp.h>
/**
* gnutls_check_version - This function checks the library's version
@@ -429,34 +392,18 @@ parse_version_string (const char *s, int *major, int *minor, int *micro)
* satisfied. If a NULL is passed to this function, no check is done,
* but the version string is simply returned.
*
+ * See %LIBGNUTLS_VERSION for a suitable @req_version string.
+ *
+ * Return value: Version string of run-time library, or NULL if the
+ * run-time library does not meet the required version number. If
+ * %NULL is passed to this function no check is done and only the
+ * version string is returned.
**/
const char *
gnutls_check_version (const char *req_version)
{
- const char *ver = VERSION;
- int my_major, my_minor, my_micro;
- int rq_major, rq_minor, rq_micro;
- const char *my_plvl, *rq_plvl;
-
- if (!req_version)
- return ver;
-
- my_plvl = parse_version_string (ver, &my_major, &my_minor, &my_micro);
- if (!my_plvl)
- return NULL; /* very strange our own version is bogus */
- rq_plvl = parse_version_string (req_version, &rq_major, &rq_minor,
- &rq_micro);
- if (!rq_plvl)
- return NULL; /* req version string is invalid */
-
- if (my_major > rq_major
- || (my_major == rq_major && my_minor > rq_minor)
- || (my_major == rq_major && my_minor == rq_minor
- && my_micro > rq_micro)
- || (my_major == rq_major && my_minor == rq_minor
- && my_micro == rq_micro && strcmp (my_plvl, rq_plvl) >= 0))
- {
- return ver;
- }
+ if (!req_version || strverscmp (req_version, VERSION) <= 0)
+ return VERSION;
+
return NULL;
}