~ubuntu-branches/ubuntu/quantal/util-linux/quantal

« back to all changes in this revision

Viewing changes to include/c.h

  • Committer: Package Import Robot
  • Author(s): Steve Langasek
  • Date: 2011-12-16 22:53:42 UTC
  • mfrom: (1.6.4) (4.5.5 sid)
  • Revision ID: package-import@ubuntu.com-20111216225342-206wz4bhvutyvx0d
Tags: 2.20.1-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Build for multiarch.
  - Add pre-depends on multiarch-support.
  - configure.ac: don't try to be clever about extracting a path name from
    $libdir to append to /usr in a way that's not overridable; instead,
    reuse the built-in configurable libexecdir.
  - Fix up the .pc.in files to know about libexecdir, so our substitutions
    don't leave us with unusable pkg-config files.
  - Install custom blkid.conf to use /dev/.blkid.tab since we don't
    expect device names to survive a reboot
  - Mention mountall(8) in fstab(5) manpages, along with its special
    options.
  - Since upstart is required in Ubuntu, the hwclock.sh init script is not
    called on startup and the hwclockfirst.sh init script is removed.
  - Drop depends on initscripts for the above.
  - Replace hwclock udev rule with an Upstart job.
  - For the case where mount is called with a directory to mount, look
    that directory up in mountall's /lib/init/fstab if we couldn't find
    it mentioned anywhere else.  This means "mount /proc", "mount /sys",
    etc. work.
  - mount.8 points to the cifs-utils package, not the obsolete smbfs one. 
  - Use canonicalize_spec in getmntdevbackward. proc should not be
    interpreted as a non-canonical-path.
* Dropped changes, superseded upstream:
  - shlibs/mount/src/tab_update.c: don't refuse to update mtab when source
    is 'none'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
#define UTIL_LINUX_C_H
7
7
 
8
8
#include <limits.h>
 
9
#include <stdint.h>
 
10
#include <stdio.h>
 
11
#include <stdarg.h>
 
12
#include <stdlib.h>
 
13
#include <string.h>
 
14
#include <errno.h>
 
15
 
 
16
#ifdef HAVE_ERR_H
 
17
# include <err.h>
 
18
#endif
9
19
 
10
20
/*
11
21
 * Compiler specific stuff
23
33
 
24
34
/* &a[0] degrades to a pointer: a different type from an array */
25
35
# define __must_be_array(a) \
26
 
        BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(__typeof__(a), __typeof__(&a[0])))
 
36
        UL_BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(__typeof__(a), __typeof__(&a[0])))
27
37
 
28
38
# define ignore_result(x) ({ \
29
39
        __typeof__(x) __dummy __attribute__((__unused__)) = (x); (void) __dummy; \
59
69
 * e.g. in a structure initializer (or where-ever else comma expressions
60
70
 * aren't permitted).
61
71
 */
62
 
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
 
72
#define UL_BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
63
73
#define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
64
74
 
65
75
#ifndef ARRAY_SIZE
94
104
        _max1 > _max2 ? _max1 : _max2; })
95
105
#endif
96
106
 
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
107
#ifndef HAVE_PROGRAM_INVOCATION_SHORT_NAME
117
108
# ifdef HAVE___PROGNAME
118
109
extern char *__progname;
119
110
#  define program_invocation_short_name __progname
120
111
# else
121
 
#  include <string.h>
122
112
#  ifdef HAVE_GETEXECNAME
123
 
#   include <stdlib.h>
124
113
#   define program_invocation_short_name \
125
114
                prog_inv_sh_nm_from_file(getexecname(), 0)
126
115
#  else
149
138
# endif
150
139
#endif
151
140
 
 
141
 
 
142
#ifndef HAVE_ERR_H
 
143
static inline void
 
144
errmsg(char doexit, int excode, char adderr, const char *fmt, ...)
 
145
{
 
146
        fprintf(stderr, "%s: ", program_invocation_short_name);
 
147
        if (fmt != NULL) {
 
148
                va_list argp;
 
149
                va_start(argp, fmt);
 
150
                vfprintf(stderr, fmt, argp);
 
151
                va_end(argp);
 
152
                if (adderr)
 
153
                        fprintf(stderr, ": ");
 
154
        }
 
155
        if (adderr)
 
156
                fprintf(stderr, "%s", strerror(errno));
 
157
        fprintf(stderr, "\n");
 
158
        if (doexit)
 
159
                exit(excode);
 
160
}
 
161
 
 
162
#ifndef HAVE_ERR
 
163
# define err(E, FMT...) errmsg(1, E, 1, FMT)
 
164
#endif
 
165
 
 
166
#ifndef HAVE_ERRX
 
167
# define errx(E, FMT...) errmsg(1, E, 0, FMT)
 
168
#endif
 
169
 
 
170
#ifndef HAVE_WARN
 
171
# define warn(FMT...) errmsg(0, 0, 1, FMT)
 
172
#endif
 
173
 
 
174
#ifndef HAVE_WARNX
 
175
# define warnx(FMT...) errmsg(0, 0, 0, FMT)
 
176
#endif
 
177
#endif /* !HAVE_ERR_H */
 
178
 
 
179
 
 
180
static inline __attribute__((const)) int is_power_of_2(unsigned long num)
 
181
{
 
182
        return (num != 0 && ((num & (num - 1)) == 0));
 
183
}
 
184
 
 
185
#ifndef HAVE_LOFF_T
 
186
typedef int64_t loff_t;
 
187
#endif
 
188
 
 
189
#if !defined(HAVE_DIRFD) && (!defined(HAVE_DECL_DIRFD) || HAVE_DECL_DIRFD == 0) && defined(HAVE_DIR_DD_FD)
 
190
#include <sys/types.h>
 
191
#include <dirent.h>
 
192
static inline int dirfd(DIR *d)
 
193
{
 
194
        return d->dd_fd;
 
195
}
 
196
#endif
 
197
 
152
198
/*
153
199
 * Fallback defines for old versions of glibc
154
200
 */
 
201
#include <fcntl.h>
155
202
#ifndef O_CLOEXEC
156
203
#define O_CLOEXEC 0
157
204
#endif
164
211
#define IUTF8 0040000
165
212
#endif
166
213
 
 
214
/*
 
215
 * scanf modifiers for "strings allocation"
 
216
 */
 
217
#ifdef HAVE_SCANF_MS_MODIFIER
 
218
#define UL_SCNsA        "%ms"
 
219
#elif defined(HAVE_SCANF_AS_MODIFIER)
 
220
#define UL_SCNsA        "%as"
 
221
#endif
 
222
 
167
223
#endif /* UTIL_LINUX_C_H */