1 //
2 /**************************************************************************************************
3 * IOWOW library
4 *
5 * MIT License
6 *
7 * Copyright (c) 2012-2020 Softmotions Ltd <info@softmotions.com>
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in all
17 * copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 *************************************************************************************************/
27
28
29 #include "iwcfg.h"
30 #include "log/iwlog.h"
31 #include "iwutils.h"
32 #include "iwp.h"
33
34 // Hardcoded requirements (fixme)
35 // CMakeLists.txt defines: -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64
36 static_assert(sizeof(off_t) == 8, "sizeof(off_t) == 8 bytes");
37
38 iwrc iwfs_init(void);
39 iwrc iwkv_init(void);
40
iw_init(void)41 iwrc iw_init(void) {
42 iwrc rc;
43 static int _iw_initialized = 0;
44 if (!__sync_bool_compare_and_swap(&_iw_initialized, 0, 1)) {
45 return 0; // initialized already
46 }
47 rc = iwlog_init();
48 RCGO(rc, finish);
49
50 rc = iwu_init();
51 RCGO(rc, finish);
52
53 rc = iwp_init();
54 RCGO(rc, finish);
55
56 uint64_t ts;
57 rc = iwp_current_time_ms(&ts, false);
58 RCRET(rc);
59 ts = IW_SWAB64(ts);
60 ts >>= 32;
61 iwu_rand_seed(ts);
62
63 rc = iwfs_init();
64 RCGO(rc, finish);
65
66 rc = iwkv_init();
67 RCGO(rc, finish);
68
69 finish:
70 return rc;
71 }
72
iowow_version_full(void)73 const char *iowow_version_full(void) {
74 return IOWOW_VERSION;
75 }
76
iowow_version_major(void)77 unsigned int iowow_version_major(void) {
78 return IOWOW_VERSION_MAJOR;
79 }
80
iowow_version_minor(void)81 unsigned int iowow_version_minor(void) {
82 return IOWOW_VERSION_MINOR;
83 }
84
iowow_version_patch(void)85 unsigned int iowow_version_patch(void) {
86 return IOWOW_VERSION_PATCH;
87 }
88