1 /* version.c - Version checking
2 * Copyright (C) 2001, 2002, 2012, 2013, 2014 g10 Code GmbH
4 * This file is part of libgpg-error.
6 * libgpg-error is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
11 * libgpg-error is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, see <http://www.gnu.org/licenses/>.
28 #include <gpg-error.h>
31 #define digitp(a) ((a) >= '0' && (a) <= '9')
34 /* This is actually a dummy function to make sure that is module is
35 not empty. Some compilers barf on empty modules. */
39 static const char blurb[] =
41 "This is Libgpg-error " PACKAGE_VERSION " - An error code library\n"
42 "Copyright 2003, 2004, 2010, 2013, 2014 g10 Code GmbH\n"
44 "(" BUILD_REVISION " " BUILD_TIMESTAMP ")\n"
51 parse_version_number (const char *s, int *number)
55 if (*s == '0' && digitp (s[1]))
56 return NULL; /* Leading zeros are not allowed. */
57 for (; digitp (*s); s++)
63 return val < 0 ? NULL : s;
68 parse_version_string (const char *s, int *major, int *minor)
70 s = parse_version_number (s, major);
74 s = parse_version_number (s, minor);
77 return s; /* Patchlevel. */
82 compare_versions (const char *my_version, const char *req_version)
84 int my_major, my_minor;
85 int rq_major, rq_minor;
86 const char *my_plvl, *rq_plvl;
93 my_plvl = parse_version_string (my_version, &my_major, &my_minor);
95 return NULL; /* Very strange: our own version is bogus. */
96 rq_plvl = parse_version_string(req_version, &rq_major, &rq_minor);
98 return NULL; /* Requested version string is invalid. */
100 if (my_major > rq_major
101 || (my_major == rq_major && my_minor >= rq_minor))
110 * Check that the the version of the library is at minimum REQ_VERSION
111 * and return the actual version string; return NULL if the condition
112 * is not met. If NULL is passed to this function, no check is done
113 * and the version string is simply returned.
116 gpg_error_check_version (const char *req_version)
118 if (req_version && req_version[0] == 1 && req_version[1] == 1)
119 return cright_blurb ();
120 return compare_versions (PACKAGE_VERSION, req_version);