Module: xenomai-3 Branch: wip/heapmem Commit: 91ec9082982a7f42b7de7e933425b08ec9895ef2 URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=91ec9082982a7f42b7de7e933425b08ec9895ef2
Author: Philippe Gerum <r...@xenomai.org> Date: Mon Apr 23 18:29:46 2018 +0200 smokey: add helper to retrieve size expr --- include/smokey/smokey.h | 11 +++++++++++ lib/smokey/helpers.c | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/smokey/smokey.h b/include/smokey/smokey.h index ffd91cf..185fd3a 100644 --- a/include/smokey/smokey.h +++ b/include/smokey/smokey.h @@ -49,6 +49,12 @@ .matched = 0, \ } +#define SMOKEY_SIZE(__name) { \ + .name = # __name, \ + .parser = smokey_size, \ + .matched = 0, \ + } + #define SMOKEY_ARGLIST(__args...) ((struct smokey_arg[]){ __args }) #define SMOKEY_NOARGS (((struct smokey_arg[]){ { .name = NULL } })) @@ -60,6 +66,7 @@ struct smokey_arg { union { int n_val; char *s_val; + size_t l_val; } u; int matched; }; @@ -104,11 +111,13 @@ struct smokey_test { #define SMOKEY_ARG_INT(__plugin, __arg) (SMOKEY_ARG(__plugin, __arg)->u.n_val) #define SMOKEY_ARG_BOOL(__plugin, __arg) (!!SMOKEY_ARG_INT(__plugin, __arg)) #define SMOKEY_ARG_STRING(__plugin, __arg) (SMOKEY_ARG(__plugin, __arg)->u.s_val) +#define SMOKEY_ARG_SIZE(__plugin, __arg) (SMOKEY_ARG(__plugin, __arg)->u.l_val) #define smokey_arg_isset(__t, __name) (smokey_lookup_arg(__t, __name)->matched) #define smokey_arg_int(__t, __name) (smokey_lookup_arg(__t, __name)->u.n_val) #define smokey_arg_bool(__t, __name) (!!smokey_arg_int(__t, __name)) #define smokey_arg_string(__t, __name) (smokey_lookup_arg(__t, __name)->u.s_val) +#define smokey_arg_size(__t, __name) (smokey_lookup_arg(__t, __name)->u.l_val) #define smokey_check_errno(__expr) \ ({ \ @@ -216,6 +225,8 @@ int smokey_bool(const char *s, struct smokey_arg *arg); int smokey_string(const char *s, struct smokey_arg *arg); +int smokey_size(const char *s, struct smokey_arg *arg); + struct smokey_arg *smokey_lookup_arg(struct smokey_test *t, const char *arg); diff --git a/lib/smokey/helpers.c b/lib/smokey/helpers.c index fd1fca3..6ee69ec 100644 --- a/lib/smokey/helpers.c +++ b/lib/smokey/helpers.c @@ -85,6 +85,28 @@ int smokey_string(const char *s, struct smokey_arg *arg) return ret; } +int smokey_size(const char *s, struct smokey_arg *arg) +{ + char *name, *p; + int ret; + + ret = sscanf(s, "%m[_a-z]=%m[^\n]", &name, &p); + if (ret != 2) + return 0; + + ret = !strcmp(name, arg->name); + if (ret) { + arg->u.l_val = get_mem_size(p); + if (arg->u.l_val == 0) + ret = 0; + } + + free(p); + free(name); + + return ret; +} + int smokey_parse_args(struct smokey_test *t, int argc, char *const argv[]) { _______________________________________________ Xenomai-git mailing list Xenomai-git@xenomai.org https://xenomai.org/mailman/listinfo/xenomai-git