diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-04-06 20:11:41 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-04-07 15:42:25 +0200 |
commit | 527b7a421ff3927d4f3f170b1b143452e88ae1dc (patch) | |
tree | cfb13e123c6dfd547fb005db63a480ca709b46da /src/shared/util.h | |
parent | 64f75d7a2898e0c0d2b66f93ddd34ffd345bb3c5 (diff) |
util: rework cunescape(), improve error handling
Change cunescape() to return a normal error code, so that we can
distuingish OOM errors from parse errors.
This also adds a flags parameter to control whether "relaxed" or normal
parsing shall be done. If set no parse failures are generated, and the
only reason why cunescape() can fail is OOM.
Diffstat (limited to 'src/shared/util.h')
-rw-r--r-- | src/shared/util.h | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/shared/util.h b/src/shared/util.h index 882355665c..e7a5d6366e 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -311,9 +311,14 @@ char decchar(int x) _const_; int undecchar(char c) _const_; char *cescape(const char *s); -char *cunescape(const char *s); -char *cunescape_length(const char *s, size_t length); -char *cunescape_length_with_prefix(const char *s, size_t length, const char *prefix); + +typedef enum UnescapeFlags { + UNESCAPE_RELAX = 1, +} UnescapeFlags; + +int cunescape(const char *s, UnescapeFlags flags, char **ret); +int cunescape_length(const char *s, size_t length, UnescapeFlags flags, char **ret); +int cunescape_length_with_prefix(const char *s, size_t length, const char *prefix, UnescapeFlags flags, char **ret); char *xescape(const char *s, const char *bad); @@ -1014,7 +1019,7 @@ int take_password_lock(const char *root); int is_symlink(const char *path); int is_dir(const char *path, bool follow); -typedef enum UnquoteFlags{ +typedef enum UnquoteFlags { UNQUOTE_RELAX = 1, UNQUOTE_CUNESCAPE = 2, } UnquoteFlags; |