From 2a749707e39de56f635b5fe3a615d09520c180da Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Thu, 8 Mar 2012 13:23:37 +0100 Subject: [PATCH] weaker search for strnlen() as it is not standard-C99 --- config.h.in | 6 +++--- configure.in | 7 ++++--- debug.c | 10 +++++----- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/config.h.in b/config.h.in index 1b46c820..2c2fd922 100644 --- a/config.h.in +++ b/config.h.in @@ -58,9 +58,6 @@ /* Define to 1 if you have the header file. */ #undef HAVE_STRING_H -/* Define to 1 if you have the `strnlen' function. */ -#undef HAVE_STRNLEN - /* Define to 1 if you have the `strrchr' function. */ #undef HAVE_STRRCHR @@ -76,6 +73,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_SYS_TYPES_H +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_UNISTD_H + /* Define to 1 if you have the header file. */ #undef HAVE_TIME_H diff --git a/configure.in b/configure.in index 25c28be2..fbf44d16 100644 --- a/configure.in +++ b/configure.in @@ -1,7 +1,7 @@ # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. # -# Copyright (C) 2010,2011 Olaf Bergmann +# Copyright (C) 2010--2012 Olaf Bergmann # # This file is part of the CoAP library libcoap. Please see # README for terms of use. @@ -46,7 +46,7 @@ AC_ARG_WITH(async, []) # Checks for header files. -AC_CHECK_HEADERS([assert.h arpa/inet.h limits.h netdb.h netinet/in.h stdlib.h string.h strings.h sys/socket.h sys/time.h time.h unistd.h]) +AC_CHECK_HEADERS([assert.h arpa/inet.h limits.h netdb.h netinet/in.h stdlib.h string.h strings.h sys/socket.h sys/time.h time.h unistd.h sys/unistd.h]) # Checks for typedefs, structures, and compiler characteristics. AC_TYPE_SIZE_T @@ -54,7 +54,8 @@ AC_TYPE_SSIZE_T # Checks for library functions. AC_FUNC_MALLOC -AC_CHECK_FUNCS([memset select socket strcasecmp strrchr getaddrinfo strnlen]) +AC_CHECK_FUNCS([memset select socket strcasecmp strrchr getaddrinfo]) +AC_SEARCH_LIBS(strnlen, c) AC_CONFIG_HEADERS([config.h]) diff --git a/debug.c b/debug.c index 67a0384b..93a1e74d 100644 --- a/debug.c +++ b/debug.c @@ -1,6 +1,6 @@ /* debug.c -- debug utilities * - * Copyright (C) 2010,2011 Olaf Bergmann + * Copyright (C) 2010--2012 Olaf Bergmann * * This file is part of the CoAP library libcoap. Please see * README for terms of use. @@ -14,6 +14,7 @@ #include #include +#include #include #ifdef HAVE_ARPA_INET_H @@ -89,7 +90,7 @@ print_timestamp(char *s, size_t len, coap_tick_t t) { * @return The length of @p s. */ static inline size_t -strnlen(unsigned char *s, size_t maxlen) { +strnlen(const char *s, size_t maxlen) { size_t n = 0; while(*s++ && n < maxlen) ++n; @@ -160,7 +161,7 @@ coap_print_addr(const struct __coap_address_t *addr, unsigned char *buf, size_t return 0; } - p += strnlen(p, len); + p += strnlen((char *)p, len); if (addr->addr.sa.sa_family == AF_INET6) { if (p < buf + len) { @@ -175,8 +176,7 @@ coap_print_addr(const struct __coap_address_t *addr, unsigned char *buf, size_t #else /* HAVE_ARPA_INET_H */ # if WITH_CONTIKI unsigned char *p = buf; - uint8_t i;\ - uint16_t port; + uint8_t i; # if WITH_UIP6 const unsigned char hex[] = "0123456789ABCDEF";