[PATCH 2/2] lib: fwts_buttion: add helper function to build button path
Ivan Hu
ivan.hu at canonical.com
Wed Jul 29 04:03:50 UTC 2020
For fixing gcc-10 generates build errors on armhf.
Signed-off-by: Ivan Hu <ivan.hu at canonical.com>
---
src/lib/src/fwts_button.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/src/lib/src/fwts_button.c b/src/lib/src/fwts_button.c
index b2be77f7..591085ca 100644
--- a/src/lib/src/fwts_button.c
+++ b/src/lib/src/fwts_button.c
@@ -26,9 +26,24 @@
#include <string.h>
#include <limits.h>
#include <dirent.h>
+#include <bsd/string.h>
#define FWTS_PROC_ACPI_BUTTON "/proc/acpi/button"
+static inline void fwts_button_path(
+ char *path,
+ const size_t path_len,
+ const char *button_dir,
+ const char *name,
+ const char *str)
+{
+ (void)strlcpy(path, button_dir, path_len);
+ (void)strlcat(path, "/", path_len);
+ (void)strlcat(path, name, path_len);
+ (void)strlcat(path, "/", path_len);
+ (void)strlcat(path, str, path_len);
+}
+
/*
* fwts_button_match_state_proc()
* find matching button state and keep count of matching
@@ -80,7 +95,8 @@ static int fwts_button_match_state_proc(
char path[PATH_MAX];
char *data;
- snprintf(path, sizeof(path), "%s/%s/%s", button_dir, entry->d_name, field);
+ fwts_button_path(path, sizeof(path), button_dir, entry->d_name, field);
+
if ((data = fwts_get(path)) != NULL) {
if (strstr(data, match))
(*matched)++;
--
2.17.1
More information about the fwts-devel
mailing list