/* Returns: a pointer to the found occurrence, or NULL if not found.  */
gchar* g_strrstr(const gchar *haystack, const gchar *needle)
/* Returns: a pointer to the found occurrence, or NULL if not found.  */
gchar* g_strrstr(const gchar *haystack, const gchar *needle)
{
  gsize i;
  gsize needle_len;
  gsize haystack_len;
  const gchar *p;
  g_return_val_if_fail (haystack != NULL, NULL);
  g_return_val_if_fail (needle != NULL, NULL);
  needle_len = strlen (needle);
  haystack_len = strlen (haystack);
  if (needle_len == 0)
    return (gchar *)haystack;
  if (haystack_len < needle_len)
    return NULL;
  p = haystack + haystack_len - needle_len;
  while (p >= haystack)
    {
      for (i = 0; i < needle_len; i++)
        if (p[i] != needle[i])
          goto next;
      return (gchar *)p;
    next:
      p--;
    }
  return NULL;
}