summaryrefslogtreecommitdiff
path: root/src/basic/escape.h
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-03-03 13:35:40 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-04-01 12:46:24 +0200
commit9e53c10a0f64bc1ab70877c245d5a8e08c509575 (patch)
treeea9f943a70e8b36df51d5d35e1ad79f549a067ef /src/basic/escape.h
parent679b0b0a21cbc14cc226c83ebe94ab2844340bc3 (diff)
downloadsystemd-9e53c10a0f64bc1ab70877c245d5a8e08c509575.tar.gz
Flagsify EscapeStyle and make ESCAPE_BACKSLASH_ONELINE implicit
I want to tweak behaviour further, and that'll be easier when "style" is converted to a bitfield. Some callers used ESCAPE_BACKSLASH_ONELINE, and others not. But the ones that didn't, simply didn't care, because the argument was assumed to be one-line anyway (e.g. a service name). In environment-generator, this could make a difference. But I think it's better to escape the newlines there too. So newlines are now always escaped, to simplify the code and the test matrix.
Diffstat (limited to 'src/basic/escape.h')
-rw-r--r--src/basic/escape.h17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/basic/escape.h b/src/basic/escape.h
index 691b6d802c..7ecae49e10 100644
--- a/src/basic/escape.h
+++ b/src/basic/escape.h
@@ -33,15 +33,12 @@ typedef enum UnescapeFlags {
UNESCAPE_ACCEPT_NUL = 1 << 1,
} UnescapeFlags;
-typedef enum EscapeStyle {
- ESCAPE_BACKSLASH = 1, /* Add shell quotes ("") so the shell will consider this a single
- argument, possibly multiline. Tabs and newlines are not escaped. */
- ESCAPE_BACKSLASH_ONELINE = 2, /* Similar to ESCAPE_BACKSLASH, but always produces a single-line
- string instead. Shell escape sequences are produced for tabs and
- newlines. */
- ESCAPE_POSIX = 3, /* Similar to ESCAPE_BACKSLASH_ONELINE, but uses POSIX shell escape
- * syntax (a string enclosed in $'') instead of plain quotes. */
-} EscapeStyle;
+typedef enum ShellEscapeFlags {
+ /* The default is to add shell quotes ("") so the shell will consider this a single argument.
+ * Tabs and newlines are escaped. */
+
+ SHELL_ESCAPE_POSIX = 1 << 1, /* Use POSIX shell escape syntax (a string enclosed in $'') instead of plain quotes. */
+} ShellEscapeFlags;
char* cescape(const char *s);
char* cescape_length(const char *s, size_t n);
@@ -64,4 +61,4 @@ char* octescape(const char *s, size_t len);
char* escape_non_printable_full(const char *str, size_t console_width, bool eight_bit);
char* shell_escape(const char *s, const char *bad);
-char* shell_maybe_quote(const char *s, EscapeStyle style);
+char* shell_maybe_quote(const char *s, ShellEscapeFlags flags);