summaryrefslogtreecommitdiff
path: root/bin/systrace/util.c
diff options
context:
space:
mode:
authorJun-ichiro itojun Hagino <itojun@cvs.openbsd.org>2003-06-16 06:36:41 +0000
committerJun-ichiro itojun Hagino <itojun@cvs.openbsd.org>2003-06-16 06:36:41 +0000
commitf4fb20fba83a40f6cbc1953f195f979baeeb3740 (patch)
tree1ded07d1d5e9e60694ee565e3120445083add775 /bin/systrace/util.c
parent9edeec56abbf5950aacf46d99f21ee8bc6c2fdfc (diff)
- limited number of processes per systrace
- escape fixes for special characters markus, sturm ok. from provos
Diffstat (limited to 'bin/systrace/util.c')
-rw-r--r--bin/systrace/util.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/bin/systrace/util.c b/bin/systrace/util.c
index b6bd8b17cd2..563c2757098 100644
--- a/bin/systrace/util.c
+++ b/bin/systrace/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.9 2002/10/09 03:52:10 itojun Exp $ */
+/* $OpenBSD: util.c,v 1.10 2003/06/16 06:36:40 itojun Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
@@ -33,10 +33,42 @@
#include <string.h>
#include <ctype.h>
#include <stdio.h>
+#include <err.h>
#include "util.h"
char *
+strescape(char *str)
+{
+ static char escape[8192];
+ int i, p;
+
+ for (p = i = 0; i < strlen(str) && p < sizeof(escape) - 1; i++) {
+ char a = str[i];
+ switch (a) {
+ case '\r':
+ a = 'r';
+ goto doescape;
+ case '\n':
+ a = 'n';
+ goto doescape;
+ case '\\':
+ case '\"':
+ doescape:
+ escape[p++] = '\\';
+ if (p >= sizeof(escape) - 1)
+ errx(1, "%s: string too long: %s",
+ __func__, str);
+ default:
+ escape[p++] = a;
+ }
+ }
+
+ escape[p] = '\0';
+ return (escape);
+}
+
+char *
strrpl(char *str, size_t size, char *match, char *value)
{
char *p, *e;