]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/escape.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 This file is part of systemd.
7 Copyright 2010 Lennart Poettering
13 #include <sys/types.h>
16 #include "string-util.h"
19 /* What characters are special in the shell? */
20 /* must be escaped outside and inside double-quotes */
21 #define SHELL_NEED_ESCAPE "\"\\`$"
23 /* Those that can be escaped or double-quoted.
25 * Stricly speaking, ! does not need to be escaped, except in interactive
26 * mode, but let's be extra nice to the user and quote ! in case this
27 * output is ever used in interactive mode. */
28 #define SHELL_NEED_QUOTES SHELL_NEED_ESCAPE GLOB_CHARS "'()<>|&;!"
30 /* Note that we assume control characters would need to be escaped too in
31 * addition to the "special" characters listed here, if they appear in the
32 * string. Current users disallow control characters. Also '"' shall not
35 #define SHELL_NEED_ESCAPE_POSIX "\\\'"
37 typedef enum UnescapeFlags
{
41 typedef enum EscapeStyle
{
46 char *cescape(const char *s
);
47 char *cescape_length(const char *s
, size_t n
);
48 size_t cescape_char(char c
, char *buf
);
50 int cunescape(const char *s
, UnescapeFlags flags
, char **ret
);
51 int cunescape_length(const char *s
, size_t length
, UnescapeFlags flags
, char **ret
);
52 int cunescape_length_with_prefix(const char *s
, size_t length
, const char *prefix
, UnescapeFlags flags
, char **ret
);
53 int cunescape_one(const char *p
, size_t length
, char32_t
*ret
, bool *eight_bit
);
55 char *xescape(const char *s
, const char *bad
);
56 char *octescape(const char *s
, size_t len
);
58 char *shell_escape(const char *s
, const char *bad
);
59 char* shell_maybe_quote(const char *s
, EscapeStyle style
);