add a compatible memrchr() function if the platform does not support it (e.g. old glibc). Patch courtesy to Thomas Jarosch

This commit is contained in:
Andreas Steffen 2009-01-09 01:19:45 +00:00
parent a205d9581d
commit 48032aed00
4 changed files with 50 additions and 0 deletions

View File

@ -707,6 +707,7 @@ dnl ==========================================
AC_HAVE_LIBRARY(dl)
AC_CHECK_FUNCS(backtrace)
AC_CHECK_FUNCS(dladdr)
AC_REPLACE_FUNCS(memrchr)
AC_MSG_CHECKING([for gcc atomic operations])
AC_TRY_RUN(

View File

@ -47,6 +47,7 @@ utils/identification.c utils/identification.h \
utils/iterator.h \
utils/lexparser.c utils/lexparser.h \
utils/linked_list.c utils/linked_list.h \
utils/memrchr.c \
utils/hashtable.c utils/hashtable.h \
utils/enumerator.c utils/enumerator.h \
utils/optionsfrom.c utils/optionsfrom.h \

View File

@ -20,6 +20,9 @@
#include "lexparser.h"
#ifndef HAVE_MEMRCHR
void *memrchr(const void *s, int c, size_t n);
#endif
/**
* eat whitespace

View File

@ -0,0 +1,45 @@
/*
* Copyright (C) 2008 Thomas Jarosch
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#ifndef HAVE_MEMRCHR
#include <string.h>
void *memrchr(const void *s, int c, size_t n)
{
unsigned char *reverse_search;
if (s == NULL || n == 0)
{
return NULL;
}
reverse_search = s + n;
for (;;)
{
if (*reverse_search == (unsigned char)c)
{
return reverse_search;
}
else if (reverse_search == s)
{
break;
}
reverse_search--;
}
return NULL;
}
#endif