diff options
Diffstat (limited to 'lib/string_helpers.c')
-rw-r--r-- | lib/string_helpers.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/string_helpers.c b/lib/string_helpers.c index 29c490e5d478..3a90a9e2b94a 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c | |||
@@ -1,3 +1,4 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0-only | ||
1 | /* | 2 | /* |
2 | * Helpers for formatting and printing strings | 3 | * Helpers for formatting and printing strings |
3 | * | 4 | * |
@@ -539,6 +540,25 @@ int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, | |||
539 | } | 540 | } |
540 | EXPORT_SYMBOL(string_escape_mem); | 541 | EXPORT_SYMBOL(string_escape_mem); |
541 | 542 | ||
543 | int string_escape_mem_ascii(const char *src, size_t isz, char *dst, | ||
544 | size_t osz) | ||
545 | { | ||
546 | char *p = dst; | ||
547 | char *end = p + osz; | ||
548 | |||
549 | while (isz--) { | ||
550 | unsigned char c = *src++; | ||
551 | |||
552 | if (!isprint(c) || !isascii(c) || c == '"' || c == '\\') | ||
553 | escape_hex(c, &p, end); | ||
554 | else | ||
555 | escape_passthrough(c, &p, end); | ||
556 | } | ||
557 | |||
558 | return p - dst; | ||
559 | } | ||
560 | EXPORT_SYMBOL(string_escape_mem_ascii); | ||
561 | |||
542 | /* | 562 | /* |
543 | * Return an allocated string that has been escaped of special characters | 563 | * Return an allocated string that has been escaped of special characters |
544 | * and double quotes, making it safe to log in quotes. | 564 | * and double quotes, making it safe to log in quotes. |