defs.h | defs.h | |||
---|---|---|---|---|
#ifndef _LIBHX_DEFS_H | #ifndef _LIBHX_DEFS_H | |||
#define _LIBHX_DEFS_H 1 | #define _LIBHX_DEFS_H 1 | |||
#ifndef __cplusplus | #ifndef __cplusplus | |||
/* These are annotations only in C mode. */ | /* N.B. signed_cast<> does not exist in C++. */ | |||
# ifndef const_cast | # define __signed_cast_compatible(a, b) \ | |||
# define const_cast(type, expr) ((type)(expr)) | __builtin_choose_expr( \ | |||
__builtin_types_compatible_p(b, const char *) || \ | ||||
__builtin_types_compatible_p(b, const signed char *) | ||||
|| \ | ||||
__builtin_types_compatible_p(b, const unsigned char | ||||
*), \ | ||||
/* if src has a const qualifier */ \ | ||||
__builtin_types_compatible_p(a, const char *) || \ | ||||
__builtin_types_compatible_p(a, const signed char *) | ||||
|| \ | ||||
__builtin_types_compatible_p(a, const unsigned char | ||||
*), \ | ||||
/* and if it has none... */ \ | ||||
__builtin_types_compatible_p(a, char *) || \ | ||||
__builtin_types_compatible_p(a, signed char *) || \ | ||||
__builtin_types_compatible_p(a, unsigned char *) \ | ||||
) | ||||
# if defined(__GNUC__) && defined(HXDEV_EXT_CAST) | ||||
# ifndef signed_cast | ||||
# define signed_cast(type, expr) ({ \ | ||||
BUILD_BUG_ON(!__signed_cast_compatible(typeo | ||||
f(type), typeof(expr))); \ | ||||
(type)(expr); \ | ||||
}) | ||||
# endif | ||||
/* | ||||
* This one may cause shadow warnings when nested, or compil | ||||
e | ||||
* errors when used in declarations, and hence is normally | ||||
* disabled. | ||||
*/ | ||||
# ifndef static_cast | ||||
# define static_cast(type, expr) ({ \ | ||||
if (0) { typeof(type) __p __attribute__((unu | ||||
sed)) = (expr); } \ | ||||
(type)(expr); \ | ||||
}) | ||||
# endif | ||||
# endif | # endif | |||
# ifndef signed_cast | # ifndef signed_cast | |||
/* N.B. signed_cast<> does not exist in C++. */ | ||||
# define signed_cast(type, expr) ((type)(expr)) | # define signed_cast(type, expr) ((type)(expr)) | |||
# endif | # endif | |||
# ifndef static_cast | # ifndef static_cast | |||
# define static_cast(type, expr) ((type)(expr)) | # define static_cast(type, expr) ((type)(expr)) | |||
# endif | # endif | |||
# ifndef const_cast | ||||
# define const_cast(type, expr) ((type)(expr)) | ||||
# endif | ||||
# ifndef reinterpret_cast | # ifndef reinterpret_cast | |||
# define reinterpret_cast(type, expr) ((type)(expr)) | # define reinterpret_cast(type, expr) ((type)(expr)) | |||
# endif | # endif | |||
#endif | #endif | |||
#ifndef offsetof | #ifndef offsetof | |||
# define offsetof(type, member) \ | # define offsetof(type, member) \ | |||
reinterpret_cast(long, &(static_cast(type *, NULL)->member)) | reinterpret_cast(long, &(static_cast(type *, NULL)->member)) | |||
#endif | #endif | |||
#ifndef containerof | #ifndef containerof | |||
# define containerof(var, type, member) reinterpret_cast(type *, \ | # define containerof(var, type, member) reinterpret_cast(type *, \ | |||
reinterpret_cast(const char *, var) - offsetof(type, member) ) | reinterpret_cast(const char *, var) - offsetof(type, member) ) | |||
#endif | #endif | |||
#ifndef ARRAY_SIZE | #ifndef ARRAY_SIZE | |||
# define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x))) | # define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x))) | |||
End of changes. 5 change blocks. | ||||
4 lines changed or deleted | 47 lines changed or added | |||
misc.h | misc.h | |||
---|---|---|---|---|
skipping to change at line 51 | skipping to change at line 51 | |||
/* | /* | |||
* OTHER.C | * OTHER.C | |||
*/ | */ | |||
enum { | enum { | |||
HX_FSYSTEM_ARGV = 1 << 0, | HX_FSYSTEM_ARGV = 1 << 0, | |||
HX_FSYSTEM_EXEC = 1 << 1, | HX_FSYSTEM_EXEC = 1 << 1, | |||
HX_FSYSTEM_ARGV1 = 1 << 2, | HX_FSYSTEM_ARGV1 = 1 << 2, | |||
}; | }; | |||
extern int HX_ffs(unsigned long); | extern int HX_ffs(unsigned long); | |||
extern void HX_hexdump(FILE *, const void *, unsigned int); | ||||
extern void HX_zvecfree(char **); | extern void HX_zvecfree(char **); | |||
extern int HX_fsystem(unsigned int, const char *, const char *, ...); | extern int HX_fsystem(unsigned int, const char *, const char *, ...); | |||
extern int HX_vfsystem(unsigned int, const char *, const char *, va_list); | extern int HX_vfsystem(unsigned int, const char *, const char *, va_list); | |||
/* | /* | |||
* RAND.C | * RAND.C | |||
*/ | */ | |||
extern int HX_rand(void); | extern int HX_rand(void); | |||
extern unsigned int HX_irand(unsigned int, unsigned int); | extern unsigned int HX_irand(unsigned int, unsigned int); | |||
End of changes. 1 change blocks. | ||||
0 lines changed or deleted | 1 lines changed or added | |||