mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-24 17:59:32 +00:00
perf string: Add {strdup,strpbrk}_esc()
To support the special characters escaped by '\' in 'perf probe' event parser. Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Reviewed-by: Thomas Richter <tmricht@linux.vnet.ibm.com> Acked-by: Ravi 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: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
4b3a2716dd
commit
1e9f9e8af0
2 changed files with 48 additions and 0 deletions
|
@ -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 */
|
||||
|
|
Loading…
Reference in a new issue