summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2010-11-26 22:40:52 -0500
committerMike Frysinger <vapier@gentoo.org>2010-11-26 22:44:34 -0500
commit084779825d5df09130538b5e748ab0a43ee8d52d (patch)
treed121b42d2343c951cb4d8a7b82ccee6bab903827 /tests/test-skel-0.c
parentlibsandbox: fix utimensat regression with NULL filename (diff)
downloadsandbox-084779825d5df09130538b5e748ab0a43ee8d52d.tar.gz
sandbox-084779825d5df09130538b5e748ab0a43ee8d52d.tar.bz2
sandbox-084779825d5df09130538b5e748ab0a43ee8d52d.zip
tests: unify duplicated name/value lookup code
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'tests/test-skel-0.c')
-rw-r--r--tests/test-skel-0.c24
1 files changed, 8 insertions, 16 deletions
diff --git a/tests/test-skel-0.c b/tests/test-skel-0.c
index 82e346a..0907e96 100644
--- a/tests/test-skel-0.c
+++ b/tests/test-skel-0.c
@@ -9,24 +9,15 @@ const char *color_red = "\033[31;01m";
# define CONFIG 1
#endif
-struct flags {
- const char *name;
- int val;
-};
-
-static int _get_flags(const char *str_flags, const struct flags flags[], size_t num_flags)
+static int _get_flags(const char *str_flags, const value_pair flags[])
{
const char *delim = "|";
char *tok = strtok(strdup(str_flags), delim);
int ret = 0;
- size_t i;
while (tok) {
- for (i = 0; i < num_flags; ++i)
- if (!strcmp(tok, flags[i].name)) {
- ret |= flags[i].val;
- break;
- }
- if (i == num_flags) {
+ bool found;
+ ret |= _lookup_val(flags, tok, &found);
+ if (!found) {
int a;
sscanf(tok, "%i", &a);
ret |= a;
@@ -35,11 +26,10 @@ static int _get_flags(const char *str_flags, const struct flags flags[], size_t
}
return ret;
}
-#define _get_flags(s, f) _get_flags(s, f, ARRAY_SIZE(f))
int f_get_flags(const char *str_flags)
{
- const struct flags flags[] = {
+ const value_pair flags[] = {
PAIR(O_APPEND)
PAIR(O_CREAT)
PAIR(O_DIRECTORY)
@@ -50,6 +40,7 @@ int f_get_flags(const char *str_flags)
PAIR(O_RDWR)
PAIR(O_TRUNC)
PAIR(O_WRONLY)
+ { }
};
return _get_flags(str_flags, flags);
}
@@ -64,11 +55,12 @@ const char *f_get_file(const char *str_file)
int at_get_flags(const char *str_flags)
{
- const struct flags flags[] = {
+ const value_pair flags[] = {
PAIR(AT_SYMLINK_NOFOLLOW)
PAIR(AT_REMOVEDIR)
PAIR(AT_SYMLINK_FOLLOW)
PAIR(AT_EACCESS)
+ { }
};
return _get_flags(str_flags, flags);
}