diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-04-11 11:25:37 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-09-03 05:01:51 +0900 |
commit | b9168275c39a190441fee73ba1c8a64515fd3b0e (patch) | |
tree | 821ecedadf750e513604741f8d82faf9e2527b40 /src | |
parent | d96c7550a0df529180ce5bbfa550578a219926fb (diff) | |
download | systemd-b9168275c39a190441fee73ba1c8a64515fd3b0e.tar.gz |
udev: move udev_node_escape_path()
No functionality is changed.
Diffstat (limited to 'src')
-rw-r--r-- | src/udev/udev-node.c | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c index bb34977d97..79d050cce6 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -222,48 +222,6 @@ static int link_find_prioritized(sd_device *dev, bool add, const char *stackdir, return !!*ret; } -size_t udev_node_escape_path(const char *src, char *dest, size_t size) { - size_t i, j; - uint64_t h; - - assert(src); - assert(dest); - assert(size >= 12); - - for (i = 0, j = 0; src[i] != '\0'; i++) { - if (src[i] == '/') { - if (j+4 >= size - 12 + 1) - goto toolong; - memcpy(&dest[j], "\\x2f", 4); - j += 4; - } else if (src[i] == '\\') { - if (j+4 >= size - 12 + 1) - goto toolong; - memcpy(&dest[j], "\\x5c", 4); - j += 4; - } else { - if (j+1 >= size - 12 + 1) - goto toolong; - dest[j] = src[i]; - j++; - } - } - dest[j] = '\0'; - return j; - -toolong: - /* If the input path is too long to encode as a filename, then let's suffix with a string - * generated from the hash of the path. */ - - h = siphash24_string(src, UDEV_NODE_HASH_KEY.bytes); - - for (unsigned k = 0; k <= 10; k++) - dest[size - k - 2] = urlsafe_base64char((h >> (k * 6)) & 63); - - dest[size - 1] = '\0'; - return size - 1; -} - static int update_timestamp(sd_device *dev, const char *path, struct stat *prev) { assert(path); assert(prev); @@ -414,6 +372,48 @@ static int update_stack_directory(sd_device *dev, const char *dirname, bool add) return log_device_debug_errno(dev, SYNTHETIC_ERRNO(ELOOP), "Failed to create symbolic link %s: %m", filename); } +size_t udev_node_escape_path(const char *src, char *dest, size_t size) { + size_t i, j; + uint64_t h; + + assert(src); + assert(dest); + assert(size >= 12); + + for (i = 0, j = 0; src[i] != '\0'; i++) { + if (src[i] == '/') { + if (j+4 >= size - 12 + 1) + goto toolong; + memcpy(&dest[j], "\\x2f", 4); + j += 4; + } else if (src[i] == '\\') { + if (j+4 >= size - 12 + 1) + goto toolong; + memcpy(&dest[j], "\\x5c", 4); + j += 4; + } else { + if (j+1 >= size - 12 + 1) + goto toolong; + dest[j] = src[i]; + j++; + } + } + dest[j] = '\0'; + return j; + +toolong: + /* If the input path is too long to encode as a filename, then let's suffix with a string + * generated from the hash of the path. */ + + h = siphash24_string(src, UDEV_NODE_HASH_KEY.bytes); + + for (unsigned k = 0; k <= 10; k++) + dest[size - k - 2] = urlsafe_base64char((h >> (k * 6)) & 63); + + dest[size - 1] = '\0'; + return size - 1; +} + /* manage "stack of names" with possibly specified device priorities */ static int link_update(sd_device *dev, const char *slink_in, bool add) { _cleanup_free_ char *slink = NULL, *dirname = NULL; |