blob: 3d5290be605f61b94fe43d68fcba6b95e3612a74 [file] [log] [blame]
James Kuszmaul82f6c042021-01-17 11:30:16 -08001/**
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 */
20int 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 */
51void libre_close(void)
52{
53 (void)fd_setsize(0);
54 net_sock_close();
55#ifdef USE_OPENSSL
56 openssl_close();
57#endif
58}