summaryrefslogtreecommitdiff
path: root/src/libudev
diff options
context:
space:
mode:
authorDan Streetman <ddstreet@ieee.org>2017-01-26 14:18:10 -0500
committerDan Streetman <ddstreet@ieee.org>2017-01-27 07:58:00 -0500
commitbe45268352d9faeca663941141a57ef728e2fc47 (patch)
tree32f20637e5585e84fbd3295bbbfcf979ffe7be69 /src/libudev
parent0d53705b65b496f979a816a15181c5b1cda7a90f (diff)
udev-event: use in-place whitespace replacement
Instead of using a temp buffer to replace whitespace in variable substitutions, just allow util_replace_whitespace to replace in-place. Add a comment to util_replace_whitespace indicating it is used to replace in-place, to prevent accidental future breakage.
Diffstat (limited to 'src/libudev')
-rw-r--r--src/libudev/libudev-util.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libudev/libudev-util.c b/src/libudev/libudev-util.c
index a9819b9db3..1d73d8f090 100644
--- a/src/libudev/libudev-util.c
+++ b/src/libudev/libudev-util.c
@@ -161,6 +161,20 @@ void util_remove_trailing_chars(char *path, char c)
path[--len] = '\0';
}
+/*
+ * Copy from 'str' to 'to', while removing all leading and trailing whitespace,
+ * and replacing each run of consecutive whitespace with a single underscore.
+ * The chars from 'str' are copied up to the \0 at the end of the string, or
+ * at most 'len' chars. This appends \0 to 'to', at the end of the copied
+ * characters.
+ *
+ * If 'len' chars are copied into 'to', the final \0 is placed at len+1
+ * (i.e. 'to[len] = \0'), so the 'to' buffer must have at least len+1
+ * chars available.
+ *
+ * Note this may be called with 'str' == 'to', i.e. to replace whitespace
+ * in-place in a buffer. This function can handle that situation.
+ */
int util_replace_whitespace(const char *str, char *to, size_t len)
{
size_t i, j;