macros.h revision 664c7007d4a0116be2cce62295cd9fb9cd33eee0
#ifndef __MACROS_H
#define __MACROS_H
/* several useful macros, mostly from glib.h */
#ifndef NULL
# define NULL ((void *)0)
#endif
#ifndef FALSE
# define FALSE (0)
#endif
#ifndef TRUE
#endif
#define BITS_IN_UINT (CHAR_BIT * sizeof(unsigned int))
files that are included after this file generating tons of warnings. */
#define I_MIN(a, b) (((a) < (b)) ? (a) : (b))
#define I_MAX(a, b) (((a) > (b)) ? (a) : (b))
sizeof(size_t) == sizeof(void *) and they're both the largest datatypes
that are allowed to be used. so, long long isn't safe with these. */
#define POINTER_CAST(i) \
((void *) ((char *) NULL + (i)))
#define POINTER_CAST_TO(p, type) \
/* Define VA_COPY() to do the right thing for copying va_list variables. */
#ifndef VA_COPY
# elif defined (VA_COPY_AS_ARRAY)
# else /* va_list is a pointer */
# endif /* va_list is a pointer */
#endif
/* Provide convenience macros for handling structure
* fields through their offsets.
*/
((void *) ((char *) (struct_p) + (long) (struct_offset)))
/* Provide simple macro statement wrappers (adapted from Perl):
STMT_START { statements; } STMT_END;
can be used as a single statement, as in
if (x) STMT_START { ... } STMT_END; else ...
For gcc we will wrap the statements within `({' and `})' braces.
For SunOS they will be wrapped within `if (1)' and `else (void) 0',
and otherwise within `do' and `while (0)'. */
#if !(defined (STMT_START) && defined (STMT_END))
# define STMT_START (void)(
# define STMT_END )
# else
# define STMT_START if (1)
# define STMT_END else (void)0
# else
# define STMT_START do
# define STMT_END while (0)
# endif
# endif
#endif
/* Provide macros to feature the GCC function attribute. */
# define __attr_format_arg__(arg_idx) \
# define __attr_const__ __attribute__((const))
#else
# define __attr_format_arg__(arg_idx)
# define __attr_unused__
# define __attr_noreturn__
# define __attr_const__
# define __attr_unused__
#endif
/* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
macros, so we can refer to them as strings unconditionally. */
#ifdef __GNUC__
# define GNUC_FUNCTION __FUNCTION__
# define GNUC_PRETTY_FUNCTION __PRETTY_FUNCTION__
#else
# define GNUC_FUNCTION ""
# define GNUC_PRETTY_FUNCTION ""
#endif
/* Provide macros for error handling. */
#ifdef DISABLE_CHECKS
# define return_if_fail(expr)
if (!(expr)) \
i_panic("file %s: line %d (%s): assertion failed: (%s)", \
__FILE__, \
__LINE__, \
if (!(expr)) \
{ \
i_warning("file %s: line %d (%s): assertion `%s' failed.", \
__FILE__, \
__LINE__, \
#expr); \
return; \
}; }STMT_END
if (!(expr)) \
{ \
i_warning("file %s: line %d (%s): assertion `%s' failed.", \
__FILE__, \
__LINE__, \
#expr); \
return val; \
}; }STMT_END
#else /* !__GNUC__ */
if (!(expr)) \
i_panic("file %s: line %d: assertion failed: (%s)", \
__FILE__, \
__LINE__, \
if (!(expr)) \
{ \
i_warning("file %s: line %d: assertion `%s' failed.", \
__FILE__, \
__LINE__, \
#expr); \
return; \
}; }STMT_END
if (!(expr)) \
{ \
i_warning("file %s: line %d: assertion `%s' failed.", \
__FILE__, \
__LINE__, \
#expr); \
return val; \
}; }STMT_END
#endif
#endif