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)))
13 # define opr_abort() opr_NTAbort()
14 extern void opr_NTAbort(void);
16 # define opr_abort() abort()
19 extern void opr_AssertionFailed(const char *, int) AFS_NORETURN;
20 extern void opr_AssertFailU(const char *, const char *, int) AFS_NORETURN;
22 /* opr_Assert is designed to work in a similar way to the operating
23 * system's assert function. This means that in future, it may compile
24 * to a no-op if NDEBUG is defined
27 #define __opr_Assert(ex) \
28 do {if (!(ex)) opr_AssertionFailed(__FILE__, __LINE__);} while(0)
30 #if defined(HAVE__PRAGMA_TAUTOLOGICAL_POINTER_COMPARE) && defined(__clang__)
31 # define opr_Assert(ex) \
32 _Pragma("clang diagnostic push") \
33 _Pragma("clang diagnostic ignored \"-Wtautological-pointer-compare\"") \
35 _Pragma("clang diagnostic pop")
37 # define opr_Assert(ex) __opr_Assert(ex)
40 /* opr_Verify is an assertion function which is guaranteed to always
41 * invoke its expression, regardless of the debugging level selected
44 #define __opr_Verify(ex) \
45 do {if (!(ex)) opr_AssertionFailed(__FILE__, __LINE__);} while(0)
47 #if defined(HAVE__PRAGMA_TAUTOLOGICAL_POINTER_COMPARE) && defined(__clang__)
48 # define opr_Verify(ex) \
49 _Pragma("clang diagnostic push") \
50 _Pragma("clang diagnostic ignored \"-Wtautological-pointer-compare\"") \
52 _Pragma("clang diagnostic pop")
54 # define opr_Verify(ex) __opr_Verify(ex)
58 #define lcstring opr_lcstring
59 #define ucstring opr_ucstring
60 #define stolower opr_stolower
61 #define stoupper opr_stoupper
62 /* XXX str* is in the implementation namespace when <string.h> is included */
63 #define strcompose opr_strcompose
65 extern char *opr_lcstring(char *d, const char *s, int n) AFS_NONNULL((1,2));
66 extern char *opr_ucstring(char *d, const char *s, int n) AFS_NONNULL((1,2));
67 extern void opr_stolower(char *s) AFS_NONNULL(());
68 extern void opr_stoupper(char *s) AFS_NONNULL(());
69 extern char *opr_strcompose(char *buf, size_t len, ...) AFS_NONNULL((1));