b5bd7553679a8243f90f9ce1272853fee8aba479
[protos/libecoli.git] / lib / ecoli_init.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
3  */
4
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include <assert.h>
9
10 #include <ecoli_init.h>
11
12 static struct ec_init_list init_list = TAILQ_HEAD_INITIALIZER(init_list);
13
14 /* register an init function */
15 void ec_init_register(struct ec_init *init)
16 {
17         TAILQ_INSERT_TAIL(&init_list, init, next);
18 }
19
20 int ec_init(void)
21 {
22         struct ec_init *init;
23
24         /* XXX sort list by priority */
25
26         TAILQ_FOREACH(init, &init_list, next) {
27                 if (init->init() < 0)
28                         return -1;
29         }
30
31         return 0;
32 }