rpm  4.11.1-rc1
rpmutil.h
Go to the documentation of this file.
1 #ifndef _RPMUTIL_H
2 #define _RPMUTIL_H
3 
4 #include <unistd.h>
5 
6 /*
7  * Miscellaneous utility macros:
8  * - portability wrappers for various gcc extensions like __attribute__()
9  * - ...
10  *
11  * Copied from glib, names replaced to avoid clashing with glib.
12  *
13  */
14 
15 /* Here we provide RPM_GNUC_EXTENSION as an alias for __extension__,
16  * where this is valid. This allows for warningless compilation of
17  * "long long" types even in the presence of '-ansi -pedantic'.
18  */
19 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
20 # define RPM_GNUC_EXTENSION __extension__
21 #else
22 # define RPM_GNUC_EXTENSION
23 #endif
24 
25 /* Provide macros to feature the GCC function attribute.
26  */
27 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
28 #define RPM_GNUC_PURE \
29  __attribute__((__pure__))
30 #define RPM_GNUC_MALLOC \
31  __attribute__((__malloc__))
32 #else
33 #define RPM_GNUC_PURE
34 #define RPM_GNUC_MALLOC
35 #endif
36 
37 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
38 #define RPM_GNUC_ALLOC_SIZE(x) __attribute__((__alloc_size__(x)))
39 #define RPM_GNUC_ALLOC_SIZE2(x,y) __attribute__((__alloc_size__(x,y)))
40 #else
41 #define RPM_GNUC_ALLOC_SIZE(x)
42 #define RPM_GNUC_ALLOC_SIZE2(x,y)
43 #endif
44 
45 #if __GNUC__ >= 4
46 #define RPM_GNUC_NULL_TERMINATED __attribute__((__sentinel__))
47 #else
48 #define RPM_GNUC_NULL_TERMINATED
49 #endif
50 
51 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
52 #define RPM_GNUC_PRINTF( format_idx, arg_idx ) \
53  __attribute__((__format__ (__printf__, format_idx, arg_idx)))
54 #define RPM_GNUC_SCANF( format_idx, arg_idx ) \
55  __attribute__((__format__ (__scanf__, format_idx, arg_idx)))
56 #define RPM_GNUC_FORMAT( arg_idx ) \
57  __attribute__((__format_arg__ (arg_idx)))
58 #define RPM_GNUC_NORETURN \
59  __attribute__((__noreturn__))
60 #define RPM_GNUC_CONST \
61  __attribute__((__const__))
62 #define RPM_GNUC_UNUSED \
63  __attribute__((__unused__))
64 #define RPM_GNUC_NO_INSTRUMENT \
65  __attribute__((__no_instrument_function__))
66 #else /* !__GNUC__ */
67 #define RPM_GNUC_PRINTF( format_idx, arg_idx )
68 #define RPM_GNUC_SCANF( format_idx, arg_idx )
69 #define RPM_GNUC_FORMAT( arg_idx )
70 #define RPM_GNUC_NORETURN
71 #define RPM_GNUC_CONST
72 #define RPM_GNUC_UNUSED
73 #define RPM_GNUC_NO_INSTRUMENT
74 #endif /* !__GNUC__ */
75 
76 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
77 #define RPM_GNUC_DEPRECATED \
78  __attribute__((__deprecated__))
79 #else
80 #define RPM_GNUC_DEPRECATED
81 #endif /* __GNUC__ */
82 
83 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
84 #define RPM_GNUC_MAY_ALIAS __attribute__((may_alias))
85 #define RPM_GNUC_NONNULL( ... ) \
86  __attribute__((__nonnull__ (__VA_ARGS__)))
87 #else
88 #define RPM_GNUC_MAY_ALIAS
89 #define RPM_GNUC_NONNULL( ... )
90 #endif
91 
92 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
93 #define RPM_GNUC_WARN_UNUSED_RESULT \
94  __attribute__((warn_unused_result))
95 #else
96 #define RPM_GNUC_WARN_UNUSED_RESULT
97 #endif /* __GNUC__ */
98 
99 #if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
100 # define RPM_GNUC_INTERNAL __attribute__((visibility("hidden")))
101 #else
102 # define RPM_GNUC_INTERNAL
103 #endif
104 
105 
106 /* Guard C code in headers, while including them from C++ */
107 #ifdef __cplusplus
108 # define RPM_BEGIN_DECLS extern "C" {
109 # define RPM_END_DECLS }
110 #else
111 # define RPM_BEGIN_DECLS
112 # define RPM_END_DECLS
113 #endif
114 
115 #ifdef __cplusplus
116 extern "C" {
117 #endif
118 
119 /* Rpm specific allocators which never return NULL but terminate on failure */
121 void * rmalloc(size_t size);
122 
124 void * rcalloc(size_t nmemb, size_t size);
125 
127 void * rrealloc(void *ptr, size_t size);
128 
129 char * rstrdup(const char *str);
130 
131 /* Rpm specific free() which returns NULL */
132 void * rfree(void *ptr);
133 
145 typedef void * (*rpmMemFailFunc) (size_t size, void *data);
146 
154 
155 #ifdef __cplusplus
156 }
157 #endif
158 
159 #endif /* _RPMUTIL_H */