public inbox for iwd@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH] wiphy: Remove basename() use
@ 2024-02-14 20:55 Denis Kenzior
  2024-02-22 15:27 ` Denis Kenzior
  0 siblings, 1 reply; 2+ messages in thread
From: Denis Kenzior @ 2024-02-14 20:55 UTC (permalink / raw)
  To: iwd; +Cc: Denis Kenzior

basename use is considered harmful.  There are two versions of
basename (see man 3 basename for details).  The more intuitive version,
which is currently being used inside wiphy.c, is not supported by musl
libc implementation.  Use of the libgen version is not preferred, so
drop use of basename entirely.  Since wiphy.c is the only call site of
basename() inside iwd, open code the required logic.
---
 src/wiphy.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/wiphy.c b/src/wiphy.c
index 3258b761af15..0d64b1b31eb8 100644
--- a/src/wiphy.c
+++ b/src/wiphy.c
@@ -1896,6 +1896,7 @@ static bool wiphy_get_driver_name(struct wiphy *wiphy)
 	unsigned int j;
 	const struct l_settings *config = iwd_get_config();
 	char **flag_list;
+	char *driver;
 
 	driver_link = l_strdup_printf("/sys/class/ieee80211/%s/device/driver",
 					wiphy->name);
@@ -1907,7 +1908,9 @@ static bool wiphy_get_driver_name(struct wiphy *wiphy)
 	}
 
 	driver_path[len] = '\0';
-	wiphy->driver_str = l_strdup(basename(driver_path));
+
+	driver = memrchr(driver_path, '/', len);
+	wiphy->driver_str = l_strdup(driver ? driver + 1 : driver_path);
 
 	for (i = 0; i < L_ARRAY_SIZE(driver_infos); i++)
 		if (!fnmatch(driver_infos[i].prefix, wiphy->driver_str, 0))
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-02-22 15:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-14 20:55 [PATCH] wiphy: Remove basename() use Denis Kenzior
2024-02-22 15:27 ` Denis Kenzior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox