rpm  4.9.1.3
rpmutil.h
Go to the documentation of this file.
00001 #ifndef _RPMUTIL_H
00002 #define _RPMUTIL_H
00003 
00004 #include <unistd.h>
00005 
00006 /*
00007  * Miscellanous utility macros:
00008  * - portability wrappers for various gcc extensions like __attribute__()
00009  * - ...
00010  *
00011  * Copied from glib, names replaced to avoid clashing with glib.
00012  *
00013  */
00014 
00015 /* Here we provide RPM_GNUC_EXTENSION as an alias for __extension__,
00016  * where this is valid. This allows for warningless compilation of
00017  * "long long" types even in the presence of '-ansi -pedantic'. 
00018  */
00019 #if     __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
00020 #  define RPM_GNUC_EXTENSION __extension__
00021 #else
00022 #  define RPM_GNUC_EXTENSION
00023 #endif
00024 
00025 /* Provide macros to feature the GCC function attribute.
00026  */
00027 #if    __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
00028 #define RPM_GNUC_PURE                            \
00029   __attribute__((__pure__))
00030 #define RPM_GNUC_MALLOC                         \
00031   __attribute__((__malloc__))
00032 #else
00033 #define RPM_GNUC_PURE
00034 #define RPM_GNUC_MALLOC
00035 #endif
00036 
00037 #if     (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
00038 #define RPM_GNUC_ALLOC_SIZE(x) __attribute__((__alloc_size__(x)))
00039 #define RPM_GNUC_ALLOC_SIZE2(x,y) __attribute__((__alloc_size__(x,y)))
00040 #else
00041 #define RPM_GNUC_ALLOC_SIZE(x)
00042 #define RPM_GNUC_ALLOC_SIZE2(x,y)
00043 #endif
00044 
00045 #if     __GNUC__ >= 4
00046 #define RPM_GNUC_NULL_TERMINATED __attribute__((__sentinel__))
00047 #else
00048 #define RPM_GNUC_NULL_TERMINATED
00049 #endif
00050 
00051 #if     __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
00052 #define RPM_GNUC_PRINTF( format_idx, arg_idx )    \
00053   __attribute__((__format__ (__printf__, format_idx, arg_idx)))
00054 #define RPM_GNUC_SCANF( format_idx, arg_idx )     \
00055   __attribute__((__format__ (__scanf__, format_idx, arg_idx)))
00056 #define RPM_GNUC_FORMAT( arg_idx )                \
00057   __attribute__((__format_arg__ (arg_idx)))
00058 #define RPM_GNUC_NORETURN                         \
00059   __attribute__((__noreturn__))
00060 #define RPM_GNUC_CONST                            \
00061   __attribute__((__const__))
00062 #define RPM_GNUC_UNUSED                           \
00063   __attribute__((__unused__))
00064 #define RPM_GNUC_NO_INSTRUMENT                  \
00065   __attribute__((__no_instrument_function__))
00066 #else   /* !__GNUC__ */
00067 #define RPM_GNUC_PRINTF( format_idx, arg_idx )
00068 #define RPM_GNUC_SCANF( format_idx, arg_idx )
00069 #define RPM_GNUC_FORMAT( arg_idx )
00070 #define RPM_GNUC_NORETURN
00071 #define RPM_GNUC_CONST
00072 #define RPM_GNUC_UNUSED
00073 #define RPM_GNUC_NO_INSTRUMENT
00074 #endif  /* !__GNUC__ */
00075 
00076 #if    __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
00077 #define RPM_GNUC_DEPRECATED                            \
00078   __attribute__((__deprecated__))
00079 #else
00080 #define RPM_GNUC_DEPRECATED
00081 #endif /* __GNUC__ */
00082 
00083 #if     __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
00084 #define RPM_GNUC_MAY_ALIAS __attribute__((may_alias))
00085 #define RPM_GNUC_NONNULL( ... ) \
00086   __attribute__((__nonnull__ (__VA_ARGS__)))
00087 #else
00088 #define RPM_GNUC_MAY_ALIAS
00089 #define RPM_GNUC_NONNULL( ... )
00090 #endif
00091 
00092 #if    __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
00093 #define RPM_GNUC_WARN_UNUSED_RESULT             \
00094   __attribute__((warn_unused_result))
00095 #else
00096 #define RPM_GNUC_WARN_UNUSED_RESULT
00097 #endif /* __GNUC__ */
00098 
00099 #if    __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
00100 #  define RPM_GNUC_INTERNAL __attribute__((visibility("hidden")))
00101 #else
00102 #  define RPM_GNUC_INTERNAL
00103 #endif
00104 
00105 
00106 /* Guard C code in headers, while including them from C++ */
00107 #ifdef  __cplusplus
00108 # define RPM_BEGIN_DECLS  extern "C" {
00109 # define RPM_END_DECLS    }
00110 #else
00111 # define RPM_BEGIN_DECLS
00112 # define RPM_END_DECLS
00113 #endif
00114 
00115 #ifdef __cplusplus
00116 extern "C" {
00117 #endif
00118 
00119 /* Rpm specific allocators which never return NULL but terminate on failure */
00120 RPM_GNUC_MALLOC RPM_GNUC_ALLOC_SIZE(1)
00121 void * rmalloc(size_t size);
00122 
00123 RPM_GNUC_MALLOC RPM_GNUC_ALLOC_SIZE2(1,2)
00124 void * rcalloc(size_t nmemb, size_t size);
00125 
00126 RPM_GNUC_ALLOC_SIZE(2)
00127 void * rrealloc(void *ptr, size_t size);
00128 
00129 char * rstrdup(const char *str);
00130 
00131 /* Rpm specific free() which returns NULL */
00132 void * rfree(void *ptr);
00133 
00145 typedef void * (*rpmMemFailFunc) (size_t size, void *data);
00146 
00153 rpmMemFailFunc rpmSetMemFail(rpmMemFailFunc func, void *data);
00154 
00155 #ifdef __cplusplus
00156 }
00157 #endif
00158 
00159 #endif /* _RPMUTIL_H */