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

@@ -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>