1 /*===========================================================================
2 *
3 *                            PUBLIC DOMAIN NOTICE
4 *               National Center for Biotechnology Information
5 *
6 *  This software/database is a "United States Government Work" under the
7 *  terms of the United States Copyright Act.  It was written as part of
8 *  the author's official duties as a United States Government employee and
9 *  thus cannot be copyrighted.  This software/database is freely available
10 *  to the public for use. The National Library of Medicine and the U.S.
11 *  Government have not placed any restriction on its use or reproduction.
12 *
13 *  Although all reasonable efforts have been taken to ensure the accuracy
14 *  and reliability of the software and data, the NLM and the U.S.
15 *  Government do not and cannot warrant the performance or results that
16 *  may be obtained by using this software or data. The NLM and the U.S.
17 *  Government disclaim all warranties, express or implied, including
18 *  warranties of performance, merchantability or fitness for any particular
19 *  purpose.
20 *
21 *  Please cite the author in any work or product based on this material.
22 *
23 * ===========================================================================
24 *
25 */
26 
27 #ifndef _h_kfc_defs_
28 #define _h_kfc_defs_
29 
30 #ifndef _h_kfc_callconv_
31 #include <kfc/callconv.h>
32 #endif
33 
34 #include <stdint.h>
35 #include <stddef.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include <memory.h>
39 #include <assert.h>
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #else
44 #include <stdbool.h>
45 #endif
46 
47 /*--------------------------------------------------------------------------
48  * ctx_t
49  *  a thread context block
50  */
51 typedef struct KCtx const * ctx_t;
52 
53 
54 /*--------------------------------------------------------------------------
55  * caps_t
56  *  a map of capability bits
57  */
58 typedef uint32_t caps_t;
59 
60 
61 /*--------------------------------------------------------------------------
62  * xobj_t
63  *  describes the type of object having problems
64  */
65 typedef struct { const char *name; } const xobj_t [ 1 ];
66 
67 
68 /*--------------------------------------------------------------------------
69  * xstate_t
70  *  describes the state of an object having problems
71  */
72 typedef struct { const char *name; } const xstate_t [ 1 ];
73 
74 
75 /*--------------------------------------------------------------------------
76  * xc_t
77  *  describes a class of error
78  */
79 typedef struct { const char *name; } const xc_t [ 1 ];
80 
81 
82 /*--------------------------------------------------------------------------
83  * under normal usage, the declarations below will create simple externs.
84  * however, they may be redefined to create static objects
85  */
86 #ifndef XC_DEFINE
87 
88 #define XOBJ( name, desc, rc )                  \
89     extern xobj_t name
90 #define XOBJ_EXT( name, supr, desc, rc )        \
91     extern xobj_t name
92 
93 #define XSTATE( name, desc, rc )                \
94     extern xstate_t name
95 #define XSTATE_EXT( name, supr, desc, rc )      \
96     extern xstate_t name
97 
98 #define XC( name, obj, state )                  \
99     extern xc_t name
100 #define XC_EXT( name, supr )                    \
101     extern xc_t name
102 
103 #endif /* XC_DEFINE */
104 
105 
106 /*--------------------------------------------------------------------------
107  * rc_t - VDB.2 LEGACY
108  *  upon success, all functions will return code 0
109  *  other codes indicate failure or additional status information
110  */
111 typedef uint32_t rc_t;
112 
113 
114 /*--------------------------------------------------------------------------
115  * ver_t - VDB.2 LEGACY
116  *  32 bit 3 part type
117  */
118 typedef uint32_t ver_t;
119 
120 /* GetMajor
121  *  return major component
122  */
123 #define VersionGetMajor( self ) \
124     ( ( self ) >> 24 )
125 
126 /* GetMinor
127  *  return minor component
128  */
129 #define VersionGetMinor( self ) \
130     ( ( ( self ) >> 16 ) & 0xFF )
131 
132 /* GetRelease
133  *  return release component
134  */
135 #define VersionGetRelease( self ) \
136     ( ( self ) & 0xFFFF )
137 
138 
139 /*--------------------------------------------------------------------------
140  * stringize
141  *  it is useful to be able to convert PP defines on the command line
142  */
143 #define stringize( tok ) tok_to_string ( tok )
144 #define tok_to_string( tok ) # tok
145 
146 
147 /*--------------------------------------------------------------------------
148  * NAME_VERS
149  *  synthesize versioned type and message names
150  */
151 #define NAME_VERS( name, maj_vers ) \
152     MAKE_NAME_VERS1 ( name, maj_vers )
153 #define MAKE_NAME_VERS1( name, maj_vers ) \
154     MAKE_NAME_VERS2 ( name, maj_vers )
155 #define MAKE_NAME_VERS2( name, maj_vers ) \
156     name ## _v ## maj_vers
157 
158 /*--------------------------------------------------------------------------
159  * __mod__, __file__ and __fext__
160  *  these guys are slightly different from __FILE__
161  *  and they complement __func__
162  */
163 #if ! defined __mod__ && defined __mod_name__
164 #define __mod__ stringize ( __mod_name__ )
165 #endif
166 
167 #if ! defined __file__ && defined __file_name__
168 #define __file__ stringize ( __file_name__ )
169 #endif
170 
171 #if ! defined __fext__ && defined __file_ext__
172 #define __fext__ stringize ( __file_ext__ )
173 #endif
174 
175 /*--------------------------------------------------------------------------
176  * PKGNAMESTR
177  */
178 #if ! defined PKGNAMESTR && defined PKGNAME
179 #define PKGNAMESTR stringize ( PKGNAME )
180 #endif
181 
182 /*--------------------------------------------------------------------------
183  * memcpy()
184  *  as of 11/29/2016 we are prohibiting the use of memcpy
185  *  NB - we depend upon including <string.h> BEFORE redefining
186  */
187 #undef memcpy
188 #if _DEBUGGING && LINUX
189 #define memcpy "DON'T USE MEMCPY! USE MEMMOVE INSTEAD!!"
190 #else
191 #define memcpy memmove
192 #endif
193 
194 #ifdef __cplusplus
195 }
196 #endif
197 
198 #endif /*  _h_kfc_defs_ */
199 
200