diff options
author | Petr Machata <pmachata@redhat.com> | 2012-09-08 00:52:34 +0200 |
---|---|---|
committer | Petr Machata <pmachata@redhat.com> | 2012-09-22 15:26:38 +0200 |
commit | 64d6e060aa1d4607e766e40825bd9c9d13e8e1a4 (patch) | |
tree | be21584f4f9ddd5fc0ac8b66b716d624c3219ec0 /type.c | |
parent | e36298a706b96bfdf9335fbe8288827761d77957 (diff) | |
download | ltrace-64d6e060aa1d4607e766e40825bd9c9d13e8e1a4.tar.gz |
Add function type_aggregate_size
That to simply obtain number of elements in a structure or an array. This
is a counterpart to type_element.
Diffstat (limited to 'type.c')
-rw-r--r-- | type.c | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -460,6 +460,27 @@ type_element(struct arg_type_info *info, size_t emt) } } +size_t +type_aggregate_size(struct arg_type_info *info) +{ + assert(info->type == ARGTYPE_STRUCT + || info->type == ARGTYPE_ARRAY); + + switch (info->type) { + long ret; + case ARGTYPE_ARRAY: + if (expr_eval_constant(info->u.array_info.length, &ret) < 0) + return (size_t)-1; + return (size_t)ret; + + case ARGTYPE_STRUCT: + return type_struct_size(info); + + default: + abort(); + } +} + int type_is_integral(enum arg_type type) { |