Skip to content

Commit eb76ca9

Browse files
grobiankarelzak
authored andcommitted
build-sys: provide alternatives for err, errx, warn and warnx
Solaris lacks err, errx, warn and warnx. This also means the err.h header doesn't exist. Removed err.h include from all files, and included err.h from c.h instead if it exists, otherwise alternatives are provided. Signed-off-by: Fabian Groffen <grobian@gentoo.org>
1 parent 4a01477 commit eb76ca9

52 files changed

Lines changed: 84 additions & 52 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

configure.ac

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ AC_CHECK_DECL([lseek64],
175175

176176
AC_CHECK_FUNCS(
177177
[inet_aton \
178+
err \
179+
errx \
178180
futimens \
179181
fstat64 \
180182
fsync \
@@ -204,6 +206,8 @@ AC_CHECK_FUNCS(
204206
posix_fadvise \
205207
getmntinfo \
206208
__secure_getenv \
209+
warn \
210+
warnx \
207211
rpmatch])
208212
AC_FUNC_FSEEKO
209213

disk-utils/swaplabel.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <sys/stat.h>
1919
#include <unistd.h>
2020
#include <stdlib.h>
21-
#include <err.h>
2221
#include <blkid.h>
2322
#include <getopt.h>
2423

include/c.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
#define UTIL_LINUX_C_H
77

88
#include <limits.h>
9+
#include <stdint.h>
10+
#include <stdio.h>
11+
#include <stdarg.h>
12+
#include <string.h>
13+
#include <errno.h>
14+
15+
#ifdef HAVE_ERR_H
16+
# include <err.h>
17+
#endif
918

1019
/*
1120
* Compiler specific stuff
@@ -95,6 +104,44 @@
95104
#endif
96105

97106

107+
#ifndef HAVE_ERR_H
108+
static inline void
109+
errmsg(char doexit, int excode, char adderr, const char *fmt, ...)
110+
{
111+
fprintf(stderr, "%s: ", program_invocation_short_name);
112+
if (fmt != NULL) {
113+
va_list argp;
114+
va_start(argp, fmt);
115+
vfprintf(stderr, fmt, argp);
116+
va_end(argp);
117+
if (adderr)
118+
fprintf(stderr, ": ");
119+
}
120+
if (adderr)
121+
fprintf(stderr, "%s", strerror(errno));
122+
fprintf(stderr, "\n");
123+
if (doexit)
124+
exit(excode);
125+
}
126+
127+
#ifndef HAVE_ERR
128+
# define err(E, FMT...) errmsg(1, E, 1, FMT)
129+
#endif
130+
131+
#ifndef HAVE_ERRX
132+
# define errx(E, FMT...) errmsg(1, E, 0, FMT)
133+
#endif
134+
135+
#ifndef HAVE_WARN
136+
# define warn(FMT...) errmsg(0, 0, 1, FMT)
137+
#endif
138+
139+
#ifndef HAVE_WARNX
140+
# define warnx(FMT...) errmsg(0, 0, 0, FMT)
141+
#endif
142+
#endif /* !HAVE_ERR_H */
143+
144+
98145
static inline __attribute__((const)) int is_power_of_2(unsigned long num)
99146
{
100147
return (num != 0 && ((num & (num - 1)) == 0));

include/xalloc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#define UTIL_LINUX_XALLOC_H
1212

1313
#include <stdlib.h>
14-
#include <err.h>
1514
#include <string.h>
1615

1716
#include "c.h"

lib/at.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <sys/stat.h>
1010

1111
#include "at.h"
12+
#include "c.h"
1213

1314
int fstat_at(int dir, const char *dirname, const char *filename,
1415
struct stat *st, int nofollow)
@@ -56,7 +57,6 @@ FILE *fopen_at(int dir, const char *dirname, const char *filename, int flags,
5657
}
5758

5859
#ifdef TEST_PROGRAM
59-
#include <err.h>
6060
#include <errno.h>
6161
#include <sys/types.h>
6262
#include <dirent.h>

lib/blkdev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "blkdev.h"
2424
#include "linux_version.h"
25+
#include "c.h"
2526

2627
static long
2728
blkdev_valid_offset (int fd, off_t offset) {
@@ -208,7 +209,6 @@ blkdev_get_sector_size(int fd, int *sector_size)
208209
#include <stdio.h>
209210
#include <stdlib.h>
210211
#include <fcntl.h>
211-
#include <err.h>
212212
int
213213
main(int argc, char **argv)
214214
{

lib/cpuset.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <sys/syscall.h>
2121

2222
#include "cpuset.h"
23+
#include "c.h"
2324

2425
static inline int val_to_char(int v)
2526
{
@@ -303,7 +304,6 @@ int cpulist_parse(const char *str, cpu_set_t *set, size_t setsize)
303304

304305
#ifdef TEST_PROGRAM
305306

306-
#include <err.h>
307307
#include <getopt.h>
308308

309309
int main(int argc, char *argv[])

lib/mangle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <ctype.h>
1212

1313
#include "mangle.h"
14+
#include "c.h"
1415

1516
#define isoctal(a) (((a) & ~7) == '0')
1617

@@ -103,7 +104,6 @@ char *unmangle(const char *s, char **end)
103104
}
104105

105106
#ifdef TEST_PROGRAM
106-
#include <err.h>
107107
#include <errno.h>
108108
int main(int argc, char *argv[])
109109
{

lib/strutils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
#include <inttypes.h>
99
#include <ctype.h>
1010
#include <errno.h>
11-
#include <err.h>
1211
#include <sys/stat.h>
1312
#include <locale.h>
1413
#include <string.h>
14+
#include "c.h"
1515

1616
static int do_scale_by_power (uintmax_t *x, int base, int power)
1717
{

lib/tt.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,6 @@ int tt_parse_columns_list(const char *list, int cols[], int *ncols,
709709
}
710710

711711
#ifdef TEST_PROGRAM
712-
#include <err.h>
713712
#include <errno.h>
714713

715714
enum { MYCOL_NAME, MYCOL_FOO, MYCOL_BAR, MYCOL_PATH };

0 commit comments

Comments
 (0)