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)).
This commit is contained in:
Olaf Bergmann committed 2015-02-18 13:18:18 +01:00
1 parent e1dbfc1f55
commit 961b5e0719
1 file changed
+5 -1
+5 -1
View File
@@ -1,6 +1,6 @@
/* debug.c -- debug utilities
*
* Copyright (C) 2010--2012,2014 Olaf Bergmann <bergmann@tzi.org>
* Copyright (C) 2010--2012,2014--2015 Olaf Bergmann <bergmann@tzi.org>
*
* 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 <assert.h>
#endif