~ubuntu-branches/ubuntu/trusty/util-linux/trusty-proposed

« back to all changes in this revision

Viewing changes to include/c.h

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2011-05-11 08:38:31 UTC
  • mfrom: (1.3.10 upstream)
  • mto: (1.6.3 upstream) (4.5.5 sid)
  • mto: This revision was merged to the branch mainline in revision 82.
  • Revision ID: james.westby@ubuntu.com-20110511083831-tty7wnezw55fmrn4
ImportĀ upstreamĀ versionĀ 2.19.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
/*
11
11
 * Compiler specific stuff
12
12
 */
 
13
#ifndef __GNUC_PREREQ
 
14
# if defined __GNUC__ && defined __GNUC_MINOR__
 
15
#  define __GNUC_PREREQ(maj, min) \
 
16
        ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
 
17
# else
 
18
#  define __GNUC_PREREQ(maj, min) 0
 
19
# endif
 
20
#endif
 
21
 
13
22
#ifdef __GNUC__
14
23
 
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])))
 
27
 
 
28
# define ignore_result(x) ({ \
 
29
        __typeof__(x) __dummy __attribute__((__unused__)) = (x); (void) __dummy; \
 
30
})
18
31
 
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__ */
23
37
 
 
38
/*
 
39
 * Function attributes
 
40
 */
 
41
#ifndef __ul_alloc_size
 
42
# if __GNUC_PREREQ (4, 3)
 
43
#  define __ul_alloc_size(s) __attribute__((alloc_size(s)))
 
44
# else
 
45
#  define __ul_alloc_size(s)
 
46
# endif
 
47
#endif
 
48
 
 
49
#ifndef __ul_calloc_size
 
50
# if __GNUC_PREREQ (4, 3)
 
51
#  define __ul_calloc_size(n, s) __attribute__((alloc_size(n, s)))
 
52
# else
 
53
#  define __ul_calloc_size(n, s)
 
54
# endif
 
55
#endif
24
56
 
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
46
78
# define FALSE 0
47
79
#endif
48
80
 
 
81
#ifndef min
 
82
# define min(x, y) ({                           \
 
83
        __typeof__(x) _min1 = (x);              \
 
84
        __typeof__(y) _min2 = (y);              \
 
85
        (void) (&_min1 == &_min2);              \
 
86
        _min1 < _min2 ? _min1 : _min2; })
 
87
#endif
 
88
 
 
89
#ifndef max
 
90
# define max(x, y) ({                           \
 
91
        __typeof__(x) _max1 = (x);              \
 
92
        __typeof__(y) _max2 = (y);              \
 
93
        (void) (&_max1 == &_max2);              \
 
94
        _max1 > _max2 ? _max1 : _max2; })
 
95
#endif
 
96
 
 
97
 
 
98
static inline __attribute__((const)) int is_power_of_2(unsigned long num)
 
99
{
 
100
        return (num != 0 && ((num & (num - 1)) == 0));
 
101
}
 
102
 
 
103
#ifndef HAVE_LOFF_T
 
104
typedef int64_t loff_t;
 
105
#endif
 
106
 
 
107
#if !defined(HAVE_DIRFD) && (!defined(HAVE_DECL_DIRFD) || HAVE_DECL_DIRFD == 0) && defined(HAVE_DIR_DD_FD)
 
108
#include <sys/types.h>
 
109
#include <dirent.h>
 
110
static inline int dirfd(DIR *d)
 
111
{
 
112
        return d->dd_fd;
 
113
}
 
114
#endif
 
115
 
 
116
#ifndef HAVE_PROGRAM_INVOCATION_SHORT_NAME
 
117
# ifdef HAVE___PROGNAME
 
118
extern char *__progname;
 
119
#  define program_invocation_short_name __progname
 
120
# else
 
121
#  include <string.h>
 
122
#  ifdef HAVE_GETEXECNAME
 
123
#   include <stdlib.h>
 
124
#   define program_invocation_short_name \
 
125
                prog_inv_sh_nm_from_file(getexecname(), 0)
 
126
#  else
 
127
#   define program_invocation_short_name \
 
128
                prog_inv_sh_nm_from_file(__FILE__, 1)
 
129
#  endif
 
130
static char prog_inv_sh_nm_buf[256];
 
131
static inline char *
 
132
prog_inv_sh_nm_from_file(char *f, char stripext)
 
133
{
 
134
        char *t;
 
135
 
 
136
        if ((t = strrchr(f, '/')) != NULL)
 
137
                t++;
 
138
        else
 
139
                t = f;
 
140
 
 
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';
 
143
 
 
144
        if (stripext && (t = strrchr(prog_inv_sh_nm_buf, '.')) != NULL)
 
145
                *t = '\0';
 
146
 
 
147
        return prog_inv_sh_nm_buf;
 
148
}
 
149
# endif
 
150
#endif
 
151
 
 
152
/*
 
153
 * Fallback defines for old versions of glibc
 
154
 */
 
155
#ifndef O_CLOEXEC
 
156
#define O_CLOEXEC 0
 
157
#endif
 
158
 
 
159
#ifndef AI_ADDRCONFIG
 
160
#define AI_ADDRCONFIG 0x0020
 
161
#endif
 
162
 
 
163
#ifndef IUTF8
 
164
#define IUTF8 0040000
 
165
#endif
 
166
 
49
167
#endif /* UTIL_LINUX_C_H */