diff mbox series

[1/2] Make inclusion of <bsd/string.h> optional

Message ID 20260507071613.2850492-2-thuth@redhat.com
State Accepted
Headers show
Series Allow compilation without libbsd | expand

Commit Message

Thomas Huth May 7, 2026, 7:16 a.m. UTC
From: Thomas Huth <thuth@redhat.com>

strlcpy() and strlcat() are available in the glibc since version 2.38:

 https://lists.gnu.org/archive/html/info-gnu/2023-07/msg00010.html

Thus it is not necessary anymore to include the <bsd/string.h> header
in the files that use these functions.
There is already a HAVE_BSD_STRING_H macro set by the configure script
which can be used to only include this header conditionally, so let's
use this now to allow compilation without the bsd/string.h header.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 src/acpi/crsdump/crsdump.c   | 5 ++++-
 src/acpi/uniqueid/uniqueid.c | 3 +++
 src/cpu/maxfreq/maxfreq.c    | 3 +++
 src/lib/src/fwts_battery.c   | 5 ++++-
 src/lib/src/fwts_button.c    | 3 +++
 src/lib/src/fwts_framework.c | 5 ++++-
 src/lib/src/fwts_hwinfo.c    | 5 ++++-
 src/lib/src/fwts_kernel.c    | 3 +++
 src/lib/src/fwts_modprobe.c  | 5 ++++-
 9 files changed, 32 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/src/acpi/crsdump/crsdump.c b/src/acpi/crsdump/crsdump.c
index a1fb9cb6..7730960b 100644
--- a/src/acpi/crsdump/crsdump.c
+++ b/src/acpi/crsdump/crsdump.c
@@ -23,12 +23,15 @@ 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <bsd/string.h>
 #include <unistd.h>
 #include <inttypes.h>
 #include "fwts_acpi_object_eval.h"
 #include "crsdump.h"
 
+#ifdef HAVE_BSD_STRING_H
+#include <bsd/string.h>
+#endif
+
 typedef struct {
 	const char *label;				/* Field label */
 	size_t offset;					/* Offset into _CRS buffer */
diff --git a/src/acpi/uniqueid/uniqueid.c b/src/acpi/uniqueid/uniqueid.c
index 17baaca8..0cdb0710 100644
--- a/src/acpi/uniqueid/uniqueid.c
+++ b/src/acpi/uniqueid/uniqueid.c
@@ -25,7 +25,10 @@ 
 #include <unistd.h>
 #include <inttypes.h>
 #include <string.h>
+
+#ifdef HAVE_BSD_STRING_H
 #include <bsd/string.h>
+#endif
 
 #include "fwts_acpi_object_eval.h"
 
diff --git a/src/cpu/maxfreq/maxfreq.c b/src/cpu/maxfreq/maxfreq.c
index 5931f251..2627591c 100644
--- a/src/cpu/maxfreq/maxfreq.c
+++ b/src/cpu/maxfreq/maxfreq.c
@@ -24,7 +24,10 @@ 
 #include <dirent.h>
 #include <ctype.h>
 #include <math.h>
+
+#ifdef HAVE_BSD_STRING_H
 #include <bsd/string.h>
+#endif
 
 #define CPU_FREQ_PATH	"/sys/devices/system/cpu"
 #define CPU_INFO_PATH	"/proc/cpuinfo"
diff --git a/src/lib/src/fwts_battery.c b/src/lib/src/fwts_battery.c
index 0342bdd8..685295e7 100644
--- a/src/lib/src/fwts_battery.c
+++ b/src/lib/src/fwts_battery.c
@@ -25,11 +25,14 @@ 
 #include <sys/stat.h>
 #include <unistd.h>
 #include <string.h>
-#include <bsd/string.h>
 #include <limits.h>
 #include <dirent.h>
 #include <inttypes.h>
 
+#ifdef HAVE_BSD_STRING_H
+#include <bsd/string.h>
+#endif
+
 static inline bool fwts_battery_match(
 	const uint32_t index,
 	const uint32_t loop_index)
diff --git a/src/lib/src/fwts_button.c b/src/lib/src/fwts_button.c
index 11eb0d7b..b1036b56 100644
--- a/src/lib/src/fwts_button.c
+++ b/src/lib/src/fwts_button.c
@@ -26,7 +26,10 @@ 
 #include <string.h>
 #include <limits.h>
 #include <dirent.h>
+
+#ifdef HAVE_BSD_STRING_H
 #include <bsd/string.h>
+#endif
 
 #define FWTS_PROC_ACPI_BUTTON	"/proc/acpi/button"
 
diff --git a/src/lib/src/fwts_framework.c b/src/lib/src/fwts_framework.c
index bda25597..d260f144 100644
--- a/src/lib/src/fwts_framework.c
+++ b/src/lib/src/fwts_framework.c
@@ -26,13 +26,16 @@ 
 #include <ctype.h>
 #include <time.h>
 #include <getopt.h>
-#include <bsd/string.h>
 #include <sys/utsname.h>
 #include <sys/time.h>
 
 #include "fwts.h"
 #include "fwts_pm_method.h"
 
+#ifdef HAVE_BSD_STRING_H
+#include <bsd/string.h>
+#endif
+
 typedef struct {
 	const char *title;		/* Test category */
 	fwts_framework_flags flag;	/* Mask of category */
diff --git a/src/lib/src/fwts_hwinfo.c b/src/lib/src/fwts_hwinfo.c
index 6f4b752f..9b3b82d1 100644
--- a/src/lib/src/fwts_hwinfo.c
+++ b/src/lib/src/fwts_hwinfo.c
@@ -20,7 +20,6 @@ 
 #include <stdlib.h>
 #include <stdint.h>
 #include <string.h>
-#include <bsd/string.h>
 #include <errno.h>
 #include <inttypes.h>
 #include <dirent.h>
@@ -37,6 +36,10 @@ 
 
 #include "fwts.h"
 
+#ifdef HAVE_BSD_STRING_H
+#include <bsd/string.h>
+#endif
+
 #define FWTS_HWINFO_LISTS_SAME		(0)
 #define FWTS_HWINFO_LISTS_DIFFER	(1)
 #define FWTS_HWINFO_LISTS_OUT_OF_MEMORY	(-1)
diff --git a/src/lib/src/fwts_kernel.c b/src/lib/src/fwts_kernel.c
index 897d09cf..f05597cc 100644
--- a/src/lib/src/fwts_kernel.c
+++ b/src/lib/src/fwts_kernel.c
@@ -23,7 +23,10 @@ 
 #include "fwts_kernel.h"
 #include <stdlib.h>
 #include <stdio.h>
+
+#ifdef HAVE_BSD_STRING_H
 #include <bsd/string.h>
+#endif
 
 #define CONFIG_FILE_PREFIX	"/boot/config-"
 #define CONFIG_FILE_PROC	"/proc/config.gz"
diff --git a/src/lib/src/fwts_modprobe.c b/src/lib/src/fwts_modprobe.c
index 1b417a0e..8ec56a93 100644
--- a/src/lib/src/fwts_modprobe.c
+++ b/src/lib/src/fwts_modprobe.c
@@ -28,10 +28,13 @@ 
 #include <stdlib.h>
 #include <errno.h>
 #include <sys/utsname.h>
-#include <bsd/string.h>
 
 #include "fwts.h"
 
+#ifdef HAVE_BSD_STRING_H
+#include <bsd/string.h>
+#endif
+
 /*
  *  fwts_module_path()
  *	build a new path based on basename path and