1/* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18/*
19 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GTK+ Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
23 */
24
25#include "config.h"
26
27#include "gtkversion.h"
28
29/**
30 * gtk_get_major_version:
31 *
32 * Returns the major version number of the GTK library.
33 *
34 * For example, in GTK version 3.1.5 this is 3.
35 *
36 * This function is in the library, so it represents the GTK library
37 * your code is running against. Contrast with the %GTK_MAJOR_VERSION
38 * macro, which represents the major version of the GTK headers you
39 * have included when compiling your code.
40 *
41 * Returns: the major version number of the GTK library
42 */
43guint
44gtk_get_major_version (void)
45{
46 return GTK_MAJOR_VERSION;
47}
48
49/**
50 * gtk_get_minor_version:
51 *
52 * Returns the minor version number of the GTK library.
53 *
54 * For example, in GTK version 3.1.5 this is 1.
55 *
56 * This function is in the library, so it represents the GTK library
57 * your code is are running against. Contrast with the
58 * %GTK_MINOR_VERSION macro, which represents the minor version of the
59 * GTK headers you have included when compiling your code.
60 *
61 * Returns: the minor version number of the GTK library
62 */
63guint
64gtk_get_minor_version (void)
65{
66 return GTK_MINOR_VERSION;
67}
68
69/**
70 * gtk_get_micro_version:
71 *
72 * Returns the micro version number of the GTK library.
73 *
74 * For example, in GTK version 3.1.5 this is 5.
75 *
76 * This function is in the library, so it represents the GTK library
77 * your code is are running against. Contrast with the
78 * %GTK_MICRO_VERSION macro, which represents the micro version of the
79 * GTK headers you have included when compiling your code.
80 *
81 * Returns: the micro version number of the GTK library
82 */
83guint
84gtk_get_micro_version (void)
85{
86 return GTK_MICRO_VERSION;
87}
88
89/**
90 * gtk_get_binary_age:
91 *
92 * Returns the binary age as passed to `libtool`.
93 *
94 * If `libtool` means nothing to you, don't worry about it.
95 *
96 * Returns: the binary age of the GTK library
97 */
98guint
99gtk_get_binary_age (void)
100{
101 return GTK_BINARY_AGE;
102}
103
104/**
105 * gtk_get_interface_age:
106 *
107 * Returns the interface age as passed to `libtool`.
108 *
109 * If `libtool` means nothing to you, don't worry about it.
110 *
111 * Returns: the interface age of the GTK library
112 */
113guint
114gtk_get_interface_age (void)
115{
116 return GTK_INTERFACE_AGE;
117}
118
119/**
120 * gtk_check_version:
121 * @required_major: the required major version
122 * @required_minor: the required minor version
123 * @required_micro: the required micro version
124 *
125 * Checks that the GTK library in use is compatible with the
126 * given version.
127 *
128 * Generally you would pass in the constants %GTK_MAJOR_VERSION,
129 * %GTK_MINOR_VERSION, %GTK_MICRO_VERSION as the three arguments
130 * to this function; that produces a check that the library in
131 * use is compatible with the version of GTK the application or
132 * module was compiled against.
133 *
134 * Compatibility is defined by two things: first the version
135 * of the running library is newer than the version
136 * @required_major.required_minor.@required_micro. Second
137 * the running library must be binary compatible with the
138 * version @required_major.required_minor.@required_micro
139 * (same major version.)
140 *
141 * This function is primarily for GTK modules; the module
142 * can call this function to check that it wasn’t loaded
143 * into an incompatible version of GTK. However, such a
144 * check isn’t completely reliable, since the module may be
145 * linked against an old version of GTK and calling the
146 * old version of gtk_check_version(), but still get loaded
147 * into an application using a newer version of GTK.
148 *
149 * Returns: (nullable): %NULL if the GTK library is compatible with the
150 * given version, or a string describing the version mismatch.
151 * The returned string is owned by GTK and should not be modified
152 * or freed.
153 */
154const char *
155gtk_check_version (guint required_major,
156 guint required_minor,
157 guint required_micro)
158{
159 int gtk_effective_micro = 100 * GTK_MINOR_VERSION + GTK_MICRO_VERSION;
160 int required_effective_micro = 100 * required_minor + required_micro;
161
162 if (required_major > GTK_MAJOR_VERSION)
163 return "GTK version too old (major mismatch)";
164 if (required_major < GTK_MAJOR_VERSION)
165 return "GTK version too new (major mismatch)";
166 if (required_effective_micro < gtk_effective_micro - GTK_BINARY_AGE)
167 return "GTK version too new (micro mismatch)";
168 if (required_effective_micro > gtk_effective_micro)
169 return "GTK version too old (micro mismatch)";
170 return NULL;
171}
172

source code of gtk/gtk/gtkversion.c