From be45268352d9faeca663941141a57ef728e2fc47 Mon Sep 17 00:00:00 2001 From: Dan Streetman Date: Thu, 26 Jan 2017 14:18:10 -0500 Subject: 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. --- src/libudev/libudev-util.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/libudev/libudev-util.c') 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; -- cgit v1.2.3-54-g00ecf