docs: use "Returns:" consistently
[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 number of the GLib library.
55  *
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.
59  */
60
61 /**
62  * GLIB_MINOR_VERSION:
63  *
64  * The minor version number of the GLib library.
65  *
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.
69  */
70
71 /**
72  * GLIB_MICRO_VERSION:
73  *
74  * The micro version number of the GLib library.
75  *
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.
79  */
80
81 /**
82  * GLIB_CHECK_VERSION:
83  * @major: the major version to check for
84  * @minor: the minor version to check for
85  * @micro: the micro version to check for
86  *
87  * Checks the version of the GLib library that is being compiled
88  * against. See glib_check_version() for a runtime check.
89  *
90  * Returns: %TRUE if the version of the GLib header files
91  * is the same as or newer than the passed-in version.
92  */
93
94 const guint glib_major_version = GLIB_MAJOR_VERSION;
95 const guint glib_minor_version = GLIB_MINOR_VERSION;
96 const guint glib_micro_version = GLIB_MICRO_VERSION;
97 const guint glib_interface_age = GLIB_INTERFACE_AGE;
98 const guint glib_binary_age = GLIB_BINARY_AGE;
99
100 /**
101  * glib_check_version:
102  * @required_major: the required major version
103  * @required_minor: the required minor version
104  * @required_micro: the required micro version
105  *
106  * Checks that the GLib library in use is compatible with the
107  * given version. Generally you would pass in the constants
108  * #GLIB_MAJOR_VERSION, #GLIB_MINOR_VERSION, #GLIB_MICRO_VERSION
109  * as the three arguments to this function; that produces
110  * a check that the library in use is compatible with
111  * the version of GLib the application or module was compiled
112  * against.
113  *
114  * Compatibility is defined by two things: first the version
115  * of the running library is newer than the version
116  * @required_major.required_minor.@required_micro. Second
117  * the running library must be binary compatible with the
118  * version @required_major.required_minor.@required_micro
119  * (same major version.)
120  *
121  * Returns: %NULL if the GLib library is compatible with the
122  *     given version, or a string describing the version mismatch.
123  *     The returned string is owned by GLib and must not be modified
124  *     or freed.
125  *
126  * Since: 2.6
127  */
128 const gchar *
129 glib_check_version (guint required_major,
130                     guint required_minor,
131                     guint required_micro)
132 {
133   gint glib_effective_micro = 100 * GLIB_MINOR_VERSION + GLIB_MICRO_VERSION;
134   gint required_effective_micro = 100 * required_minor + required_micro;
135
136   if (required_major > GLIB_MAJOR_VERSION)
137     return "GLib version too old (major mismatch)";
138   if (required_major < GLIB_MAJOR_VERSION)
139     return "GLib version too new (major mismatch)";
140   if (required_effective_micro < glib_effective_micro - GLIB_BINARY_AGE)
141     return "GLib version too new (micro mismatch)";
142   if (required_effective_micro > glib_effective_micro)
143     return "GLib version too old (micro mismatch)";
144   return NULL;
145 }