From 961b5e0719d1bc34cdc868a53b4d13b57d049628 Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Wed, 18 Feb 2015 13:18:18 +0100 Subject: [PATCH] fix compiler warning for strnlen() strnlen() is used for formatting messages in debug.c. As strnlen() is unknown in C99, the compiler emits a warning even if configure has detected the presence of strnlen() in glibc and has set HAVE_STRNLEN accordingly. To overcome this, the symbol _GNU_SOURCE now is set when HAVE_STRNLEN and __GNUC__ are defined but not _GNU_SOURCE. This works not only for glibc prior 2.10 but also for newer versions that conform to POSIX.1-2008 (see strnlen(1)). --- debug.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/debug.c b/debug.c index c7f98e5b..9b33a00b 100644 --- a/debug.c +++ b/debug.c @@ -1,6 +1,6 @@ /* debug.c -- debug utilities * - * Copyright (C) 2010--2012,2014 Olaf Bergmann + * Copyright (C) 2010--2012,2014--2015 Olaf Bergmann * * This file is part of the CoAP library libcoap. Please see * README for terms of use. @@ -8,6 +8,10 @@ #include "coap_config.h" +#if defined(HAVE_STRNLEN) && defined(__GNUC__) && !defined(_GNU_SOURCE) +#define _GNU_SOURCE 1 +#endif + #if defined(HAVE_ASSERT_H) && !defined(assert) # include #endif