summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2020-12-14 08:17:19 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2020-12-15 18:14:47 +0100
commit9a56b87717ae6c24576b939b6484f3af175514d6 (patch)
treef77558741e45094b4884a5b1383de32cad572c86 /src
parentudev: move util_replace_whitespace() to udev-util.c (diff)
downloadsystemd-9a56b87717ae6c24576b939b6484f3af175514d6.tar.xz
systemd-9a56b87717ae6c24576b939b6484f3af175514d6.zip
udev: move util_path_encode() and rename it to escape_path()
Diffstat (limited to 'src')
-rw-r--r--src/libudev/libudev-util.c34
-rw-r--r--src/libudev/libudev-util.h1
-rw-r--r--src/udev/udev-node.c36
3 files changed, 35 insertions, 36 deletions
diff --git a/src/libudev/libudev-util.c b/src/libudev/libudev-util.c
index 45977339ac..f4f686fc88 100644
--- a/src/libudev/libudev-util.c
+++ b/src/libudev/libudev-util.c
@@ -75,40 +75,6 @@ int util_resolve_subsys_kernel(const char *string, char *result, size_t maxsize,
return 0;
}
-size_t util_path_encode(const char *src, char *dest, size_t size) {
- size_t i, j;
-
- assert(src);
- assert(dest);
-
- for (i = 0, j = 0; src[i] != '\0'; i++) {
- if (src[i] == '/') {
- if (j+4 >= size) {
- j = 0;
- break;
- }
- memcpy(&dest[j], "\\x2f", 4);
- j += 4;
- } else if (src[i] == '\\') {
- if (j+4 >= size) {
- j = 0;
- break;
- }
- memcpy(&dest[j], "\\x5c", 4);
- j += 4;
- } else {
- if (j+1 >= size) {
- j = 0;
- break;
- }
- dest[j] = src[i];
- j++;
- }
- }
- dest[j] = '\0';
- return j;
-}
-
/* allow chars in allow list, plain ascii, hex-escaping and valid utf8 */
size_t util_replace_chars(char *str, const char *allow) {
size_t i = 0, replaced = 0;
diff --git a/src/libudev/libudev-util.h b/src/libudev/libudev-util.h
index d2b22f9974..dd0561d90e 100644
--- a/src/libudev/libudev-util.h
+++ b/src/libudev/libudev-util.h
@@ -10,7 +10,6 @@
#define UTIL_NAME_SIZE 512
#define UTIL_LINE_SIZE 16384
#define UDEV_ALLOWED_CHARS_INPUT "/ $%?,"
-size_t util_path_encode(const char *src, char *dest, size_t size);
size_t util_replace_chars(char *str, const char *white);
int util_resolve_subsys_kernel(const char *string, char *result, size_t maxsize, bool read_value);
diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c
index 2cc78c9e2f..9cb78ae837 100644
--- a/src/udev/udev-node.c
+++ b/src/udev/udev-node.c
@@ -192,6 +192,40 @@ static int link_find_prioritized(sd_device *dev, bool add, const char *stackdir,
return 0;
}
+static size_t escape_path(const char *src, char *dest, size_t size) {
+ size_t i, j;
+
+ assert(src);
+ assert(dest);
+
+ for (i = 0, j = 0; src[i] != '\0'; i++) {
+ if (src[i] == '/') {
+ if (j+4 >= size) {
+ j = 0;
+ break;
+ }
+ memcpy(&dest[j], "\\x2f", 4);
+ j += 4;
+ } else if (src[i] == '\\') {
+ if (j+4 >= size) {
+ j = 0;
+ break;
+ }
+ memcpy(&dest[j], "\\x5c", 4);
+ j += 4;
+ } else {
+ if (j+1 >= size) {
+ j = 0;
+ break;
+ }
+ dest[j] = src[i];
+ j++;
+ }
+ }
+ dest[j] = '\0';
+ return j;
+}
+
/* manage "stack of names" with possibly specified device priorities */
static int link_update(sd_device *dev, const char *slink, bool add) {
_cleanup_free_ char *target = NULL, *filename = NULL, *dirname = NULL;
@@ -206,7 +240,7 @@ static int link_update(sd_device *dev, const char *slink, bool add) {
if (r < 0)
return log_device_debug_errno(dev, r, "Failed to get id_filename: %m");
- util_path_encode(slink + STRLEN("/dev"), name_enc, sizeof(name_enc));
+ escape_path(slink + STRLEN("/dev"), name_enc, sizeof(name_enc));
dirname = path_join("/run/udev/links/", name_enc);
if (!dirname)
return log_oom();