glibcompat.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. GLIB - Library of useful routines for C programming
  3. Copyright (C) 2009-2019
  4. Free Software Foundation, Inc.
  5. Written by:
  6. Slava Zanko <slavazanko@gmail.com>, 2009, 2013.
  7. This file is part of the Midnight Commander.
  8. The Midnight Commander is free software: you can redistribute it
  9. and/or modify it under the terms of the GNU General Public License as
  10. published by the Free Software Foundation, either version 3 of the License,
  11. or (at your option) any later version.
  12. The Midnight Commander is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /** \file glibcompat.c
  20. * \brief Source: compatibility with older versions of glib
  21. *
  22. * Following code was copied from glib to GNU Midnight Commander to
  23. * provide compatibility with older versions of glib.
  24. */
  25. #include <config.h>
  26. #include <string.h>
  27. #include "global.h"
  28. #include "glibcompat.h"
  29. /*** global variables ****************************************************************************/
  30. /*** file scope macro definitions ****************************************************************/
  31. /*** file scope type declarations ****************************************************************/
  32. /*** file scope variables ************************************************************************/
  33. /*** file scope functions ************************************************************************/
  34. /* --------------------------------------------------------------------------------------------- */
  35. /*** public functions ****************************************************************************/
  36. /* --------------------------------------------------------------------------------------------- */
  37. #if ! GLIB_CHECK_VERSION (2, 28, 0)
  38. /**
  39. * g_slist_free_full:
  40. * @list: a pointer to a #GSList
  41. * @free_func: the function to be called to free each element's data
  42. *
  43. * Convenience method, which frees all the memory used by a #GSList, and
  44. * calls the specified destroy function on every element's data.
  45. *
  46. * Since: 2.28
  47. **/
  48. void
  49. g_slist_free_full (GSList * list, GDestroyNotify free_func)
  50. {
  51. g_slist_foreach (list, (GFunc) free_func, NULL);
  52. g_slist_free (list);
  53. }
  54. /* --------------------------------------------------------------------------------------------- */
  55. /**
  56. * g_list_free_full:
  57. * @list: a pointer to a #GList
  58. * @free_func: the function to be called to free each element's data
  59. *
  60. * Convenience method, which frees all the memory used by a #GList, and
  61. * calls the specified destroy function on every element's data.
  62. *
  63. * Since: 2.28
  64. */
  65. void
  66. g_list_free_full (GList * list, GDestroyNotify free_func)
  67. {
  68. g_list_foreach (list, (GFunc) free_func, NULL);
  69. g_list_free (list);
  70. }
  71. /* --------------------------------------------------------------------------------------------- */
  72. #endif /* ! GLIB_CHECK_VERSION (2, 28, 0) */
  73. #if ! GLIB_CHECK_VERSION (2, 32, 0)
  74. /**
  75. * g_queue_free_full:
  76. * @queue: a pointer to a #GQueue
  77. * @free_func: the function to be called to free each element's data
  78. *
  79. * Convenience method, which frees all the memory used by a #GQueue,
  80. * and calls the specified destroy function on every element's data.
  81. *
  82. * Since: 2.32
  83. */
  84. void
  85. g_queue_free_full (GQueue * queue, GDestroyNotify free_func)
  86. {
  87. g_queue_foreach (queue, (GFunc) free_func, NULL);
  88. g_queue_free (queue);
  89. }
  90. #endif /* ! GLIB_CHECK_VERSION (2, 32, 0) */
  91. /* --------------------------------------------------------------------------------------------- */
  92. #if ! GLIB_CHECK_VERSION (2, 60, 0)
  93. /**
  94. * g_queue_clear_full:
  95. * @queue: a pointer to a #GQueue
  96. * @free_func: (nullable): the function to be called to free memory allocated
  97. *
  98. * Convenience method, which frees all the memory used by a #GQueue,
  99. * and calls the provided @free_func on each item in the #GQueue.
  100. *
  101. * Since: 2.60
  102. */
  103. void
  104. g_queue_clear_full (GQueue * queue, GDestroyNotify free_func)
  105. {
  106. g_return_if_fail (queue != NULL);
  107. if (free_func != NULL)
  108. g_queue_foreach (queue, (GFunc) free_func, NULL);
  109. g_queue_clear (queue);
  110. }
  111. #endif /* ! GLIB_CHECK_VERSION (2, 60, 0) */
  112. /* --------------------------------------------------------------------------------------------- */