rpm 6.1.90
The RPM Package Manager
Loading...
Searching...
No Matches
rpmutil.h
Go to the documentation of this file.
1#ifndef _RPMUTIL_H
2#define _RPMUTIL_H
3
4#include <unistd.h>
5#include <rpm/rpmtypes.h>
6
16
17/* Here we provide RPM_GNUC_EXTENSION as an alias for __extension__,
18 * where this is valid. This allows for warningless compilation of
19 * "long long" types even in the presence of '-ansi -pedantic'.
20 */
21#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
22# define RPM_GNUC_EXTENSION __extension__
23#else
24# define RPM_GNUC_EXTENSION
25#endif
26
27/* Provide macros to feature the GCC function attribute.
28 */
29#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
30#define RPM_GNUC_PURE \
31 __attribute__((__pure__))
32#define RPM_GNUC_MALLOC \
33 __attribute__((__malloc__))
34#else
35#define RPM_GNUC_PURE
36#define RPM_GNUC_MALLOC
37#endif
38
39#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
40#define RPM_GNUC_ALLOC_SIZE(x) __attribute__((__alloc_size__(x)))
41#define RPM_GNUC_ALLOC_SIZE2(x,y) __attribute__((__alloc_size__(x,y)))
42#else
43#define RPM_GNUC_ALLOC_SIZE(x)
44#define RPM_GNUC_ALLOC_SIZE2(x,y)
45#endif
46
47#if __GNUC__ >= 4
48#define RPM_GNUC_NULL_TERMINATED __attribute__((__sentinel__))
49#else
50#define RPM_GNUC_NULL_TERMINATED
51#endif
52
53#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
54#define RPM_GNUC_PRINTF( format_idx, arg_idx ) \
55 __attribute__((__format__ (__printf__, format_idx, arg_idx)))
56#define RPM_GNUC_SCANF( format_idx, arg_idx ) \
57 __attribute__((__format__ (__scanf__, format_idx, arg_idx)))
58#define RPM_GNUC_FORMAT( arg_idx ) \
59 __attribute__((__format_arg__ (arg_idx)))
60#define RPM_GNUC_NORETURN \
61 __attribute__((__noreturn__))
62#define RPM_GNUC_CONST \
63 __attribute__((__const__))
64#define RPM_GNUC_UNUSED \
65 __attribute__((__unused__))
66#define RPM_GNUC_NO_INSTRUMENT \
67 __attribute__((__no_instrument_function__))
68#else /* !__GNUC__ */
69#define RPM_GNUC_PRINTF( format_idx, arg_idx )
70#define RPM_GNUC_SCANF( format_idx, arg_idx )
71#define RPM_GNUC_FORMAT( arg_idx )
72#define RPM_GNUC_NORETURN
73#define RPM_GNUC_CONST
74#define RPM_GNUC_UNUSED
75#define RPM_GNUC_NO_INSTRUMENT
76#endif /* !__GNUC__ */
77
78#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
79#define RPM_GNUC_DEPRECATED \
80 __attribute__((__deprecated__))
81#else
82#define RPM_GNUC_DEPRECATED
83#endif /* __GNUC__ */
84
85#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
86#define RPM_GNUC_MAY_ALIAS __attribute__((may_alias))
87#define RPM_GNUC_NONNULL( ... ) \
88 __attribute__((__nonnull__ (__VA_ARGS__)))
89#else
90#define RPM_GNUC_MAY_ALIAS
91#define RPM_GNUC_NONNULL( ... )
92#endif
93
94#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
95#define RPM_GNUC_WARN_UNUSED_RESULT \
96 __attribute__((warn_unused_result))
97#else
98#define RPM_GNUC_WARN_UNUSED_RESULT
99#endif /* __GNUC__ */
100
101#if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
102# define RPM_GNUC_INTERNAL __attribute__((visibility("hidden")))
103#else
104# define RPM_GNUC_INTERNAL
105#endif
106
107
108/* Guard C code in headers, while including them from C++ */
109#ifdef __cplusplus
110# define RPM_BEGIN_DECLS extern "C" {
111# define RPM_END_DECLS }
112#else
113# define RPM_BEGIN_DECLS
114# define RPM_END_DECLS
115#endif
116
117#ifdef __cplusplus
118extern "C" {
119#endif
120
121/* Rpm specific allocators which never return NULL but terminate on failure */
122RPM_GNUC_MALLOC RPM_GNUC_ALLOC_SIZE(1)
123RPM_PUBLIC_API
124void * rmalloc(size_t size);
125
126RPM_GNUC_MALLOC RPM_GNUC_ALLOC_SIZE2(1,2)
127RPM_PUBLIC_API
128void * rcalloc(size_t nmemb, size_t size);
129
130/* Like realloc() but with overflow protection */
131RPM_GNUC_MALLOC RPM_GNUC_ALLOC_SIZE2(2,3)
132RPM_PUBLIC_API
133void * rreallocn(void * ptr, size_t nmemb, size_t size);
134
135RPM_GNUC_ALLOC_SIZE(2)
136RPM_PUBLIC_API
137void * rrealloc(void *ptr, size_t size);
138
139RPM_PUBLIC_API
140char * rstrdup(const char *str);
141
142RPM_PUBLIC_API
143char * rstrndup(const char *str, size_t n);
144
145/* Rpm specific free() which returns NULL */
146RPM_PUBLIC_API
147void * rfree(void *ptr);
148
149/* Rpm specific wrappers for program name handling */
150RPM_PUBLIC_API
151const char *rgetprogname(void);
152RPM_PUBLIC_API
153void rsetprogname(const char *pn);
154
166typedef void * (*rpmMemFailFunc) (size_t size, void *data);
167
174RPM_PUBLIC_API
176
177#ifdef __cplusplus
178}
179#endif
180
181#endif /* _RPMUTIL_H */
RPM_PUBLIC_API rpmMemFailFunc rpmSetMemFail(rpmMemFailFunc func, void *data)
void *(* rpmMemFailFunc)(size_t size, void *data)
Definition rpmutil.h:166