[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240609141721.52344-1-jain.abhinav177@gmail.com>
Date: Sun, 9 Jun 2024 14:17:21 +0000
From: Abhinav Jain <jain.abhinav177@...il.com>
To: agk@...hat.com,
snitzer@...nel.org,
mpatocka@...hat.com,
dm-devel@...ts.linux.dev,
linux-kernel@...r.kernel.org
Cc: skhan@...uxfoundation.org,
javier.carrasco.cruz@...il.com,
jain.abhinav177@...il.com
Subject: [PATCH] dm: Add support for escaped characters in str_field_delimit()
Add a new variable for escaped characters.
If an escaped character (\) is found before the separator, and if the
separator is not found or if the escaped character is located before the
separator, then move the separator ahead and continue searching for the
next separator.
Return the pointer to remainder string after the delimiter. If the
separator was found, return a pointer to the character immediately after
the delimiter (s + 1). If the separator was not found, return NULL.
Signed-off-by: Abhinav Jain <jain.abhinav177@...il.com>
---
drivers/md/dm-init.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/drivers/md/dm-init.c b/drivers/md/dm-init.c
index 2a71bcdba92d..bef6a582a4ae 100644
--- a/drivers/md/dm-init.c
+++ b/drivers/md/dm-init.c
@@ -87,11 +87,21 @@ static void __init dm_setup_cleanup(struct list_head *devices)
*/
static char __init *str_field_delimit(char **str, char separator)
{
- char *s;
+ char *s, *escaped;
- /* TODO: add support for escaped characters */
*str = skip_spaces(*str);
s = strchr(*str, separator);
+
+ /* Check for escaped character */
+ escaped = strchr(*str, '\\');
+ if (escaped && (s == NULL || escaped < s)) {
+ /*
+ * If escaped character comes before the separator, move
+ * the separator ahead & continue searching for next one.
+ */
+ s = strchr(escaped + 1, separator);
+ }
+
/* Delimit the field and remove trailing spaces */
if (s)
*s = '\0';
--
2.34.1
Powered by blists - more mailing lists