regex: Remove obsolete patch
[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, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GLib Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
25  */
26
27 #include "config.h"
28
29 #include "gversion.h"
30
31 /**
32  * SECTION:version
33  * @Title: Version Information
34  * @Short_description: variables and functions to check the GLib version
35  *
36  * GLib provides version information, primarily useful in configure
37  * checks for builds that have a configure script. Applications will
38  * not typically use the features described here.
39  */
40
41 /**
42  * GLIB_MAJOR_VERSION:
43  *
44  * The major version number of the GLib library.
45  *
46  * Like #glib_major_version, but from the headers used at
47  * application compile time, rather than from the library
48  * linked against at application run time.
49  */
50
51 /**
52  * GLIB_MINOR_VERSION:
53  *
54  * The minor version number of the GLib library.
55  *
56  * Like #gtk_minor_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_MICRO_VERSION:
63  *
64  * The micro version number of the GLib library.
65  *
66  * Like #gtk_micro_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_CHECK_VERSION:
73  * @major: the major version to check for
74  * @minor: the minor version to check for
75  * @micro: the micro version to check for
76  *
77  * Checks the version of the GLib library that is being compiled
78  * against.
79  *
80  * <example>
81  * <title>Checking the version of the GLib library</title>
82  * <programlisting>
83  *   if (!GLIB_CHECK_VERSION (1, 2, 0))
84  *     g_error ("GLib version 1.2.0 or above is needed");
85  * </programlisting>
86  * </example>
87  *
88  * 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  * Return value: %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 }