[kdbus] sync with kdbus (kdbus.h - commit: 5ae1ecac44cb)
[platform/upstream/glib.git] / glib / gversion.c
1 /* GLIB - Library of useful routines for C programming
2  * Copyright (C) 1995-1998  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 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/. 
23  */
24
25 #include "config.h"
26
27 #include "gversion.h"
28
29 /**
30  * SECTION:version
31  * @Title: Version Information
32  * @Short_description: variables and functions to check the GLib version
33  *
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.
37  *
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.
42  *
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.
49  */
50
51 /**
52  * glib_major_version:
53  *
54  * The major version of the GLib library.
55  *
56  * An integer variable exported from the library linked
57  * against at application run time.
58  */
59
60 /**
61  * GLIB_MAJOR_VERSION:
62  *
63  * The major version number of the GLib library.
64  *
65  * Like #glib_major_version, but from the headers used at
66  * application compile time, rather than from the library
67  * linked against at application run time.
68  */
69
70 /**
71  * glib_minor_version:
72  *
73  * The minor version number of the GLib library.
74  *
75  * An integer variable exported from the library linked
76  * against at application run time.
77  */
78
79 /**
80  * GLIB_MINOR_VERSION:
81  *
82  * The minor version number of the GLib library.
83  *
84  * Like #gtk_minor_version, but from the headers used at
85  * application compile time, rather than from the library
86  * linked against at application run time.
87  */
88
89 /**
90  * glib_micro_version:
91  *
92  * The micro version number of the GLib library.
93  *
94  * An integer variable exported from the library linked
95  * against at application run time.
96  */
97
98 /**
99  * GLIB_MICRO_VERSION:
100  *
101  * The micro version number of the GLib library.
102  *
103  * Like #gtk_micro_version, but from the headers used at
104  * application compile time, rather than from the library
105  * linked against at application run time.
106  */
107
108 /**
109  * GLIB_CHECK_VERSION:
110  * @major: the major version to check for
111  * @minor: the minor version to check for
112  * @micro: the micro version to check for
113  *
114  * Checks the version of the GLib library that is being compiled
115  * against. See glib_check_version() for a runtime check.
116  *
117  * Returns: %TRUE if the version of the GLib header files
118  * is the same as or newer than the passed-in version.
119  */
120
121 /**
122  * glib_binary_age:
123  *
124  * The binary age of the GLib library.
125  * Defines how far back backwards compatibility reaches.
126  *
127  * An integer variable exported from the library linked
128  * against at application run time.
129  */
130
131 /**
132  * glib_interface_age:
133  *
134  * The interface age of the GLib library.
135  * Defines how far back the API has last been extended.
136  *
137  * An integer variable exported from the library linked
138  * against at application run time.
139  */
140
141 const guint glib_major_version = GLIB_MAJOR_VERSION;
142 const guint glib_minor_version = GLIB_MINOR_VERSION;
143 const guint glib_micro_version = GLIB_MICRO_VERSION;
144 const guint glib_interface_age = GLIB_INTERFACE_AGE;
145 const guint glib_binary_age = GLIB_BINARY_AGE;
146
147 /**
148  * glib_check_version:
149  * @required_major: the required major version
150  * @required_minor: the required minor version
151  * @required_micro: the required micro version
152  *
153  * Checks that the GLib library in use is compatible with the
154  * given version. Generally you would pass in the constants
155  * #GLIB_MAJOR_VERSION, #GLIB_MINOR_VERSION, #GLIB_MICRO_VERSION
156  * as the three arguments to this function; that produces
157  * a check that the library in use is compatible with
158  * the version of GLib the application or module was compiled
159  * against.
160  *
161  * Compatibility is defined by two things: first the version
162  * of the running library is newer than the version
163  * @required_major.required_minor.@required_micro. Second
164  * the running library must be binary compatible with the
165  * version @required_major.required_minor.@required_micro
166  * (same major version.)
167  *
168  * Returns: %NULL if the GLib library is compatible with the
169  *     given version, or a string describing the version mismatch.
170  *     The returned string is owned by GLib and must not be modified
171  *     or freed.
172  *
173  * Since: 2.6
174  */
175 const gchar *
176 glib_check_version (guint required_major,
177                     guint required_minor,
178                     guint required_micro)
179 {
180   gint glib_effective_micro = 100 * GLIB_MINOR_VERSION + GLIB_MICRO_VERSION;
181   gint required_effective_micro = 100 * required_minor + required_micro;
182
183   if (required_major > GLIB_MAJOR_VERSION)
184     return "GLib version too old (major mismatch)";
185   if (required_major < GLIB_MAJOR_VERSION)
186     return "GLib version too new (major mismatch)";
187   if (required_effective_micro < glib_effective_micro - GLIB_BINARY_AGE)
188     return "GLib version too new (micro mismatch)";
189   if (required_effective_micro > glib_effective_micro)
190     return "GLib version too old (micro mismatch)";
191   return NULL;
192 }