glibcompat.c 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. GLIB - Library of useful routines for C programming
  3. Copyright (C) 2009, 2011, 2013
  4. The 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. /* --------------------------------------------------------------------------------------------- */