openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/kmod/26-r0/git/tools/depmod.c
static uint32_t index_write__node(const struct index_node* node, FILE* out)
{
    uint32_t* child_offs = NULL;
    int child_count = 0;
    long offset;

    if (!node)
        return 0;

    /* Write children and save their offsets */
    if (index__haschildren(node))
    {
        const struct index_node* child;
        int i;

        child_count = node->last - node->first + 1;
        child_offs = NOFAIL(malloc(child_count * sizeof(uint32_t)));

        for (i = 0; i < child_count; i++)
        {
            child = node->children[node->first + i];
            child_offs[i] = htonl(index_write__node(child, out));
        }
    }

    /* Now write this node */
    offset = ftell(out);

    if (node->prefix[0])
    {
        fputs(node->prefix, out);
        fputc('\0', out);
        offset |= INDEX_NODE_PREFIX;
    }

    if (child_count)
    {
        fputc(node->first, out);
        fputc(node->last, out);
        fwrite(child_offs, sizeof(uint32_t), child_count, out);
        offset |= INDEX_NODE_CHILDS;
    }

    free(child_offs);

    if (node->values)
    {
        const struct index_value* v;
        unsigned int value_count;
        uint32_t u;

        value_count = 0;
        for (v = node->values; v != NULL; v = v->next)
            value_count++;
        u = htonl(value_count);
        fwrite(&u, sizeof(u), 1, out);

        for (v = node->values; v != NULL; v = v->next)
        {
            u = htonl(v->priority);
            fwrite(&u, sizeof(u), 1, out);
            fputs(v->value, out);
            fputc('\0', out);
        }
        offset |= INDEX_NODE_VALUES;
    }

    return offset;
}
/* Recursive post-order traversal

   Pre-order would make for better read-side buffering / readahead / caching.
   (post-order means you go backwards in the file as you descend the tree).
   However, index reading is already fast enough.
   Pre-order is simpler for writing, and depmod is already slow.
 */
Recursive post-order traversal
Pre-order would make for better read-side buffering / readahead / caching.
(post-order means you go backwards in the file as you descend the tree).
However, index reading is already fast enough.
Pre-order is simpler for writing, and depmod is already slow.
Recursive post - order traversal Pre - order would make for better read - side buffering / readahead / caching . ( post - order means you go backwards in the file as you descend the tree ) . However index reading is already fast enough . Pre - order is simpler for writing and depmod is already slow .
static uint32_t index_write__node(const struct index_node* node, FILE* out)
{
    uint32_t* child_offs = NULL;
    int child_count = 0;
    long offset;
    if (!node)
        return 0;
    if (index__haschildren(node))
    {
        const struct index_node* child;
        int i;
        child_count = node->last - node->first + 1;
        child_offs = NOFAIL(malloc(child_count * sizeof(uint32_t)));
        for (i = 0; i < child_count; i++)
        {
            child = node->children[node->first + i];
            child_offs[i] = htonl(index_write__node(child, out));
        }
    }
    offset = ftell(out);
    if (node->prefix[0])
    {
        fputs(node->prefix, out);
        fputc('\0', out);
        offset |= INDEX_NODE_PREFIX;
    }
    if (child_count)
    {
        fputc(node->first, out);
        fputc(node->last, out);
        fwrite(child_offs, sizeof(uint32_t), child_count, out);
        offset |= INDEX_NODE_CHILDS;
    }
    free(child_offs);
    if (node->values)
    {
        const struct index_value* v;
        unsigned int value_count;
        uint32_t u;
        value_count = 0;
        for (v = node->values; v != NULL; v = v->next)
            value_count++;
        u = htonl(value_count);
        fwrite(&u, sizeof(u), 1, out);
        for (v = node->values; v != NULL; v = v->next)
        {
            u = htonl(v->priority);
            fwrite(&u, sizeof(u), 1, out);
            fputs(v->value, out);
            fputc('\0', out);
        }
        offset |= INDEX_NODE_VALUES;
    }
    return offset;
}
static uint32_t index_write__node ( const struct index_node * node , FILE * out ) { uint32_t * child_offs = NULL ; int child_count = 0 ; long offset ; if ( ! node ) return 0 ; if ( index__haschildren ( node ) ) { const struct index_node * child ; int i ; child_count = node -> last - node -> first + 1 ; child_offs = NOFAIL ( malloc ( child_count * sizeof ( uint32_t ) ) ) ; for ( i = 0 ; i < child_count ; i ++ ) { child = node -> children [ node -> first + i ] ; child_offs [ i ] = htonl ( index_write__node ( child , out ) ) ; } } offset = ftell ( out ) ; if ( node -> prefix [ 0 ] ) { fputs ( node -> prefix , out ) ; fputc ( ' \0 ' , out ) ; offset |= INDEX_NODE_PREFIX ; } if ( child_count ) { fputc ( node -> first , out ) ; fputc ( node -> last , out ) ; fwrite ( child_offs , sizeof ( uint32_t ) , child_count , out ) ; offset |= INDEX_NODE_CHILDS ; } free ( child_offs ) ; if ( node -> values ) { const struct index_value * v ; unsigned int value_count ; uint32_t u ; value_count = 0 ; for ( v = node -> values ; v != NULL ; v = v -> next ) value_count ++ ; u = htonl ( value_count ) ; fwrite ( & u , sizeof ( u ) , 1 , out ) ; for ( v = node -> values ; v != NULL ; v = v -> next ) { u = htonl ( v -> priority ) ; fwrite ( & u , sizeof ( u ) , 1 , out ) ; fputs ( v -> value , out ) ; fputc ( ' \0 ' , out ) ; } offset |= INDEX_NODE_VALUES ; } return offset ; }
Recursive post-order traversal
Pre-order would make for better read-side buffering / readahead / caching.
Recursive post - order traversal Pre - order would make for better read - side buffering / readahead / caching .
/* Write children and save their offsets */ /* Now write this node */