2 GLIB - Library of useful routines for C programming
4 Copyright (C) 2009-2015
5 Free Software Foundation, Inc.
8 Slava Zanko <slavazanko@gmail.com>, 2009, 2013.
10 This file is part of the Midnight Commander.
12 The Midnight Commander is free software: you can redistribute it
13 and/or modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation, either version 3 of the License,
15 or (at your option) any later version.
17 The Midnight Commander is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 /** \file glibcompat.c
27 * \brief Source: compatibility with older versions of glib
29 * Following code was copied from glib to GNU Midnight Commander to
30 * provide compatibility with older versions of glib.
37 #include "glibcompat.h"
39 /*** global variables ****************************************************************************/
41 /*** file scope macro definitions ****************************************************************/
43 /*** file scope type declarations ****************************************************************/
45 /*** file scope variables ************************************************************************/
47 /*** file scope functions ************************************************************************/
49 /*** public functions ****************************************************************************/
50 /* --------------------------------------------------------------------------------------------- */
52 #if ! GLIB_CHECK_VERSION (2, 16, 0)
55 * @str1: (allow-none): a C string or %NULL
56 * @str2: (allow-none): another C string or %NULL
58 * Compares @str1 and @str2 like strcmp(). Handles %NULL
59 * gracefully by sorting it before non-%NULL strings.
60 * Comparing two %NULL pointers returns 0.
62 * Returns: an integer less than, equal to, or greater than zero, if @str1 is <, == or > than @str2.
67 g_strcmp0 (const char *str1
, const char *str2
)
70 return -(str1
!= str2
);
73 return strcmp (str1
, str2
);
75 #endif /* ! GLIB_CHECK_VERSION (2, 16, 0) */
77 /* --------------------------------------------------------------------------------------------- */
79 #if ! GLIB_CHECK_VERSION (2, 28, 0)
82 * @list: a pointer to a #GSList
83 * @free_func: the function to be called to free each element's data
85 * Convenience method, which frees all the memory used by a #GSList, and
86 * calls the specified destroy function on every element's data.
91 g_slist_free_full (GSList
* list
, GDestroyNotify free_func
)
93 g_slist_foreach (list
, (GFunc
) free_func
, NULL
);
97 /* --------------------------------------------------------------------------------------------- */
101 * @list: a pointer to a #GList
102 * @free_func: the function to be called to free each element's data
104 * Convenience method, which frees all the memory used by a #GList, and
105 * calls the specified destroy function on every element's data.
110 g_list_free_full (GList
* list
, GDestroyNotify free_func
)
112 g_list_foreach (list
, (GFunc
) free_func
, NULL
);
116 #endif /* ! GLIB_CHECK_VERSION (2, 28, 0) */
118 /* --------------------------------------------------------------------------------------------- */
119 #if ! GLIB_CHECK_VERSION (2, 22, 0)
121 * Creates a new GError with the given domain and code, and a message formatted with format.
122 * @param domain error domain
123 * @param code error code
124 * @param format printf()-style format for error message
125 * @param args va_list of parameters for the message format
126 * @returns a new GError
130 g_error_new_valist (GQuark domain
, gint code
, const gchar
* format
, va_list args
)
135 message
= g_strdup_vprintf (format
, args
);
137 ret_value
= g_error_new_literal (domain
, code
, message
);
143 #endif /* ! GLIB_CHECK_VERSION (2, 22, 0) */
145 /* --------------------------------------------------------------------------------------------- */