• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 /**************************************************************************************************
3  * IOWOW library
4  *
5  * MIT License
6  *
7  * Copyright (c) 2012-2022 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 iwrc jbl_init(void);
41 
iw_init(void)42 iwrc iw_init(void) {
43   iwrc rc;
44   static int _iw_initialized = 0;
45   if (!__sync_bool_compare_and_swap(&_iw_initialized, 0, 1)) {
46     return 0;  // initialized already
47   }
48   RCC(rc, finish, iwlog_init());
49   RCC(rc, finish, iwu_init());
50   RCC(rc, finish, iwp_init());
51   RCC(rc, finish, jbl_init());
52 
53   uint64_t ts;
54   RCC(rc, finish, iwp_current_time_ms(&ts, false));
55   ts = IW_SWAB64(ts);
56   ts >>= 32;
57   iwu_rand_seed(ts);
58 
59   RCC(rc, finish, iwfs_init());
60   RCC(rc, finish, iwkv_init());
61 
62 finish:
63   return rc;
64 }
65 
iowow_version_full(void)66 const char* iowow_version_full(void) {
67   return IOWOW_VERSION;
68 }
69 
iowow_version_major(void)70 unsigned int iowow_version_major(void) {
71   return IOWOW_VERSION_MAJOR;
72 }
73 
iowow_version_minor(void)74 unsigned int iowow_version_minor(void) {
75   return IOWOW_VERSION_MINOR;
76 }
77 
iowow_version_patch(void)78 unsigned int iowow_version_patch(void) {
79   return IOWOW_VERSION_PATCH;
80 }
81