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