logo

utils-std

Collection of commonly available Unix tools
commit: a8363b592dd8eb119ed85e5eeb93b66f59c33c95
parent 3d2b46bceac5de0cd651355dd8bbfb300bfd6548
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sun, 31 Mar 2024 17:24:30 +0200

configure: Add test for splice(2)

Diffstat:

MMakefile2+-
Mconfigure19+++++++++++++++++++
Aconfigure.d/splice.c17+++++++++++++++++
3 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile @@ -49,7 +49,7 @@ install: all coverage: $(GCOV) -b $(EXE) -C_SOURCES = cmd/*.c lib/*.h lib/*.c +C_SOURCES = cmd/*.c lib/*.h lib/*.c configure.d/*.c format: $(C_SOURCES) clang-format -style=file -assume-filename=.clang-format -i $(C_SOURCES) diff --git a/configure b/configure @@ -100,6 +100,21 @@ check_header() { is_ok } +check_conftest() { + conftest="$1" + + printf 'Checking if conftest %s compiles ...' "$conftest" + + out="$(${CC} ${CFLAGS} -c -o /dev/null "${conftest}" 2>&1)" + status="$?" + + is_ok + + echo "$out" + + return $status +} + ## User configuration # defaults @@ -231,6 +246,10 @@ if ! check_header mntent.h; then echo 'cmd/df' >> target_filter fi +if check_conftest configure.d/splice.c; then + CFLAGS="${CFLAGS} -DHAS_SPLICE" +fi + echo ## Configuration write diff --git a/configure.d/splice.c b/configure.d/splice.c @@ -0,0 +1,17 @@ +// utils-std: Collection of commonly available Unix tools +// SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +// SPDX-License-Identifier: MPL-2.0 + +// Because that's what our utilities will use :) +#define _POSIX_C_SOURCE 200809L +#define _GNU_SOURCE // for splice + +#include <fcntl.h> // splice +#include <stdint.h> // SIZE_MAX + +ssize_t +test(int in, int out) +{ + off_t in_pos = 0, out_pos = 0; + return splice(in, &in_pos, out, &out_pos, SIZE_MAX, 0); +}