glibcompat.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. GLIB - Library of useful routines for C programming
  3. Copyright (C) 2009-2014
  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. /*** public functions ****************************************************************************/
  35. /* --------------------------------------------------------------------------------------------- */
  36. #if ! GLIB_CHECK_VERSION (2, 13, 0)
  37. /*
  38. This is incomplete copy of same glib-function.
  39. For older glib (less than 2.13) functional is enought.
  40. For full version of glib welcome to glib update.
  41. */
  42. gboolean
  43. g_unichar_iszerowidth (gunichar c)
  44. {
  45. if (G_UNLIKELY (c == 0x00AD))
  46. return FALSE;
  47. if (G_UNLIKELY ((c >= 0x1160 && c < 0x1200) || c == 0x200B))
  48. return TRUE;
  49. return FALSE;
  50. }
  51. #endif /* ! GLIB_CHECK_VERSION (2, 13, 0) */
  52. /* --------------------------------------------------------------------------------------------- */
  53. #if ! GLIB_CHECK_VERSION (2, 16, 0)
  54. /**
  55. * g_strcmp0:
  56. * @str1: (allow-none): a C string or %NULL
  57. * @str2: (allow-none): another C string or %NULL
  58. *
  59. * Compares @str1 and @str2 like strcmp(). Handles %NULL
  60. * gracefully by sorting it before non-%NULL strings.
  61. * Comparing two %NULL pointers returns 0.
  62. *
  63. * Returns: an integer less than, equal to, or greater than zero, if @str1 is <, == or > than @str2.
  64. *
  65. * Since: 2.16
  66. */
  67. int
  68. g_strcmp0 (const char *str1, const char *str2)
  69. {
  70. if (!str1)
  71. return -(str1 != str2);
  72. if (!str2)
  73. return str1 != str2;
  74. return strcmp (str1, str2);
  75. }
  76. #endif /* ! GLIB_CHECK_VERSION (2, 16, 0) */
  77. /* --------------------------------------------------------------------------------------------- */
  78. #if ! GLIB_CHECK_VERSION (2, 28, 0)
  79. /**
  80. * g_slist_free_full:
  81. * @list: a pointer to a #GSList
  82. * @free_func: the function to be called to free each element's data
  83. *
  84. * Convenience method, which frees all the memory used by a #GSList, and
  85. * calls the specified destroy function on every element's data.
  86. *
  87. * Since: 2.28
  88. **/
  89. void
  90. g_slist_free_full (GSList * list, GDestroyNotify free_func)
  91. {
  92. g_slist_foreach (list, (GFunc) free_func, NULL);
  93. g_slist_free (list);
  94. }
  95. /* --------------------------------------------------------------------------------------------- */
  96. /**
  97. * g_list_free_full:
  98. * @list: a pointer to a #GList
  99. * @free_func: the function to be called to free each element's data
  100. *
  101. * Convenience method, which frees all the memory used by a #GList, and
  102. * calls the specified destroy function on every element's data.
  103. *
  104. * Since: 2.28
  105. */
  106. void
  107. g_list_free_full (GList * list, GDestroyNotify free_func)
  108. {
  109. g_list_foreach (list, (GFunc) free_func, NULL);
  110. g_list_free (list);
  111. }
  112. #endif /* ! GLIB_CHECK_VERSION (2, 28, 0) */
  113. /* --------------------------------------------------------------------------------------------- */