summaryrefslogtreecommitdiffstats
path: root/src/shared/udev-util.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-06-23 08:58:31 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-06-23 09:02:05 +0200
commite1ecfef16f74dac23803c45f145939027e18eda9 (patch)
tree09531b77eddb5f82a77838575fae08aedcce6905 /src/shared/udev-util.c
parentsocket-util: split out checking valid character for ifname into ifname_valid_... (diff)
downloadsystemd-e1ecfef16f74dac23803c45f145939027e18eda9.tar.xz
systemd-e1ecfef16f74dac23803c45f145939027e18eda9.zip
udev-util: introduce udev_replace_ifname()
Diffstat (limited to 'src/shared/udev-util.c')
-rw-r--r--src/shared/udev-util.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/shared/udev-util.c b/src/shared/udev-util.c
index 06aede9d36..f934fc157e 100644
--- a/src/shared/udev-util.c
+++ b/src/shared/udev-util.c
@@ -18,6 +18,7 @@
#include "parse-util.h"
#include "path-util.h"
#include "signal-util.h"
+#include "socket-util.h"
#include "string-table.h"
#include "string-util.h"
#include "strxcpyx.h"
@@ -436,6 +437,22 @@ size_t udev_replace_whitespace(const char *str, char *to, size_t len) {
return j;
}
+size_t udev_replace_ifname(char *str) {
+ size_t replaced = 0;
+
+ assert(str);
+
+ /* See ifname_valid_full(). */
+
+ for (char *p = str; *p != '\0'; p++)
+ if (!ifname_valid_char(*p)) {
+ *p = '_';
+ replaced++;
+ }
+
+ return replaced;
+}
+
size_t udev_replace_chars(char *str, const char *allow) {
size_t i = 0, replaced = 0;