blob: fee1cbcf907111ac17eb7a94a9ff42fca2e32321 [file] [log] [blame]
Patrick Williamsb48b7b42016-08-17 15:04:38 -05001From e56767b9caa02e7c41803499c77dc939d5a7f64a Mon Sep 17 00:00:00 2001
2From: Thorsten Glaser <tg@mirbsd.org>
3Date: Fri, 20 Jun 2014 10:56:27 +0000
4Subject: [PATCH 4/6] Restore compatibility to dietlibc, klibc, musl libc after commit 4f1b108
5
6Each C library has their own way to define off_t, and the <features.h>
7header is nonstandard and specific to the GNU libc and those that clone
8it (uClibc). Fefes dietlibc uses different flags, and klibc always uses
9a 64-bit off_t (like the BSDs); musl libc cannot be recognised using cpp
10instructions, so we assume 64 bit there (and on unknown C libraries) and
11leave it to the user to submit a follow-up fix if we guess wrong. I also
12added a static assertion to verify the 64 bit guess is correct.
13
14It would be really better using a configure script for this instead.
15
16Fixes:
17| CC lib/libmtd.o
18| In file included from ubi-utils/ubiutils-common.c:35:0:
19| ./include/common.h:29:22: fatal error: features.h: No such file or directory
20| #include <features.h>
21| ^
22| compilation terminated.
23
24Upstream-Status: Pending
25
26Signed-off-by: Thorsten Glaser <tg@mirbsd.org>
27Signed-off-by: Andrea Adami <andrea.adami@gmail.com>
28---
29 include/common.h | 24 ++++++++++++++++++++++++
30 1 file changed, 24 insertions(+)
31
32diff --git a/include/common.h b/include/common.h
33index 6895e5c..77f3f7d 100644
34--- a/include/common.h
35+++ b/include/common.h
36@@ -26,7 +26,9 @@
37 #include <string.h>
38 #include <fcntl.h>
39 #include <errno.h>
40+#if defined(__GLIBC__) || defined(__UCLIBC__)
41 #include <features.h>
42+#endif
43 #include <inttypes.h>
44 #include "version.h"
45
46@@ -52,6 +54,21 @@ extern "C" {
47 #endif
48
49 /* define a print format specifier for off_t */
50+#if defined(__KLIBC__)
51+/* always 64 bit on klibc */
52+#define PRIxoff_t PRIx64
53+#define PRIdoff_t PRId64
54+#elif defined(__dietlibc__)
55+/* depends on compiler flags on dietlibc */
56+#if defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)
57+#define PRIxoff_t PRIx64
58+#define PRIdoff_t PRId64
59+#else
60+#define PRIxoff_t "l"PRIx32
61+#define PRIdoff_t "l"PRId32
62+#endif
63+#elif defined(__GLIBC__) || defined(__UCLIBC__)
64+/* depends on compiler flags on glibc and uClibc */
65 #ifdef __USE_FILE_OFFSET64
66 #define PRIxoff_t PRIx64
67 #define PRIdoff_t PRId64
68@@ -59,6 +76,13 @@ extern "C" {
69 #define PRIxoff_t "l"PRIx32
70 #define PRIdoff_t "l"PRId32
71 #endif
72+#else
73+/* unknown libc or musl */
74+#define PRIxoff_t PRIx64
75+#define PRIdoff_t PRId64
76+/* verify our guess of 64 bit is correct */
77+static char __PRIxoff_t_static_assert[sizeof(off_t) == 8 ? 1 : -1];
78+#endif
79
80 /* Verbose messages */
81 #define bareverbose(verbose, fmt, ...) do { \
82--
831.9.1
84