11
11
* Compiler specific stuff
14
# if defined __GNUC__ && defined __GNUC_MINOR__
15
# define __GNUC_PREREQ(maj, min) \
16
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
18
# define __GNUC_PREREQ(maj, min) 0
15
24
/* &a[0] degrades to a pointer: a different type from an array */
16
25
# define __must_be_array(a) \
17
BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(typeof(a), typeof(&a[0])))
26
BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(__typeof__(a), __typeof__(&a[0])))
28
# define ignore_result(x) ({ \
29
__typeof__(x) __dummy __attribute__((__unused__)) = (x); (void) __dummy; \
19
32
#else /* !__GNUC__ */
20
33
# define __must_be_array(a) 0
21
34
# define __attribute__(_arg_)
35
# define ignore_result(x) ((void) (x))
22
36
#endif /* !__GNUC__ */
41
#ifndef __ul_alloc_size
42
# if __GNUC_PREREQ (4, 3)
43
# define __ul_alloc_size(s) __attribute__((alloc_size(s)))
45
# define __ul_alloc_size(s)
49
#ifndef __ul_calloc_size
50
# if __GNUC_PREREQ (4, 3)
51
# define __ul_calloc_size(n, s) __attribute__((alloc_size(n, s)))
53
# define __ul_calloc_size(n, s)
25
57
/* Force a compilation error if condition is true, but also produce a
26
58
* result (of value 0 and type size_t), so the expression can be used
82
# define min(x, y) ({ \
83
__typeof__(x) _min1 = (x); \
84
__typeof__(y) _min2 = (y); \
85
(void) (&_min1 == &_min2); \
86
_min1 < _min2 ? _min1 : _min2; })
90
# define max(x, y) ({ \
91
__typeof__(x) _max1 = (x); \
92
__typeof__(y) _max2 = (y); \
93
(void) (&_max1 == &_max2); \
94
_max1 > _max2 ? _max1 : _max2; })
98
static inline __attribute__((const)) int is_power_of_2(unsigned long num)
100
return (num != 0 && ((num & (num - 1)) == 0));
104
typedef int64_t loff_t;
107
#if !defined(HAVE_DIRFD) && (!defined(HAVE_DECL_DIRFD) || HAVE_DECL_DIRFD == 0) && defined(HAVE_DIR_DD_FD)
108
#include <sys/types.h>
110
static inline int dirfd(DIR *d)
116
#ifndef HAVE_PROGRAM_INVOCATION_SHORT_NAME
117
# ifdef HAVE___PROGNAME
118
extern char *__progname;
119
# define program_invocation_short_name __progname
122
# ifdef HAVE_GETEXECNAME
124
# define program_invocation_short_name \
125
prog_inv_sh_nm_from_file(getexecname(), 0)
127
# define program_invocation_short_name \
128
prog_inv_sh_nm_from_file(__FILE__, 1)
130
static char prog_inv_sh_nm_buf[256];
132
prog_inv_sh_nm_from_file(char *f, char stripext)
136
if ((t = strrchr(f, '/')) != NULL)
141
strncpy(prog_inv_sh_nm_buf, t, sizeof(prog_inv_sh_nm_buf) - 1);
142
prog_inv_sh_nm_buf[sizeof(prog_inv_sh_nm_buf) - 1] = '\0';
144
if (stripext && (t = strrchr(prog_inv_sh_nm_buf, '.')) != NULL)
147
return prog_inv_sh_nm_buf;
153
* Fallback defines for old versions of glibc
159
#ifndef AI_ADDRCONFIG
160
#define AI_ADDRCONFIG 0x0020
164
#define IUTF8 0040000
49
167
#endif /* UTIL_LINUX_C_H */