Add macro %isu_package to generate ISU Package
[platform/upstream/rpm.git] / rpmio / rpmutil.h
1 #ifndef _RPMUTIL_H
2 #define _RPMUTIL_H
3
4 #include <unistd.h>
5
6 /** \file rpmio/rpmutil.h
7  *
8  * Miscellaneous utility macros:
9  * - portability wrappers for various gcc extensions like __attribute__()
10  * - ...
11  *
12  * Copied from glib, names replaced to avoid clashing with glib.
13  *
14  */
15
16 /* Here we provide RPM_GNUC_EXTENSION as an alias for __extension__,
17  * where this is valid. This allows for warningless compilation of
18  * "long long" types even in the presence of '-ansi -pedantic'. 
19  */
20 #if     __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
21 #  define RPM_GNUC_EXTENSION __extension__
22 #else
23 #  define RPM_GNUC_EXTENSION
24 #endif
25
26 /* Provide macros to feature the GCC function attribute.
27  */
28 #if    __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
29 #define RPM_GNUC_PURE                            \
30   __attribute__((__pure__))
31 #define RPM_GNUC_MALLOC                         \
32   __attribute__((__malloc__))
33 #else
34 #define RPM_GNUC_PURE
35 #define RPM_GNUC_MALLOC
36 #endif
37
38 #if     (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
39 #define RPM_GNUC_ALLOC_SIZE(x) __attribute__((__alloc_size__(x)))
40 #define RPM_GNUC_ALLOC_SIZE2(x,y) __attribute__((__alloc_size__(x,y)))
41 #else
42 #define RPM_GNUC_ALLOC_SIZE(x)
43 #define RPM_GNUC_ALLOC_SIZE2(x,y)
44 #endif
45
46 #if     __GNUC__ >= 4
47 #define RPM_GNUC_NULL_TERMINATED __attribute__((__sentinel__))
48 #else
49 #define RPM_GNUC_NULL_TERMINATED
50 #endif
51
52 #if     __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
53 #define RPM_GNUC_PRINTF( format_idx, arg_idx )    \
54   __attribute__((__format__ (__printf__, format_idx, arg_idx)))
55 #define RPM_GNUC_SCANF( format_idx, arg_idx )     \
56   __attribute__((__format__ (__scanf__, format_idx, arg_idx)))
57 #define RPM_GNUC_FORMAT( arg_idx )                \
58   __attribute__((__format_arg__ (arg_idx)))
59 #define RPM_GNUC_NORETURN                         \
60   __attribute__((__noreturn__))
61 #define RPM_GNUC_CONST                            \
62   __attribute__((__const__))
63 #define RPM_GNUC_UNUSED                           \
64   __attribute__((__unused__))
65 #define RPM_GNUC_NO_INSTRUMENT                  \
66   __attribute__((__no_instrument_function__))
67 #else   /* !__GNUC__ */
68 #define RPM_GNUC_PRINTF( format_idx, arg_idx )
69 #define RPM_GNUC_SCANF( format_idx, arg_idx )
70 #define RPM_GNUC_FORMAT( arg_idx )
71 #define RPM_GNUC_NORETURN
72 #define RPM_GNUC_CONST
73 #define RPM_GNUC_UNUSED
74 #define RPM_GNUC_NO_INSTRUMENT
75 #endif  /* !__GNUC__ */
76
77 #if    __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
78 #define RPM_GNUC_DEPRECATED                            \
79   __attribute__((__deprecated__))
80 #else
81 #define RPM_GNUC_DEPRECATED
82 #endif /* __GNUC__ */
83
84 #if     __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
85 #define RPM_GNUC_MAY_ALIAS __attribute__((may_alias))
86 #define RPM_GNUC_NONNULL( ... ) \
87   __attribute__((__nonnull__ (__VA_ARGS__)))
88 #else
89 #define RPM_GNUC_MAY_ALIAS
90 #define RPM_GNUC_NONNULL( ... )
91 #endif
92
93 #if    __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
94 #define RPM_GNUC_WARN_UNUSED_RESULT             \
95   __attribute__((warn_unused_result))
96 #else
97 #define RPM_GNUC_WARN_UNUSED_RESULT
98 #endif /* __GNUC__ */
99
100 #if    __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
101 #  define RPM_GNUC_INTERNAL __attribute__((visibility("hidden")))
102 #else
103 #  define RPM_GNUC_INTERNAL
104 #endif
105
106
107 /* Guard C code in headers, while including them from C++ */
108 #ifdef  __cplusplus
109 # define RPM_BEGIN_DECLS  extern "C" {
110 # define RPM_END_DECLS    }
111 #else
112 # define RPM_BEGIN_DECLS
113 # define RPM_END_DECLS
114 #endif
115
116 #ifdef __cplusplus
117 extern "C" {
118 #endif
119
120 /* Rpm specific allocators which never return NULL but terminate on failure */
121 RPM_GNUC_MALLOC RPM_GNUC_ALLOC_SIZE(1)
122 void * rmalloc(size_t size);
123
124 RPM_GNUC_MALLOC RPM_GNUC_ALLOC_SIZE2(1,2)
125 void * rcalloc(size_t nmemb, size_t size);
126
127 RPM_GNUC_ALLOC_SIZE(2)
128 void * rrealloc(void *ptr, size_t size);
129
130 char * rstrdup(const char *str);
131
132 /* Rpm specific free() which returns NULL */
133 void * rfree(void *ptr);
134
135 /** \ingroup rpmutil
136  * Memory allocation failure callback prototype. When registered through
137  * rpmSetMemFail(), this gets called if memory allocation through rmalloc()
138  * and friends fails. If the application can somehow recover memory here,
139  * it can return a newly allocated memory block of requested size, otherwise
140  * it must return NULL after performing it's own shutdown deeds or 
141  * terminate itself.
142  * @param size          Size of allocation request in bytes
143  * @param data          User data (or NULL)
144  * @return              Allocated memory block of requested size or NULL
145  */
146 typedef void * (*rpmMemFailFunc) (size_t size, void *data);
147
148 /** \ingroup rpmutil
149  * Set memory allocation failure callback.
150  * @param func          Allocation failure callback function
151  * @param data          User data (or NULL)
152  * @return              Previous callback function
153  */
154 rpmMemFailFunc rpmSetMemFail(rpmMemFailFunc func, void *data);
155
156 #ifdef __cplusplus
157 }
158 #endif
159
160 #endif /* _RPMUTIL_H */