source: trunk/src/core/scew_extras.c @ 91

Last change on this file since 91 was 91, checked in by dkearney, 15 years ago

fixes a few things i broke with the last update,
scew_extras.o should compile ok now
change the makefile in test so it knows where to find include files properly.

File size: 1.0 KB
Line 
1#include "scew/scew.h"
2#include "scew/xelement.h"
3#include "scew/xerror.h"
4
5#include <assert.h>
6
7#include "scew_extras.h"
8
9scew_element*
10scew_element_parent(scew_element const* element)
11{
12    assert(element != NULL);
13    return element->parent;
14}
15
16scew_element**
17scew_element_list_all(scew_element const* parent, unsigned int* count)
18{
19    unsigned int curr = 0;
20    unsigned int max = 0;
21    scew_element** list = NULL;
22    scew_element* element;
23
24    assert(parent != NULL);
25    assert(count != NULL);
26
27    element = scew_element_next(parent, 0);
28    while (element)
29    {
30        if (curr >= max)
31        {
32            max = (max + 1) * 2;
33            list = (scew_element**) realloc(list,
34                                            sizeof(scew_element*) * max);
35            if (!list)
36            {
37                set_last_error(scew_error_no_memory);
38                return NULL;
39            }
40        }
41        list[curr++] = element;
42
43        element = scew_element_next(parent, element);
44    }
45
46    *count = curr;
47
48    return list;
49}
Note: See TracBrowser for help on using the repository browser.