summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-08-09 16:49:28 +0200
committerLennart Poettering <lennart@poettering.net>2012-08-09 16:49:28 +0200
commit5b4c61cd0b7d35f5a905c83a0ee111a1876a7873 (patch)
tree08fa0dda6f66bd02adc4f2c2f9bdc7f6c7cfaab6 /src/shared/util.c
parente7573d7fa9366f72fb81e0a02d82dbb0dfd106aa (diff)
journald: properly unescape messages from /dev/kmsg
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index af975956db..946b7d53f9 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -1562,19 +1562,25 @@ char *cescape(const char *s) {
return r;
}
-char *cunescape_length(const char *s, size_t length) {
+char *cunescape_length_with_prefix(const char *s, size_t length, const char *prefix) {
char *r, *t;
const char *f;
+ size_t pl;
assert(s);
- /* Undoes C style string escaping */
+ /* Undoes C style string escaping, and optionally prefixes it. */
+
+ pl = prefix ? strlen(prefix) : 0;
- r = new(char, length+1);
+ r = new(char, pl+length+1);
if (!r)
return r;
- for (f = s, t = r; f < s + length; f++) {
+ if (prefix)
+ memcpy(r, prefix, pl);
+
+ for (f = s, t = r + pl; f < s + length; f++) {
if (*f != '\\') {
*(t++) = *f;
@@ -1685,7 +1691,13 @@ finish:
return r;
}
+char *cunescape_length(const char *s, size_t length) {
+ return cunescape_length_with_prefix(s, length, NULL);
+}
+
char *cunescape(const char *s) {
+ assert(s);
+
return cunescape_length(s, strlen(s));
}