]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/escape.h
Add 8bit-version of get_process_cmdline() and use in cgroup-show.c
[thirdparty/systemd.git] / src / basic / escape.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
4f5dd394
LP
2#pragma once
3
4f5dd394 4#include <inttypes.h>
11c3a366
TA
5#include <stddef.h>
6#include <stdint.h>
71d35b6b 7#include <sys/types.h>
c932fb71 8#include <uchar.h>
4f5dd394 9
11c3a366 10#include "string-util.h"
38e0c63d 11#include "missing_type.h"
11c3a366 12
4f5dd394
LP
13/* What characters are special in the shell? */
14/* must be escaped outside and inside double-quotes */
15#define SHELL_NEED_ESCAPE "\"\\`$"
804ee07c
ZJS
16
17/* Those that can be escaped or double-quoted.
18 *
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 "'()<>|&;!"
23
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
27 * be escaped.
28 */
29#define SHELL_NEED_ESCAPE_POSIX "\\\'"
4f5dd394
LP
30
31typedef enum UnescapeFlags {
32 UNESCAPE_RELAX = 1,
33} UnescapeFlags;
34
804ee07c
ZJS
35typedef enum EscapeStyle {
36 ESCAPE_BACKSLASH = 1,
37 ESCAPE_POSIX = 2,
38} EscapeStyle;
39
4f5dd394 40char *cescape(const char *s);
a5ef3638 41char *cescape_length(const char *s, size_t n);
b778252b 42int cescape_char(char c, char *buf);
4f5dd394
LP
43
44int cunescape(const char *s, UnescapeFlags flags, char **ret);
45int cunescape_length(const char *s, size_t length, UnescapeFlags flags, char **ret);
46int cunescape_length_with_prefix(const char *s, size_t length, const char *prefix, UnescapeFlags flags, char **ret);
c932fb71 47int cunescape_one(const char *p, size_t length, char32_t *ret, bool *eight_bit);
4f5dd394 48
70d55819
ZJS
49char *xescape_full(const char *s, const char *bad, size_t console_width, bool eight_bits);
50static inline char *xescape(const char *s, const char *bad) {
51 return xescape_full(s, bad, SIZE_MAX, false);
52}
95052df3 53char *octescape(const char *s, size_t len);
e3b4efd2 54char *escape_non_printable_full(const char *str, size_t console_width, bool eight_bit);
4f5dd394
LP
55
56char *shell_escape(const char *s, const char *bad);
804ee07c 57char* shell_maybe_quote(const char *s, EscapeStyle style);