From 2c40ad78166c4cdb667caf4238080a4708c43326 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Wed, 1 Apr 2026 11:36:41 +0100 Subject: lbutils: only use GNU SOURCE for syscall and remove manual prototypes; fchmod, realpath and so on rely on the _XOPEN_SOURCE macro. the POSIX macro wasn't needed: _XOPEN_SOURCE is sufficient. Signed-off-by: Leah Rowe --- util/libreboot-utils/include/common.h | 16 ---------------- util/libreboot-utils/lib/file.c | 20 +++++++++++--------- util/libreboot-utils/lib/mkhtemp.c | 29 ++++++++++++++++------------- util/libreboot-utils/lib/rand.c | 16 +++++++++------- util/libreboot-utils/lib/state.c | 4 ++-- util/libreboot-utils/lottery.c | 5 ----- util/libreboot-utils/mkhtemp.c | 5 ++--- util/libreboot-utils/nvmutil.c | 4 ---- 8 files changed, 40 insertions(+), 59 deletions(-) diff --git a/util/libreboot-utils/include/common.h b/util/libreboot-utils/include/common.h index 21be1898..a7099f35 100644 --- a/util/libreboot-utils/include/common.h +++ b/util/libreboot-utils/include/common.h @@ -13,18 +13,6 @@ #include #include #include -#include - -/* for linux getrandom - */ -#if defined(__linux__) -#include -#include -#endif - -#ifdef __OpenBSD__ /* for pledge */ -#include -#endif /* dangerously cool macros: */ @@ -49,10 +37,6 @@ /* system prototypes */ -int fchmod(int fd, mode_t mode); -char *realpath(const char *path, - char *resolved); - #ifndef USE_URANDOM #define USE_URANDOM 0 #endif diff --git a/util/libreboot-utils/lib/file.c b/util/libreboot-utils/lib/file.c index 685cdf9a..3f15aabf 100644 --- a/util/libreboot-utils/lib/file.c +++ b/util/libreboot-utils/lib/file.c @@ -16,8 +16,17 @@ more correct usage example: long max = pathconf("/", _PC_PATH_MAX); */ -#ifndef _POSIX_C_SOURCE -#define _POSIX_C_SOURCE 200809L +#ifndef _XOPEN_SOURCE +#define _XOPEN_SOURCE 700 +#endif + +/* for openat2: */ +#ifdef __linux__ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE 1 +#endif +#include +#include #endif #include @@ -30,13 +39,6 @@ long max = pathconf("/", _PC_PATH_MAX); #include #include -/* for openat2: */ -#ifdef __linux__ -#include -#include -long syscall(long number, ...); -#endif - #include "../include/common.h" /* check that a file changed diff --git a/util/libreboot-utils/lib/mkhtemp.c b/util/libreboot-utils/lib/mkhtemp.c index 46f6419f..11a5bdb9 100644 --- a/util/libreboot-utils/lib/mkhtemp.c +++ b/util/libreboot-utils/lib/mkhtemp.c @@ -4,24 +4,17 @@ * Hardened mktemp (be nice to the demon). */ -#if !defined(_POSIX_C_SOURCE) -#define _POSIX_C_SOURCE 200809L +#ifndef _XOPEN_SOURCE +#define _XOPEN_SOURCE 700 #endif -#include -#include - -#include -#include -#include -#include -#include -#include - /* for openat2 / fast path: */ #ifdef __linux__ -#include +#ifndef _GNU_SOURCE +#define _GNU_SOURCE 1 +#endif #include +#include #ifndef O_TMPFILE #define O_TMPFILE 020000000 #endif @@ -30,6 +23,16 @@ #endif #endif +#include +#include + +#include +#include +#include +#include +#include +#include + #include "../include/common.h" /* note: tmpdir is an override of TMPDIR or /tmp or /var/tmp */ diff --git a/util/libreboot-utils/lib/rand.c b/util/libreboot-utils/lib/rand.c index 8c3fbf4c..726d5cd2 100644 --- a/util/libreboot-utils/lib/rand.c +++ b/util/libreboot-utils/lib/rand.c @@ -7,19 +7,21 @@ #ifndef RAND_H #define RAND_H -#ifdef __OpenBSD__ -#include -#endif -#include - #if defined(USE_URANDOM) && \ ((USE_URANDOM) > 0) #include /* if not arc4random: /dev/urandom */ #elif defined(__linux__) -#include +#ifndef _GNU_SOURCE +#define _GNU_SOURCE 1 +#endif #include -long syscall(long number, ...); +#include +#endif + +#ifdef __OpenBSD__ +#include #endif +#include #include #include diff --git a/util/libreboot-utils/lib/state.c b/util/libreboot-utils/lib/state.c index a7c85bfb..78e15134 100644 --- a/util/libreboot-utils/lib/state.c +++ b/util/libreboot-utils/lib/state.c @@ -4,8 +4,8 @@ * State machine (singleton) for nvmutil data. */ -#ifndef _POSIX_C_SOURCE -#define _POSIX_C_SOURCE 200809L +#ifndef _XOPEN_SOURCE +#define _XOPEN_SOURCE 700 #endif #include diff --git a/util/libreboot-utils/lottery.c b/util/libreboot-utils/lottery.c index a494eff1..1648cbc7 100644 --- a/util/libreboot-utils/lottery.c +++ b/util/libreboot-utils/lottery.c @@ -2,11 +2,6 @@ * Copyright (c) 2026 Leah Rowe /| |\ Something something non-determinism / \ */ -#if !defined(_POSIX_C_SOURCE) -/* for openat2 on linux */ -#define _POSIX_C_SOURCE 200809L -#endif - #include #include #include diff --git a/util/libreboot-utils/mkhtemp.c b/util/libreboot-utils/mkhtemp.c index c8ddb1b1..86aab536 100644 --- a/util/libreboot-utils/mkhtemp.c +++ b/util/libreboot-utils/mkhtemp.c @@ -16,9 +16,8 @@ * while the specification that it implements evolves. */ -#if !defined(_POSIX_C_SOURCE) -/* for openat2 on linux */ -#define _POSIX_C_SOURCE 200809L +#ifndef _XOPEN_SOURCE +#define _XOPEN_SOURCE 700 #endif #include diff --git a/util/libreboot-utils/nvmutil.c b/util/libreboot-utils/nvmutil.c index c805f523..ee20e851 100644 --- a/util/libreboot-utils/nvmutil.c +++ b/util/libreboot-utils/nvmutil.c @@ -6,10 +6,6 @@ * These images configure your Intel Gigabit Ethernet adapter. */ -#ifndef _POSIX_C_SOURCE -#define _POSIX_C_SOURCE 200809L -#endif - #include #include -- cgit v1.2.1