venus: Remove dedebug
[openafs.git] / src / opr / opr.h
1 #ifndef OPENAFS_OPR_OPR_H
2 #define OPENAFS_OPR_OPR_H 1
3
4 /* macros */
5
6 /* should use offsetof() if available */
7 #define opr_containerof(ptr, structure, member) \
8    ((structure *)((char *)(ptr)-(char *)(&((structure *)NULL)->member)))
9
10 /* assert.c */
11
12 /* A simple macro to help show the value of #define'd constants. e.g. If 'FOO'
13  * is defined as 5, then opr_stringize(FOO) expands to "5" */
14 #define opr_stringize_(s) #s
15 #define opr_stringize(s) opr_stringize_(s)
16
17 #ifdef AFS_NT40_ENV
18 # define opr_abort() opr_NTAbort()
19 extern void opr_NTAbort(void);
20 #else
21 # define opr_abort() abort()
22 #endif
23
24 extern void opr_AssertionFailed(const char *, int) AFS_NORETURN;
25
26 /* opr_Assert is designed to work in a similar way to the operating
27  * system's assert function. This means that in future, it may compile
28  * to a no-op if NDEBUG is defined
29  */
30
31 #define __opr_Assert(ex) \
32     do {if (!(ex)) opr_AssertionFailed(__FILE__, __LINE__);} while(0)
33
34 #if defined(HAVE__PRAGMA_TAUTOLOGICAL_POINTER_COMPARE) && defined(__clang__)
35 # define opr_Assert(ex) \
36     _Pragma("clang diagnostic push") \
37     _Pragma("clang diagnostic ignored \"-Wtautological-pointer-compare\"") \
38     __opr_Assert(ex) \
39     _Pragma("clang diagnostic pop")
40 #else
41 # define opr_Assert(ex) __opr_Assert(ex)
42 #endif
43
44 /* opr_Verify is an assertion function which is guaranteed to always
45  * invoke its expression, regardless of the debugging level selected
46  * at compile time */
47
48 #define __opr_Verify(ex) \
49     do {if (!(ex)) opr_AssertionFailed(__FILE__, __LINE__);} while(0)
50
51 #if defined(HAVE__PRAGMA_TAUTOLOGICAL_POINTER_COMPARE) && defined(__clang__)
52 # define opr_Verify(ex) \
53     _Pragma("clang diagnostic push") \
54     _Pragma("clang diagnostic ignored \"-Wtautological-pointer-compare\"") \
55     __opr_Verify(ex) \
56     _Pragma("clang diagnostic pop")
57 #else
58 # define opr_Verify(ex) __opr_Verify(ex)
59 #endif
60
61 /* opr_StaticAssert is a static build-time assertion, to assert certain
62  * static values (such as sizeof results). If the assertion fails, the
63  * build will fail. */
64
65 #define opr_StaticAssert(ex) \
66     ((void)(sizeof(char[1 - 2 * !(ex)])))
67
68 /* casestrcpy.c */
69 #define lcstring opr_lcstring
70 #define ucstring opr_ucstring
71 #define stolower opr_stolower
72 /* XXX str* is in the implementation namespace when <string.h> is included */
73 #define strcompose opr_strcompose
74
75 extern char *opr_lcstring(char *d, const char *s, int n) AFS_NONNULL((1,2));
76 extern char *opr_ucstring(char *d, const char *s, int n) AFS_NONNULL((1,2));
77 extern void opr_stolower(char *s) AFS_NONNULL((1));
78 extern char *opr_strcompose(char *buf, size_t len, ...) AFS_NONNULL((1));
79
80 /* threadname.c */
81
82 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
83 extern void opr_threadname_set(const char *threadname);
84 #else
85 static_inline void
86 opr_threadname_set(const char *threadname)
87 {
88     /* noop */
89 }
90 #endif
91
92 /* cache.c */
93
94 struct opr_cache_opts {
95     afs_uint32 max_entries;
96     afs_uint32 n_buckets;
97 };
98 struct opr_cache;
99
100 extern int opr_cache_init(struct opr_cache_opts *opts,
101                           struct opr_cache **a_cache) AFS_NONNULL();
102 extern void opr_cache_free(struct opr_cache **a_cache) AFS_NONNULL();
103
104 extern int opr_cache_get(struct opr_cache *cache, void *key_buf,
105                          size_t key_len, void *val_buf, size_t *a_val_len)
106                          AFS_NONNULL((4,5));
107 extern void opr_cache_put(struct opr_cache *cache, void *key_buf,
108                           size_t key_len, void *val_buf, size_t val_len);
109
110 #endif