LCOV - code coverage report
Current view: top level - glib/glib - gversion.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 11 12 91.7 %
Date: 2024-04-23 05:16:05 Functions: 1 1 100.0 %
Branches: 7 8 87.5 %

           Branch data     Line data    Source code
       1                 :            : /* GLIB - Library of useful routines for C programming
       2                 :            :  * Copyright (C) 1995-1998  Peter Mattis, Spencer Kimball and Josh MacDonald
       3                 :            :  *
       4                 :            :  * SPDX-License-Identifier: LGPL-2.1-or-later
       5                 :            :  *
       6                 :            :  * This library is free software; you can redistribute it and/or
       7                 :            :  * modify it under the terms of the GNU Lesser General Public
       8                 :            :  * License as published by the Free Software Foundation; either
       9                 :            :  * version 2.1 of the License, or (at your option) any later version.
      10                 :            :  *
      11                 :            :  * This library is distributed in the hope that it will be useful,
      12                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14                 :            :  * Lesser General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU Lesser General Public
      17                 :            :  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
      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                 :            :  * glib_major_version:
      33                 :            :  *
      34                 :            :  * The major version of the GLib library.
      35                 :            :  *
      36                 :            :  * An integer variable exported from the library linked
      37                 :            :  * against at application run time.
      38                 :            :  */
      39                 :            : 
      40                 :            : /**
      41                 :            :  * GLIB_MAJOR_VERSION:
      42                 :            :  *
      43                 :            :  * The major version number of the GLib library.
      44                 :            :  *
      45                 :            :  * Like #glib_major_version, but from the headers used at
      46                 :            :  * application compile time, rather than from the library
      47                 :            :  * linked against at application run time.
      48                 :            :  */
      49                 :            : 
      50                 :            : /**
      51                 :            :  * glib_minor_version:
      52                 :            :  *
      53                 :            :  * The minor version number of the GLib library.
      54                 :            :  *
      55                 :            :  * An integer variable exported from the library linked
      56                 :            :  * against at application run time.
      57                 :            :  */
      58                 :            : 
      59                 :            : /**
      60                 :            :  * GLIB_MINOR_VERSION:
      61                 :            :  *
      62                 :            :  * The minor version number of the GLib library.
      63                 :            :  *
      64                 :            :  * Like #gtk_minor_version, but from the headers used at
      65                 :            :  * application compile time, rather than from the library
      66                 :            :  * linked against at application run time.
      67                 :            :  */
      68                 :            : 
      69                 :            : /**
      70                 :            :  * glib_micro_version:
      71                 :            :  *
      72                 :            :  * The micro version number of the GLib library.
      73                 :            :  *
      74                 :            :  * An integer variable exported from the library linked
      75                 :            :  * against at application run time.
      76                 :            :  */
      77                 :            : 
      78                 :            : /**
      79                 :            :  * GLIB_MICRO_VERSION:
      80                 :            :  *
      81                 :            :  * The micro version number of the GLib library.
      82                 :            :  *
      83                 :            :  * Like #gtk_micro_version, but from the headers used at
      84                 :            :  * application compile time, rather than from the library
      85                 :            :  * linked against at application run time.
      86                 :            :  */
      87                 :            : 
      88                 :            : /**
      89                 :            :  * GLIB_CHECK_VERSION:
      90                 :            :  * @major: the major version to check for
      91                 :            :  * @minor: the minor version to check for
      92                 :            :  * @micro: the micro version to check for
      93                 :            :  *
      94                 :            :  * Checks whether the version of the GLib library that is being compiled
      95                 :            :  * against is greater than or equal to the given one.
      96                 :            :  *
      97                 :            :  * See glib_check_version() for a runtime check.
      98                 :            :  *
      99                 :            :  * Returns: %TRUE if the version of the GLib header files
     100                 :            :  * is the same as or newer than the passed-in version.
     101                 :            :  */
     102                 :            : 
     103                 :            : /**
     104                 :            :  * glib_binary_age:
     105                 :            :  *
     106                 :            :  * The binary age of the GLib library.
     107                 :            :  * Defines how far back backwards compatibility reaches.
     108                 :            :  *
     109                 :            :  * An integer variable exported from the library linked
     110                 :            :  * against at application run time.
     111                 :            :  */
     112                 :            : 
     113                 :            : /**
     114                 :            :  * glib_interface_age:
     115                 :            :  *
     116                 :            :  * The interface age of the GLib library.
     117                 :            :  * Defines how far back the API has last been extended.
     118                 :            :  *
     119                 :            :  * An integer variable exported from the library linked
     120                 :            :  * against at application run time.
     121                 :            :  */
     122                 :            : 
     123                 :            : const guint glib_major_version = GLIB_MAJOR_VERSION;
     124                 :            : const guint glib_minor_version = GLIB_MINOR_VERSION;
     125                 :            : const guint glib_micro_version = GLIB_MICRO_VERSION;
     126                 :            : const guint glib_interface_age = GLIB_INTERFACE_AGE;
     127                 :            : const guint glib_binary_age = GLIB_BINARY_AGE;
     128                 :            : 
     129                 :            : /**
     130                 :            :  * glib_check_version:
     131                 :            :  * @required_major: the required major version
     132                 :            :  * @required_minor: the required minor version
     133                 :            :  * @required_micro: the required micro version
     134                 :            :  *
     135                 :            :  * Checks that the GLib library in use is compatible with the
     136                 :            :  * given version.
     137                 :            :  *
     138                 :            :  * Generally you would pass in the constants %GLIB_MAJOR_VERSION,
     139                 :            :  * %GLIB_MINOR_VERSION, %GLIB_MICRO_VERSION as the three arguments
     140                 :            :  * to this function; that produces a check that the library in use
     141                 :            :  * is compatible with the version of GLib the application or module
     142                 :            :  * was compiled against.
     143                 :            :  *
     144                 :            :  * Compatibility is defined by two things: first the version
     145                 :            :  * of the running library is newer than the version
     146                 :            :  * `@required_major.required_minor.@required_micro`. Second
     147                 :            :  * the running library must be binary compatible with the
     148                 :            :  * version `@required_major.@required_minor.@required_micro`
     149                 :            :  * (same major version.)
     150                 :            :  *
     151                 :            :  * Returns: (transfer none) (nullable): %NULL if the GLib library is
     152                 :            :  *   compatible with the given version, or a string describing the
     153                 :            :  *   version mismatch. The returned string is owned by GLib and must
     154                 :            :  *   not be modified or freed.
     155                 :            :  *
     156                 :            :  * Since: 2.6
     157                 :            :  */
     158                 :            : const gchar *
     159                 :         30 : glib_check_version (guint required_major,
     160                 :            :                     guint required_minor,
     161                 :            :                     guint required_micro)
     162                 :            : {
     163                 :         30 :   gint glib_effective_micro = 100 * GLIB_MINOR_VERSION + GLIB_MICRO_VERSION;
     164                 :         30 :   gint required_effective_micro = 100 * required_minor + required_micro;
     165                 :            : 
     166         [ +  + ]:         30 :   if (required_major > GLIB_MAJOR_VERSION)
     167                 :          5 :     return "GLib version too old (major mismatch)";
     168         [ +  + ]:         25 :   if (required_major < GLIB_MAJOR_VERSION)
     169                 :          5 :     return "GLib version too new (major mismatch)";
     170         [ -  + ]:         20 :   if (required_effective_micro < glib_effective_micro - GLIB_BINARY_AGE)
     171                 :          0 :     return "GLib version too new (micro mismatch)";
     172         [ +  + ]:         20 :   if (required_effective_micro > glib_effective_micro)
     173                 :         10 :     return "GLib version too old (micro mismatch)";
     174                 :         10 :   return NULL;
     175                 :            : }

Generated by: LCOV version 1.14