1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1998 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
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/>.
19 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GLib Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GLib at ftp://ftp.gtk.org/pub/gtk/.
31 * @Title: Version Information
32 * @Short_description: variables and functions to check the GLib version
34 * GLib provides version information, primarily useful in configure
35 * checks for builds that have a configure script. Applications will
36 * not typically use the features described here.
38 * The GLib headers annotate deprecated APIs in a way that produces
39 * compiler warnings if these deprecated APIs are used. The warnings
40 * can be turned off by defining the macro %GLIB_DISABLE_DEPRECATION_WARNINGS
41 * before including the glib.h header.
43 * GLib also provides support for building applications against
44 * defined subsets of deprecated or new GLib APIs. Define the macro
45 * %GLIB_VERSION_MIN_REQUIRED to specify up to what version of GLib
46 * you want to receive warnings about deprecated APIs. Define the
47 * macro %GLIB_VERSION_MAX_ALLOWED to specify the newest version of
48 * GLib whose API you want to use.
54 * The major version number of the GLib library.
56 * Like #glib_major_version, but from the headers used at
57 * application compile time, rather than from the library
58 * linked against at application run time.
64 * The minor version number of the GLib library.
66 * Like #gtk_minor_version, but from the headers used at
67 * application compile time, rather than from the library
68 * linked against at application run time.
74 * The micro version number of the GLib library.
76 * Like #gtk_micro_version, but from the headers used at
77 * application compile time, rather than from the library
78 * linked against at application run time.
83 * @major: the major version to check for
84 * @minor: the minor version to check for
85 * @micro: the micro version to check for
87 * Checks the version of the GLib library that is being compiled
91 * <title>Checking the version of the GLib library</title>
93 * if (!GLIB_CHECK_VERSION (1, 2, 0))
94 * g_error ("GLib version 1.2.0 or above is needed");
98 * See glib_check_version() for a runtime check.
100 * Returns: %TRUE if the version of the GLib header files
101 * is the same as or newer than the passed-in version.
104 const guint glib_major_version = GLIB_MAJOR_VERSION;
105 const guint glib_minor_version = GLIB_MINOR_VERSION;
106 const guint glib_micro_version = GLIB_MICRO_VERSION;
107 const guint glib_interface_age = GLIB_INTERFACE_AGE;
108 const guint glib_binary_age = GLIB_BINARY_AGE;
111 * glib_check_version:
112 * @required_major: the required major version.
113 * @required_minor: the required minor version.
114 * @required_micro: the required micro version.
116 * Checks that the GLib library in use is compatible with the
117 * given version. Generally you would pass in the constants
118 * #GLIB_MAJOR_VERSION, #GLIB_MINOR_VERSION, #GLIB_MICRO_VERSION
119 * as the three arguments to this function; that produces
120 * a check that the library in use is compatible with
121 * the version of GLib the application or module was compiled
124 * Compatibility is defined by two things: first the version
125 * of the running library is newer than the version
126 * @required_major.required_minor.@required_micro. Second
127 * the running library must be binary compatible with the
128 * version @required_major.required_minor.@required_micro
129 * (same major version.)
131 * Return value: %NULL if the GLib library is compatible with the
132 * given version, or a string describing the version mismatch.
133 * The returned string is owned by GLib and must not be modified
139 glib_check_version (guint required_major,
140 guint required_minor,
141 guint required_micro)
143 gint glib_effective_micro = 100 * GLIB_MINOR_VERSION + GLIB_MICRO_VERSION;
144 gint required_effective_micro = 100 * required_minor + required_micro;
146 if (required_major > GLIB_MAJOR_VERSION)
147 return "GLib version too old (major mismatch)";
148 if (required_major < GLIB_MAJOR_VERSION)
149 return "GLib version too new (major mismatch)";
150 if (required_effective_micro < glib_effective_micro - GLIB_BINARY_AGE)
151 return "GLib version too new (micro mismatch)";
152 if (required_effective_micro > glib_effective_micro)
153 return "GLib version too old (micro mismatch)";