]> git.proxmox.com Git - ceph.git/blob - ceph/src/pmdk/src/libpmemobj/libpmemobj.c
import ceph 16.2.7
[ceph.git] / ceph / src / pmdk / src / libpmemobj / libpmemobj.c
1 // SPDX-License-Identifier: BSD-3-Clause
2 /* Copyright 2014-2017, Intel Corporation */
3
4 /*
5 * libpmemobj.c -- pmem entry points for libpmemobj
6 */
7
8 #include "pmemcommon.h"
9 #include "obj.h"
10
11 /*
12 * libpmemobj_init -- load-time initialization for obj
13 *
14 * Called automatically by the run-time loader.
15 */
16 ATTR_CONSTRUCTOR
17 void
18 libpmemobj_init(void)
19 {
20 common_init(PMEMOBJ_LOG_PREFIX, PMEMOBJ_LOG_LEVEL_VAR,
21 PMEMOBJ_LOG_FILE_VAR, PMEMOBJ_MAJOR_VERSION,
22 PMEMOBJ_MINOR_VERSION);
23 LOG(3, NULL);
24 obj_init();
25 }
26
27 /*
28 * libpmemobj_fini -- libpmemobj cleanup routine
29 *
30 * Called automatically when the process terminates.
31 */
32 ATTR_DESTRUCTOR
33 void
34 libpmemobj_fini(void)
35 {
36 LOG(3, NULL);
37 obj_fini();
38 common_fini();
39 }
40
41 /*
42 * pmemobj_check_versionU -- see if lib meets application version requirements
43 */
44 #ifndef _WIN32
45 static inline
46 #endif
47 const char *
48 pmemobj_check_versionU(unsigned major_required, unsigned minor_required)
49 {
50 LOG(3, "major_required %u minor_required %u",
51 major_required, minor_required);
52
53 if (major_required != PMEMOBJ_MAJOR_VERSION) {
54 ERR("libpmemobj major version mismatch (need %u, found %u)",
55 major_required, PMEMOBJ_MAJOR_VERSION);
56 return out_get_errormsg();
57 }
58
59 if (minor_required > PMEMOBJ_MINOR_VERSION) {
60 ERR("libpmemobj minor version mismatch (need %u, found %u)",
61 minor_required, PMEMOBJ_MINOR_VERSION);
62 return out_get_errormsg();
63 }
64
65 return NULL;
66 }
67
68 #ifndef _WIN32
69 /*
70 * pmemobj_check_version -- see if lib meets application version requirements
71 */
72 const char *
73 pmemobj_check_version(unsigned major_required, unsigned minor_required)
74 {
75 return pmemobj_check_versionU(major_required, minor_required);
76 }
77 #else
78 /*
79 * pmemobj_check_versionW -- see if lib meets application version requirements
80 */
81 const wchar_t *
82 pmemobj_check_versionW(unsigned major_required, unsigned minor_required)
83 {
84 if (pmemobj_check_versionU(major_required, minor_required) != NULL)
85 return out_get_errormsgW();
86 else
87 return NULL;
88 }
89 #endif
90
91 /*
92 * pmemobj_set_funcs -- allow overriding libpmemobj's call to malloc, etc.
93 */
94 void
95 pmemobj_set_funcs(
96 void *(*malloc_func)(size_t size),
97 void (*free_func)(void *ptr),
98 void *(*realloc_func)(void *ptr, size_t size),
99 char *(*strdup_func)(const char *s))
100 {
101 LOG(3, NULL);
102
103 util_set_alloc_funcs(malloc_func, free_func, realloc_func, strdup_func);
104 }
105
106 /*
107 * pmemobj_errormsgU -- return last error message
108 */
109 #ifndef _WIN32
110 static inline
111 #endif
112 const char *
113 pmemobj_errormsgU(void)
114 {
115 return out_get_errormsg();
116 }
117
118 #ifndef _WIN32
119 /*
120 * pmemobj_errormsg -- return last error message
121 */
122 const char *
123 pmemobj_errormsg(void)
124 {
125 return pmemobj_errormsgU();
126 }
127 #else
128 /*
129 * pmemobj_errormsgW -- return last error message as wchar_t
130 */
131 const wchar_t *
132 pmemobj_errormsgW(void)
133 {
134 return out_get_errormsgW();
135 }
136 #endif