]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/escape.h
45e23d0651bf5c40bd3b7e3dae5f7015a1f514e3
1 /* SPDX-License-Identifier: LGPL-2.1+ */
10 #include "string-util.h"
11 #include "missing_type.h"
13 /* What characters are special in the shell? */
14 /* must be escaped outside and inside double-quotes */
15 #define SHELL_NEED_ESCAPE "\"\\`$"
17 /* Those that can be escaped or double-quoted.
19 * Stricly speaking, ! does not need to be escaped, except in interactive
20 * mode, but let's be extra nice to the user and quote ! in case this
21 * output is ever used in interactive mode. */
22 #define SHELL_NEED_QUOTES SHELL_NEED_ESCAPE GLOB_CHARS "'()<>|&;!"
24 /* Note that we assume control characters would need to be escaped too in
25 * addition to the "special" characters listed here, if they appear in the
26 * string. Current users disallow control characters. Also '"' shall not
29 #define SHELL_NEED_ESCAPE_POSIX "\\\'"
31 typedef enum UnescapeFlags
{
35 typedef enum EscapeStyle
{
40 char *cescape(const char *s
);
41 char *cescape_length(const char *s
, size_t n
);
42 int cescape_char(char c
, char *buf
);
44 int cunescape(const char *s
, UnescapeFlags flags
, char **ret
);
45 int cunescape_length(const char *s
, size_t length
, UnescapeFlags flags
, char **ret
);
46 int cunescape_length_with_prefix(const char *s
, size_t length
, const char *prefix
, UnescapeFlags flags
, char **ret
);
47 int cunescape_one(const char *p
, size_t length
, char32_t
*ret
, bool *eight_bit
);
49 char *xescape_full(const char *s
, const char *bad
, size_t console_width
, bool eight_bits
);
50 static inline char *xescape(const char *s
, const char *bad
) {
51 return xescape_full(s
, bad
, SIZE_MAX
, false);
53 char *octescape(const char *s
, size_t len
);
55 char *shell_escape(const char *s
, const char *bad
);
56 char* shell_maybe_quote(const char *s
, EscapeStyle style
);