Commit 1c5bec45 authored by Pekka Pessi's avatar Pekka Pessi

Added replacement functions memccpy().

Also moved memcspn() to a file of its own.

darcs-hash:20051128221756-65a35-4c8d9d70307f2e4b763855076a8af775db5d03c3.gz
parent b69d4f3e
......@@ -49,9 +49,11 @@ include_sofia_HEADERS = su_types.h su.h su_localinfo.h \
su_tag_io.h su_tag_inline.h \
htable.h htable2.h \
su_debug.h su_module_debug.h su_log.h \
su_config.h su_configure.h su_md5.h su_uniqueid.h \
su_config.h su_md5.h su_uniqueid.h \
tstdef.h rbtree.h su_memmem.h
nodist_include_sofia_HEADERS = su_configure.h
libsu_la_SOURCES = \
su.c $(GSOURCES) \
su_alloc.c su_alloc_lock.c su_strdup.c su_sprintf.c \
......@@ -63,6 +65,15 @@ libsu_la_SOURCES = \
su_log.c su_global_log.c su_default_log.c \
su_md5.c su_uniqueid.c su_memmem.c
EXTRA_libsu_la_SOURCES = \
memmem.c strtoull.c strcasestr.c \
memspn.c memcspn.c memccpy.c \
inet_ntop.c inet_pton.c \
su_tag_ref.c
libsu_la_LIBADD = $(REPLACE_LIBADD)
libsu_la_DEPENDENCIES = $(REPLACE_LIBADD)
COVERAGE_INPUT = $(libsu_la_SOURCES) $(include_sofia_HEADERS)
LDADD = libsu.la $(GLIB_LIBS)
......@@ -75,10 +86,7 @@ endif
# Install and distribution rules
EXTRA_DIST = Doxyfile su.docs \
run_addrinfo run_localinfo run_su_test \
memmem.c strtoull.c strcasestr.c \
inet_ntop.c inet_pton.c \
su_tag_ref.c
run_addrinfo run_localinfo run_su_test
dist_sofialibexec_SCRIPTS = tag_dll.awk
......
/*
* This file is part of the Sofia-SIP package
*
* Copyright (C) 2005 Nokia Corporation.
*
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
/**@file memccpy.c
* @brief The memccpy() replacement function.
*
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
*
* @date Created: Thu Nov 17 17:45:51 EET 2005 ppessi
*/
#include "config.h"
#include <string.h>
#include <limits.h>
/**Copy memory until @a c is found.
*
* Copies no more than @a n bytes from memory area @a src to memory area @a
* dest, stopping after the character @a c is copied and found.
*
* @param dest pointer to destination area
* @param src pointer to source area
* @param c terminating byte
* @param n size of destination area
*
* @return
* Returns a pointer to the next character in @a dest after @a c,
* or NULL if @a c was not found in the first @a n characters of @a src.
*/
void *memccpy(void *dest, const void *src, int c, size_t n)
{
char *d;
char const *s;
if (!src || !dest)
return dest;
for (d = dest, s = src; n-- > 0;) {
if (c == (*d++ = *s++))
return d;
}
return NULL;
}
/*
* This file is part of the Sofia-SIP package
*
* Copyright (C) 2005 Nokia Corporation.
*
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
/**@file memcspn.c
* @brief The memcspn() replacement function.
*
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
*
* @date Created: Thu Nov 17 17:45:51 EET 2005 ppessi
*/
#include "config.h"
#include <string.h>
#include <limits.h>
/**Search memory for bytes not in a given set.
*
* The memcspn() function calculates the length of the memory area @a mem
* which consists entirely of bytes not in @a reject.
*
* @param mem pointer to memory area
* @param memlen size of @a mem in bytes
* @param reject pointer to table containing bytes to reject
* @param rejectlen size of @a reject table
*
* @return
* The memspn() function returns the number of bytes in the memory area @a
* which consists entirely of bytes not in @a reject.
* @par
* If @a rejectlen is 0, or @a reject is NULL, it returns @a memlen, size of
* the memory area.
*/
size_t memcspn(const void *mem, size_t memlen,
const void *reject, size_t rejectlen)
{
size_t i;
unsigned char const *m = mem, *r = reject;
char rejected[UCHAR_MAX + 1];
if (rejectlen == 0 || reject == 0)
return memlen;
if (mem == NULL || memlen == 0)
return 0;
memset(rejected, 0, sizeof rejected);
for (i = 0; i < rejectlen; i++)
rejected[r[i]] = 1;
for (i = 0; i < memlen; i++)
if (rejected[m[i]])
break;
return i;
}
......@@ -23,8 +23,7 @@
*/
/**@file memspn.c
* @brief The memspn() and memcspn() functions
* - search memory for a set of characters.
* The memspn() replacement function.
*
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
*
......@@ -37,7 +36,6 @@
#include <string.h>
#include <limits.h>
#if !HAVE_MEMSPN
/**Scan memory for a set of bytes.
*
* The memspn() function calculates the length of the memory area @a mem
......@@ -75,50 +73,3 @@ size_t memspn(const void *mem, size_t memlen,
return i;
}
#endif
#if !HAVE_MEMCSPN
/**Search memory for bytes not in a given set.
*
* The memcspn() function calculates the length of the memory area @a mem
* which consists entirely of bytes not in @a reject.
*
* @param mem pointer to memory area
* @param memlen size of @a mem in bytes
* @param reject pointer to table containing bytes to reject
* @param rejectlen size of @a reject table
*
* @return
* The memspn() function returns the number of bytes in the memory area @a
* which consists entirely of bytes not in @a reject.
* @par
* If @a rejectlen is 0, or @a reject is NULL, it returns @a memlen, size of
* the memory area.
*/
size_t memcspn(const void *mem, size_t memlen,
const void *reject, size_t rejectlen)
{
size_t i;
unsigned char const *m = mem, *r = reject;
char rejected[UCHAR_MAX + 1];
if (rejectlen == 0 || reject == 0)
return memlen;
if (mem == NULL || memlen == 0)
return 0;
memset(rejected, 0, sizeof rejected);
for (i = 0; i < rejectlen; i++)
rejected[r[i]] = 1;
for (i = 0; i < memlen; i++)
if (rejected[m[i]])
break;
return i;
}
#endif
......@@ -37,7 +37,7 @@
char *strcasestr(const char *haystack,
const char *needle)
{
char lcn, ucn;
unsigned char lcn, ucn;
unsigned i;
if (haystack == NULL || needle == NULL)
......
......@@ -204,8 +204,7 @@ if test "${with_rt}" != no; then
AC_CHECK_FUNCS(clock_gettime clock_getcpuclockid)
fi
AC_CHECK_FUNCS(memccpy memcspn memspn strcasestr)
AC_REPLACE_FUNCS(memmem)
SAC_REPLACE_FUNCS(memmem memccpy memspn memcspn strcasestr strtoull)
AC_CHECK_FUNC([poll],
SAC_SU_DEFINE([SU_HAVE_POLL], 1, [
......@@ -256,3 +255,15 @@ cat >>confdefs.h <<_ACEOF
[@%:@define] $1 m4_if($#, 2, [$2], $#, 3, [$2], 1)
_ACEOF
])
AC_DEFUN([SAC_REPLACE_FUNCS],[dnl
AC_CHECK_FUNCS($1,,[dnl
case "$REPLACE_LIBADD" in
"$ac_func.lo" | \
*" $ac_func.lo" | \
"$ac_func.lo "* | \
*" $ac_func.lo "* ) ;;
*) REPLACE_LIBADD="$REPLACE_LIBADD $ac_func.lo" ;;
esac])
AC_SUBST([REPLACE_LIBADD])
])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment