1 #ifndef OPENAFS_OPR_OPR_H
2 #define OPENAFS_OPR_OPR_H 1
6 /* should use offsetof() if available */
7 #define opr_containerof(ptr, structure, member) \
8 ((structure *)((char *)(ptr)-(char *)(&((structure *)NULL)->member)))
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)
18 # define opr_abort() opr_NTAbort()
19 extern void opr_NTAbort(void);
21 # define opr_abort() abort()
24 extern void opr_AssertionFailed(const char *, int) AFS_NORETURN;
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
31 #define __opr_Assert(ex) \
32 do {if (!(ex)) opr_AssertionFailed(__FILE__, __LINE__);} while(0)
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\"") \
39 _Pragma("clang diagnostic pop")
41 # define opr_Assert(ex) __opr_Assert(ex)
44 /* opr_Verify is an assertion function which is guaranteed to always
45 * invoke its expression, regardless of the debugging level selected
48 #define __opr_Verify(ex) \
49 do {if (!(ex)) opr_AssertionFailed(__FILE__, __LINE__);} while(0)
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\"") \
56 _Pragma("clang diagnostic pop")
58 # define opr_Verify(ex) __opr_Verify(ex)
61 /* opr_StaticAssert is a static build-time assertion, to assert certain
62 * static values (such as sizeof results). If the assertion fails, the
65 #define opr_StaticAssert(ex) \
66 ((void)(sizeof(char[1 - 2 * !(ex)])))
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
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));
82 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
83 extern void opr_threadname_set(const char *threadname);
86 opr_threadname_set(const char *threadname)
94 struct opr_cache_opts {
95 afs_uint32 max_entries;
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();
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)
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);