root/lib/glibcompat.c

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

DEFINITIONS

This source file includes following definitions.
  1. g_clear_slist
  2. g_clear_list
  3. g_queue_free_full
  4. g_queue_clear_full

   1 /*
   2    GLIB - Library of useful routines for C programming
   3 
   4    Copyright (C) 2009-2020
   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, 63, 3)
  54 /**
  55  * g_clear_slist: (skip)
  56  * @slist_ptr: (not nullable): a #GSList return location
  57  * @destroy: (nullable): the function to pass to g_slist_free_full() or NULL to not free elements
  58  *
  59  * Clears a pointer to a #GSList, freeing it and, optionally, freeing its elements using @destroy.
  60  *
  61  * @slist_ptr must be a valid pointer. If @slist_ptr points to a null #GSList, this does nothing.
  62  *
  63  * Since: 2.64
  64  */
  65 void
  66 g_clear_slist (GSList ** slist_ptr, GDestroyNotify destroy)
     /* [previous][next][first][last][top][bottom][index][help]  */
  67 {
  68     GSList *slist;
  69 
  70     slist = *slist_ptr;
  71 
  72     if (slist != NULL)
  73     {
  74         *slist_ptr = NULL;
  75 
  76         if (destroy != NULL)
  77             g_slist_free_full (slist, destroy);
  78         else
  79             g_slist_free (slist);
  80     }
  81 }
  82 
  83 /* --------------------------------------------------------------------------------------------- */
  84 
  85 /**
  86  * g_clear_list:
  87  * @list_ptr: (not nullable): a #GList return location
  88  * @destroy: (nullable): the function to pass to g_list_free_full() or NULL to not free elements
  89  *
  90  * Clears a pointer to a #GList, freeing it and, optionally, freeing its elements using @destroy.
  91  *
  92  * @list_ptr must be a valid pointer. If @list_ptr points to a null #GList, this does nothing.
  93  *
  94  * Since: 2.64
  95  */
  96 void
  97 g_clear_list (GList ** list_ptr, GDestroyNotify destroy)
     /* [previous][next][first][last][top][bottom][index][help]  */
  98 {
  99     GList *list;
 100 
 101     list = *list_ptr;
 102 
 103     if (list != NULL)
 104     {
 105         *list_ptr = NULL;
 106 
 107         if (destroy != NULL)
 108             g_list_free_full (list, destroy);
 109         else
 110             g_list_free (list);
 111     }
 112 }
 113 
 114 /* --------------------------------------------------------------------------------------------- */
 115 
 116 #endif /* ! GLIB_CHECK_VERSION (2, 63, 3) */
 117 
 118 #if ! GLIB_CHECK_VERSION (2, 32, 0)
 119 /**
 120  * g_queue_free_full:
 121  * @queue: a pointer to a #GQueue
 122  * @free_func: the function to be called to free each element's data
 123  *
 124  * Convenience method, which frees all the memory used by a #GQueue,
 125  * and calls the specified destroy function on every element's data.
 126  *
 127  * Since: 2.32
 128  */
 129 void
 130 g_queue_free_full (GQueue * queue, GDestroyNotify free_func)
     /* [previous][next][first][last][top][bottom][index][help]  */
 131 {
 132     g_queue_foreach (queue, (GFunc) free_func, NULL);
 133     g_queue_free (queue);
 134 }
 135 #endif /* ! GLIB_CHECK_VERSION (2, 32, 0) */
 136 
 137 /* --------------------------------------------------------------------------------------------- */
 138 
 139 #if ! GLIB_CHECK_VERSION (2, 60, 0)
 140 /**
 141  * g_queue_clear_full:
 142  * @queue: a pointer to a #GQueue
 143  * @free_func: (nullable): the function to be called to free memory allocated
 144  *
 145  * Convenience method, which frees all the memory used by a #GQueue,
 146  * and calls the provided @free_func on each item in the #GQueue.
 147  *
 148  * Since: 2.60
 149  */
 150 void
 151 g_queue_clear_full (GQueue * queue, GDestroyNotify free_func)
     /* [previous][next][first][last][top][bottom][index][help]  */
 152 {
 153     g_return_if_fail (queue != NULL);
 154 
 155     if (free_func != NULL)
 156         g_queue_foreach (queue, (GFunc) free_func, NULL);
 157 
 158     g_queue_clear (queue);
 159 }
 160 #endif /* ! GLIB_CHECK_VERSION (2, 60, 0) */
 161 
 162 /* --------------------------------------------------------------------------------------------- */

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