提交 1e9f9e8a 编写于 作者: M Masami Hiramatsu 提交者: Arnaldo Carvalho de Melo

perf string: Add {strdup,strpbrk}_esc()

To support the special characters escaped by '\' in 'perf probe' event parser.
Signed-off-by: NMasami Hiramatsu <mhiramat@kernel.org>
Reviewed-by: NThomas Richter <tmricht@linux.vnet.ibm.com>
Acked-by: NRavi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: bhargavb <bhargavaramudu@gmail.com>
Cc: linux-rt-users@vger.kernel.org
Link: http://lkml.kernel.org/r/151275052163.24652.18205979384585484358.stgit@devbox
[ Split from a larger patch ]
Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
上级 4b3a2716
......@@ -396,3 +396,49 @@ char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints
free(expr);
return NULL;
}
/* Like strpbrk(), but not break if it is right after a backslash (escaped) */
char *strpbrk_esc(char *str, const char *stopset)
{
char *ptr;
do {
ptr = strpbrk(str, stopset);
if (ptr == str ||
(ptr == str + 1 && *(ptr - 1) != '\\'))
break;
str = ptr + 1;
} while (ptr && *(ptr - 1) == '\\' && *(ptr - 2) != '\\');
return ptr;
}
/* Like strdup, but do not copy a single backslash */
char *strdup_esc(const char *str)
{
char *s, *d, *p, *ret = strdup(str);
if (!ret)
return NULL;
d = strchr(ret, '\\');
if (!d)
return ret;
s = d + 1;
do {
if (*s == '\0') {
*d = '\0';
break;
}
p = strchr(s + 1, '\\');
if (p) {
memmove(d, s, p - s);
d += p - s;
s = p + 1;
} else
memmove(d, s, strlen(s) + 1);
} while (p);
return ret;
}
......@@ -39,5 +39,7 @@ static inline char *asprintf_expr_not_in_ints(const char *var, size_t nints, int
return asprintf_expr_inout_ints(var, false, nints, ints);
}
char *strpbrk_esc(char *str, const char *stopset);
char *strdup_esc(const char *str);
#endif /* PERF_STRING_H */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册