Fix usage of _GNU_SOURCE

_GNU_SOURCE must be defined before including any other (system)
header, so defining it in glib-unix.h (and hoping no one has included
anything else before that) is wrong. And the "#define _USE_GNU"
workaround for this problem in gnetworkingprivate.h is even wronger
(and still prone to failure anyway due to single-include guards).

Fix this by defining _GNU_SOURCE in config.h when building against
glibc. In theory this is bad because new releases of glibc may include
symbols that conflict with glib symbols, which could then cause
compile failures. However, most people only see new releases of glibc
when they upgrade their distro, at which point they also generally get
new releases of gcc, which have new warnings/errors to clean up
anyway.

https://bugzilla.gnome.org/show_bug.cgi?id=649201
This commit is contained in:
Dan Winship 2011-05-01 11:17:14 -04:00
parent 33c0877adc
commit e56498ee0b
16 changed files with 11 additions and 61 deletions

View File

@ -206,6 +206,10 @@ if test "x$glib_have_carbon" = "xyes"; then
LDFLAGS="$LDFLAGS -framework Carbon"
fi
gl_GLIBC21
if test "x$GLIBC21" = "xyes"; then
AC_DEFINE([_GNU_SOURCE], 1, [Make all glibc extensions visible])
fi
dnl declare --enable-* args and collect ac_help strings
AC_ARG_ENABLE(debug,
@ -412,7 +416,6 @@ else
fi
fi
gl_GLIBC21
AC_ARG_ENABLE(iconv-cache,
[AC_HELP_STRING([--enable-iconv-cache=@<:@yes/no/auto@:>@],
[cache iconv descriptors [default=auto]])],,
@ -929,7 +932,6 @@ AC_CHECK_MEMBERS([struct tm.tm_gmtoff, struct tm.__tm_gmtoff],,,[#include <time.
# Checks for libcharset
AM_LANGINFO_CODESET
gl_GLIBC21
AC_CHECK_HEADERS([stddef.h stdlib.h string.h])
AC_CHECK_FUNCS(setlocale)

View File

@ -24,7 +24,6 @@
#include "config.h"
#ifdef HAVE_SPLICE
#define _GNU_SOURCE
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>

View File

@ -20,7 +20,6 @@
*/
/* Prologue {{{1 */
#define _GNU_SOURCE
#include "config.h"
#include <gstdio.h>

View File

@ -33,7 +33,6 @@
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#define _GNU_SOURCE
#include <fcntl.h>
#include <errno.h>
#ifdef HAVE_GRP_H

View File

@ -40,38 +40,24 @@
#else /* !G_OS_WIN32 */
/* need this for struct ucred on Linux */
#ifdef __linux__
#define __USE_GNU
#include <sys/types.h>
#include <sys/socket.h>
#undef __USE_GNU
#endif
#include <sys/types.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
#if defined(HAVE_ARPA_NAMESER_COMPAT_H) && !defined(GETSHORT)
#include <arpa/nameser_compat.h>
#endif
#ifndef T_SRV
#define T_SRV 33
#endif
/* We're supposed to define _GNU_SOURCE to get EAI_NODATA, but that
* won't actually work since <features.h> has already been included at
* this point. So we define __USE_GNU instead.
*/
#define __USE_GNU
#include <netdb.h>
#undef __USE_GNU
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <resolv.h>
#include <sys/socket.h>
#include <sys/un.h>
#ifndef T_SRV
#define T_SRV 33
#endif
#ifndef _PATH_RESCONF
#define _PATH_RESCONF "/etc/resolv.conf"
#endif

View File

@ -20,7 +20,6 @@
*/
/* Prelude {{{1 */
#define _GNU_SOURCE
#include "config.h"
#include <glib.h>

View File

@ -37,8 +37,6 @@
/* ---------------------------------------------------------------------------------------------------- */
#ifdef __linux__
#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>

View File

@ -31,8 +31,6 @@
* <filename>gio-unix-2.0.pc</filename> pkg-config file when using it.
*/
#define _GNU_SOURCE /* for F_DUPFD_CLOEXEC */
#include "config.h"
#include <sys/types.h>

View File

@ -20,8 +20,6 @@
#include "config.h"
#define _GNU_SOURCE
/* We want to build the fork-based version, not the threaded version. */
#undef HAVE_PTHREAD

View File

@ -20,6 +20,8 @@
* Author: David Zeuthen <davidz@redhat.com>
*/
#include "config.h"
#include <gio/gio.h>
#include <unistd.h>
#include <string.h>

View File

@ -26,10 +26,6 @@
* system, work around it here (or better, fix the system or tell
* people to use a better one).
*/
#ifndef _GNU_SOURCE
#define _G_GNU_SOURCE_TEMPORARILY_DEFINED
#define _GNU_SOURCE
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
@ -37,10 +33,6 @@
#include <sys/wait.h>
#include <stdlib.h>
#include <fcntl.h>
#ifdef _G_GNU_SOURCE_TEMPORARILY_DEFINED
#undef _GNU_SOURCE
#undef _G_GNU_SOURCE_TEMPORARILY_DEFINED
#endif
#include <glib.h>

View File

@ -31,21 +31,6 @@
* MT safe
*/
#ifndef _WIN32
/* for pipe2; need to define it first to avoid
* other headers pulling in unistd.h
*/
/* The meaning of_GNU_SOURCE that is intended here is present only on
* Linux; avoid the possibility that some misguided header in MinGW
* looks at it. Ideally we should define _GNU_SOURCE only on platforms
* where we know what it means and that is what we want here
* (i.e. Linux with glibc). After all, there might be some other POSIX
* platform even where _GNU_SOURCE is used for some unrelated change
* in semantics that isn't wanted. Sigh.
*/
#define _GNU_SOURCE
#endif
#include "config.h"
#include "glibconfig.h"

View File

@ -19,10 +19,6 @@
#include "config.h"
#ifndef _WIN32
#define _GNU_SOURCE /* For vasprintf */
#endif
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>

View File

@ -34,7 +34,6 @@
#include "config.h"
#define _GNU_SOURCE
#include <limits.h>
#include <stdlib.h>
#include <string.h>

View File

@ -25,7 +25,7 @@
# define HAVE_COMPLIANT_POSIX_MEMALIGN 1
#endif
#ifdef HAVE_COMPLIANT_POSIX_MEMALIGN
#if defined(HAVE_COMPLIANT_POSIX_MEMALIGN) && !defined(_XOPEN_SOURCE)
#define _XOPEN_SOURCE 600 /* posix_memalign() */
#endif
#include <stdlib.h> /* posix_memalign() */

View File

@ -30,8 +30,6 @@
#include "config.h"
#define _GNU_SOURCE /* For stpcpy */
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>