Jorge Lucangeli Obes | a6b034d | 2012-08-07 15:29:20 -0700 | [diff] [blame^] | 1 | /* Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 2 | * Use of this source code is governed by a BSD-style license that can be |
| 3 | * found in the LICENSE file. |
| 4 | */ |
| 5 | |
| 6 | #include <ctype.h> |
| 7 | #include <string.h> |
| 8 | |
| 9 | #include "util.h" |
| 10 | |
| 11 | #include "libsyscalls.h" |
| 12 | |
| 13 | int lookup_syscall(const char *name) |
| 14 | { |
| 15 | const struct syscall_entry *entry = syscall_table; |
| 16 | for (; entry->name && entry->nr >= 0; ++entry) |
| 17 | if (!strcmp(entry->name, name)) |
| 18 | return entry->nr; |
| 19 | return -1; |
| 20 | } |
| 21 | |
| 22 | const char *lookup_syscall_name(int nr) |
| 23 | { |
| 24 | const struct syscall_entry *entry = syscall_table; |
| 25 | for (; entry->name && entry->nr >= 0; ++entry) |
| 26 | if (entry->nr == nr) |
| 27 | return entry->name; |
| 28 | return NULL; |
| 29 | } |
| 30 | |
| 31 | char *strip(char *s) |
| 32 | { |
| 33 | char *end; |
| 34 | while (*s && isblank(*s)) |
| 35 | s++; |
| 36 | end = s + strlen(s) - 1; |
| 37 | while (end >= s && *end && (isblank(*end) || *end == '\n')) |
| 38 | end--; |
| 39 | *(end + 1) = '\0'; |
| 40 | return s; |
| 41 | } |