root/lib/glibcompat.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. g_slist_free_full
  2. g_list_free_full
  3. g_clear_slist
  4. g_clear_list
  5. g_queue_free_full
  6. g_queue_clear_full

   1 /*
   2    GLIB - Library of useful routines for C programming
   3 
   4    Copyright (C) 2009-2019
   5    Free Software Foundation, Inc.
   6 
   7    Written by:
   8    Slava Zanko <slavazanko@gmail.com>, 2009, 2013.
   9 
  10    This file is part of the Midnight Commander.
  11 
  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.
  16 
  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.
  21 
  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/>.
  24  */
  25 
  26 /** \file glibcompat.c
  27  *  \brief Source: compatibility with older versions of glib
  28  *
  29  *  Following code was copied from glib to GNU Midnight Commander to
  30  *  provide compatibility with older versions of glib.
  31  */
  32 
  33 #include <config.h>
  34 #include <string.h>
  35 
  36 #include "global.h"
  37 #include "glibcompat.h"
  38 
  39 /*** global variables ****************************************************************************/
  40 
  41 /*** file scope macro definitions ****************************************************************/
  42 
  43 /*** file scope type declarations ****************************************************************/
  44 
  45 /*** file scope variables ************************************************************************/
  46 
  47 /*** file scope functions ************************************************************************/
  48 
  49 /* --------------------------------------------------------------------------------------------- */
  50 /*** public functions ****************************************************************************/
  51 /* --------------------------------------------------------------------------------------------- */
  52 
  53 #if ! GLIB_CHECK_VERSION (2, 28, 0)
  54 /**
  55  * g_slist_free_full:
  56  * @list: a pointer to a #GSList
  57  * @free_func: the function to be called to free each element's data
  58  *
  59  * Convenience method, which frees all the memory used by a #GSList, and
  60  * calls the specified destroy function on every element's data.
  61  *
  62  * Since: 2.28
  63  **/
  64 void
  65 g_slist_free_full (GSList * list, GDestroyNotify free_func)
     /* [previous][next][first][last][top][bottom][index][help]  */
  66 {
  67     g_slist_foreach (list, (GFunc) free_func, NULL);
  68     g_slist_free (list);
  69 }
  70 
  71 /* --------------------------------------------------------------------------------------------- */
  72 
  73 /**
  74  * g_list_free_full:
  75  * @list: a pointer to a #GList
  76  * @free_func: the function to be called to free each element's data
  77  *
  78  * Convenience method, which frees all the memory used by a #GList, and
  79  * calls the specified destroy function on every element's data.
  80  *
  81  * Since: 2.28
  82  */
  83 void
  84 g_list_free_full (GList * list, GDestroyNotify free_func)
     /* [previous][next][first][last][top][bottom][index][help]  */
  85 {
  86     g_list_foreach (list, (GFunc) free_func, NULL);
  87     g_list_free (list);
  88 }
  89 
  90 /* --------------------------------------------------------------------------------------------- */
  91 
  92 #endif /* ! GLIB_CHECK_VERSION (2, 28, 0) */
  93 
  94 #if ! GLIB_CHECK_VERSION (2, 64, 0)
  95 /**
  96  * g_clear_slist: (skip)
  97  * @slist_ptr: (not nullable): a #GSList return location
  98  * @destroy: (nullable): the function to pass to g_slist_free_full() or NULL to not free elements
  99  *
 100  * Clears a pointer to a #GSList, freeing it and, optionally, freeing its elements using @destroy.
 101  *
 102  * @slist_ptr must be a valid pointer. If @slist_ptr points to a null #GSList, this does nothing.
 103  *
 104  * Since: 2.64
 105  */
 106 void
 107 g_clear_slist (GSList ** slist_ptr, GDestroyNotify destroy)
     /* [previous][next][first][last][top][bottom][index][help]  */
 108 {
 109     GSList *slist;
 110 
 111     slist = *slist_ptr;
 112 
 113     if (slist != NULL)
 114     {
 115         *slist_ptr = NULL;
 116 
 117         if (destroy != NULL)
 118             g_slist_free_full (slist, destroy);
 119         else
 120             g_slist_free (slist);
 121     }
 122 }
 123 
 124 /* --------------------------------------------------------------------------------------------- */
 125 
 126 /**
 127  * g_clear_list:
 128  * @list_ptr: (not nullable): a #GList return location
 129  * @destroy: (nullable): the function to pass to g_list_free_full() or NULL to not free elements
 130  *
 131  * Clears a pointer to a #GList, freeing it and, optionally, freeing its elements using @destroy.
 132  *
 133  * @list_ptr must be a valid pointer. If @list_ptr points to a null #GList, this does nothing.
 134  *
 135  * Since: 2.64
 136  */
 137 void
 138 g_clear_list (GList ** list_ptr, GDestroyNotify destroy)
     /* [previous][next][first][last][top][bottom][index][help]  */
 139 {
 140     GList *list;
 141 
 142     list = *list_ptr;
 143 
 144     if (list != NULL)
 145     {
 146         *list_ptr = NULL;
 147 
 148         if (destroy != NULL)
 149             g_list_free_full (list, destroy);
 150         else
 151             g_list_free (list);
 152     }
 153 }
 154 
 155 /* --------------------------------------------------------------------------------------------- */
 156 
 157 #endif /* ! GLIB_CHECK_VERSION (2, 64, 0) */
 158 
 159 #if ! GLIB_CHECK_VERSION (2, 32, 0)
 160 /**
 161  * g_queue_free_full:
 162  * @queue: a pointer to a #GQueue
 163  * @free_func: the function to be called to free each element's data
 164  *
 165  * Convenience method, which frees all the memory used by a #GQueue,
 166  * and calls the specified destroy function on every element's data.
 167  *
 168  * Since: 2.32
 169  */
 170 void
 171 g_queue_free_full (GQueue * queue, GDestroyNotify free_func)
     /* [previous][next][first][last][top][bottom][index][help]  */
 172 {
 173     g_queue_foreach (queue, (GFunc) free_func, NULL);
 174     g_queue_free (queue);
 175 }
 176 #endif /* ! GLIB_CHECK_VERSION (2, 32, 0) */
 177 
 178 /* --------------------------------------------------------------------------------------------- */
 179 
 180 #if ! GLIB_CHECK_VERSION (2, 60, 0)
 181 /**
 182  * g_queue_clear_full:
 183  * @queue: a pointer to a #GQueue
 184  * @free_func: (nullable): the function to be called to free memory allocated
 185  *
 186  * Convenience method, which frees all the memory used by a #GQueue,
 187  * and calls the provided @free_func on each item in the #GQueue.
 188  *
 189  * Since: 2.60
 190  */
 191 void
 192 g_queue_clear_full (GQueue * queue, GDestroyNotify free_func)
     /* [previous][next][first][last][top][bottom][index][help]  */
 193 {
 194     g_return_if_fail (queue != NULL);
 195 
 196     if (free_func != NULL)
 197         g_queue_foreach (queue, (GFunc) free_func, NULL);
 198 
 199     g_queue_clear (queue);
 200 }
 201 #endif /* ! GLIB_CHECK_VERSION (2, 60, 0) */
 202 
 203 /* --------------------------------------------------------------------------------------------- */

/* [previous][next][first][last][top][bottom][index][help]  */