src: move _GNU_SOURCE definition before all includes in files that need vasprintf()

Build of input-libinput fails on GCC-11.2 although succeeds on GCC-14.2.
Function vasprintf() becomes implicitle declared because its definition
in stdio.h is guarded by __GLIBC_USE_LIB_EXT2 which depends on _USE_GNU,
which in turn depends on __GNU_SOURCE. __GNU_SOURCE is defined at
the beginning of util_string.h before #include <stdio.h>, and this file
is included by util_strings.c and xf86libinput.c. The latter file
includes first a lot of headers in /usr/include and /usr/include/xorg,
and finally util_string.h. If some of the previous header files
#include <stdio.h>, then it is included first without _GNU_SOURCE, and
vasprintf() is left undefined, which causes a build error.

This patch moves #define _GNU_SOURCE to util_strings.c and xf86libinput.c
from util_strings.h, thus making vasprintf() declaration safe and
independent of a specific compiler.

Signed-off-by: Oleh Nykyforchyn <olen.nyk@gmail.com>
This commit is contained in:
Oleh Nykyforchyn
2025-07-31 00:21:32 +03:00
committed by Enrico Weigelt
parent f03931201b
commit a95e7b25e6
3 changed files with 2 additions and 3 deletions

View File

@@ -23,6 +23,7 @@
*/
#include "config.h"
#define _GNU_SOURCE
#include "util-strings.h"

View File

@@ -24,9 +24,6 @@
#pragma once
#include "config.h"
#define _GNU_SOURCE
#include <assert.h>
#include <ctype.h>
#include <errno.h>

View File

@@ -24,6 +24,7 @@
*/
#include "config.h"
#define _GNU_SOURCE
#include <errno.h>
#include <fcntl.h>