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:
@@ -707,6 +707,7 @@ dnl ==========================================
|
|||||||
AC_HAVE_LIBRARY(dl)
|
AC_HAVE_LIBRARY(dl)
|
||||||
AC_CHECK_FUNCS(backtrace)
|
AC_CHECK_FUNCS(backtrace)
|
||||||
AC_CHECK_FUNCS(dladdr)
|
AC_CHECK_FUNCS(dladdr)
|
||||||
|
AC_REPLACE_FUNCS(memrchr)
|
||||||
|
|
||||||
AC_MSG_CHECKING([for gcc atomic operations])
|
AC_MSG_CHECKING([for gcc atomic operations])
|
||||||
AC_TRY_RUN(
|
AC_TRY_RUN(
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ utils/identification.c utils/identification.h \
|
|||||||
utils/iterator.h \
|
utils/iterator.h \
|
||||||
utils/lexparser.c utils/lexparser.h \
|
utils/lexparser.c utils/lexparser.h \
|
||||||
utils/linked_list.c utils/linked_list.h \
|
utils/linked_list.c utils/linked_list.h \
|
||||||
|
utils/memrchr.c \
|
||||||
utils/hashtable.c utils/hashtable.h \
|
utils/hashtable.c utils/hashtable.h \
|
||||||
utils/enumerator.c utils/enumerator.h \
|
utils/enumerator.c utils/enumerator.h \
|
||||||
utils/optionsfrom.c utils/optionsfrom.h \
|
utils/optionsfrom.c utils/optionsfrom.h \
|
||||||
|
|||||||
@@ -20,6 +20,9 @@
|
|||||||
|
|
||||||
#include "lexparser.h"
|
#include "lexparser.h"
|
||||||
|
|
||||||
|
#ifndef HAVE_MEMRCHR
|
||||||
|
void *memrchr(const void *s, int c, size_t n);
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* eat whitespace
|
* eat whitespace
|
||||||
|
|||||||
@@ -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
|
||||||
Reference in New Issue
Block a user