Minijail: extract utility functions.
Extract utility functions and add them, together with logging,
to a separate util.(c|h) file.
BUG=chromium-os:33361
TEST=unit tests
TEST=security_Minijail0, security_Minijail_seccomp, platform_CrosDisksArchive.
Change-Id: Ied436a7b27f14ef87198b7bf007634b28cbbd480
Reviewed-on: https://gerrit.chromium.org/gerrit/29492
Tested-by: Jorge Lucangeli Obes <[email protected]>
Reviewed-by: Elly Jones <[email protected]>
Reviewed-by: Kees Cook <[email protected]>
Commit-Ready: Jorge Lucangeli Obes <[email protected]>
diff --git a/util.c b/util.c
new file mode 100644
index 0000000..ea3c722
--- /dev/null
+++ b/util.c
@@ -0,0 +1,41 @@
+/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <ctype.h>
+#include <string.h>
+
+#include "util.h"
+
+#include "libsyscalls.h"
+
+int lookup_syscall(const char *name)
+{
+ const struct syscall_entry *entry = syscall_table;
+ for (; entry->name && entry->nr >= 0; ++entry)
+ if (!strcmp(entry->name, name))
+ return entry->nr;
+ return -1;
+}
+
+const char *lookup_syscall_name(int nr)
+{
+ const struct syscall_entry *entry = syscall_table;
+ for (; entry->name && entry->nr >= 0; ++entry)
+ if (entry->nr == nr)
+ return entry->name;
+ return NULL;
+}
+
+char *strip(char *s)
+{
+ char *end;
+ while (*s && isblank(*s))
+ s++;
+ end = s + strlen(s) - 1;
+ while (end >= s && *end && (isblank(*end) || *end == '\n'))
+ end--;
+ *(end + 1) = '\0';
+ return s;
+}