1 /**
2  * @file init.c  Main initialisation routine
3  *
4  * Copyright (C) 2010 Creytiv.com
5  */
6 #include <re_types.h>
7 #include <re_fmt.h>
8 #include <re_list.h>
9 #include <re_net.h>
10 #include <re_sys.h>
11 #include <re_main.h>
12 #include "main.h"
13 
14 
15 /**
16  * Initialise main library
17  *
18  * @return 0 if success, errorcode if failure
19  */
20 int libre_init(void)
21 {
22 	int err;
23 
24 	rand_init();
25 
26 #ifdef USE_OPENSSL
27 	err = openssl_init();
28 	if (err)
29 		goto out;
30 #endif
31 
32 	err = net_sock_init();
33 	if (err)
34 		goto out;
35 
36  out:
37 	if (err) {
38 		net_sock_close();
39 #ifdef USE_OPENSSL
40 		openssl_close();
41 #endif
42 	}
43 
44 	return err;
45 }
46 
47 
48 /**
49  * Close library and free up all resources
50  */
51 void libre_close(void)
52 {
53 	(void)fd_setsize(0);
54 	net_sock_close();
55 #ifdef USE_OPENSSL
56 	openssl_close();
57 #endif
58 }
59