summaryrefslogtreecommitdiff
blob: f1e1d1c917166e9298abf10e55694bac6ada74b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
From 22960546489285b03857609c5c3f6c25ae91a6cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?G=C3=B6kt=C3=BCrk=20Y=C3=BCksek?= <gokturk@gentoo.org>
Date: Sun, 7 Jan 2024 16:59:09 -0800
Subject: [PATCH 1/1] Include config.h in various files before any other
 include statements
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This is an indirect way to fix a compilation failure with musl
libc. Glibc includes sys/stat.h as part of stdlib.h[1], which
eventually typedefs dev_t[2]. Musl libc doesn't seem to pull that in
like glibc does. The header file ext2fs.h uses dev_t in some of its
function signatures[3], but the inclusion of sys/types.h is guarded by
the macro `#ifdef HAVE_SYS_TYPES_H`[4].

So every time ext4magic tries to include ext2fs.h while building with musl, it fails with:

```
In file included from hard_link_stack.h:23,
from hard_link_stack.c:25:
/usr/include/ext2fs/ext2fs.h:1402:39: error: unknown type name 'dev_t'; did you mean 'div_t'?
1402 | extern char *ext2fs_find_block_device(dev_t device);
|                                       ^~~~~
|                                       div_t
/usr/include/ext2fs/ext2fs.h:1822:62: error: unknown type name 'mode_t'
1822 | extern int ext2fs_open_file(const char *pathname, int flags, mode_t mode);
|                                                              ^~~~~~
make[2]: *** [Makefile:467: ext4magic-hard_link_stack.o] Error 1
```

Autoconf actually declares HAVE_SYS_TYPES_H during ext4magic build, we
just need to include config.h in the relevant C files so that the
macro propagates. The alternative would be to pass -DHAVE_SYS_TYPES_H
to gcc but that solution seems more of a hack compared to including
config.h as it's meant to be included.

[1] https://sourceware.org/git/?p=glibc.git;a=blob;f=include/stdlib.h;h=580da9be15adf0c1034986f62dd89aaaf6498c3f;hb=HEAD#l20
[2] https://sourceware.org/git/?p=glibc.git;a=blob;f=io/sys/stat.h;h=1fa6d6e62ecb2e4b4f0039d0154307a6c27e3fa9;hb=HEAD#l40
[3] https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git/tree/lib/ext2fs/ext2fs.h#n1402
[4] https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git/tree/lib/ext2fs/ext2fs.h#n68

Bug: https://bugs.gentoo.org/716136
Signed-off-by: Göktürk Yüksek <gokturk@gentoo.org>
---
 src/block.c            | 4 ++++
 src/file_type.c        | 5 +++++
 src/hard_link_stack.c  | 4 ++++
 src/imap_search.c      | 4 ++++
 src/inode.c            | 5 +++++
 src/lookup_local.c     | 5 +++++
 src/magic_block_scan.c | 5 +++++
 src/util.c             | 5 +++++
 8 files changed, 37 insertions(+)

diff --git a/src/block.c b/src/block.c
index 84fc1bb..4681d8e 100644
--- a/src/block.c
+++ b/src/block.c
@@ -12,6 +12,10 @@
  * %End-Header%
  */
 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 /*
  This is a workaround to allow compilation, but the one line that uses
  this constant will never run because we open the fs read-only.
diff --git a/src/file_type.c b/src/file_type.c
index a1396c1..cf1790a 100644
--- a/src/file_type.c
+++ b/src/file_type.c
@@ -17,6 +17,11 @@
  *                                                                         *
  *   C Implementation: file_type                                           *
  ***************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
diff --git a/src/hard_link_stack.c b/src/hard_link_stack.c
index abef55e..df7666f 100644
--- a/src/hard_link_stack.c
+++ b/src/hard_link_stack.c
@@ -16,6 +16,10 @@
  *   along with this program; if not, see <http://www.gnu.org/licenses/>.  *
  ***************************************************************************/
 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 //construct for global collect of hardlinks
 
 #include <stdio.h>
diff --git a/src/imap_search.c b/src/imap_search.c
index 3c9c180..b8025c9 100644
--- a/src/imap_search.c
+++ b/src/imap_search.c
@@ -19,6 +19,10 @@
  * C Implementation: imap_search                                           *
  ***************************************************************************/
 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 //header  util.h
 
 #include "util.h"
diff --git a/src/inode.c b/src/inode.c
index 5cbf52e..db8c915 100644
--- a/src/inode.c
+++ b/src/inode.c
@@ -15,6 +15,11 @@
  *   You should have received a copy of the GNU General Public License     *
  *   along with this program; if not, see <http://www.gnu.org/licenses/>.  *
  ***************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
diff --git a/src/lookup_local.c b/src/lookup_local.c
index c566809..9dcd8aa 100644
--- a/src/lookup_local.c
+++ b/src/lookup_local.c
@@ -15,6 +15,11 @@
  *   You should have received a copy of the GNU General Public License     *
  *   along with this program; if not, see <http://www.gnu.org/licenses/>.  *
  ***************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 //header  util.h
 
 #include <stdio.h>
diff --git a/src/magic_block_scan.c b/src/magic_block_scan.c
index 000cf80..d0844e1 100644
--- a/src/magic_block_scan.c
+++ b/src/magic_block_scan.c
@@ -18,6 +18,11 @@
  *                                                                         *
  *   C Implementation: magic_block_scan                                    * 
  ***************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
diff --git a/src/util.c b/src/util.c
index b148baa..99a58fc 100644
--- a/src/util.c
+++ b/src/util.c
@@ -15,6 +15,11 @@
  *   You should have received a copy of the GNU General Public License     *
  *   along with this program; if not, see <http://www.gnu.org/licenses/>.  *
  ***************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
-- 
2.43.0