[Yaffs] [PATCH] Make ydirectenv.h work for non-glibc builds

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Michał Kępień
Date:  
To: yaffs
Subject: [Yaffs] [PATCH] Make ydirectenv.h work for non-glibc builds
The ydirectenv.h header includes yaffsfs.h. The latter needs certain
types (like dev_t or mode_t) to be defined beforehand. When building
against glibc, including stdlib.h from ydirectenv.h happens to be enough
because the former includes sys/types.h, which in turn contains the
necessary type definitions (as specified by POSIX). However, the
stdlib.h header shipped by some other C standard library implementations
(e.g. musl) does not include sys/types.h, which leads to compilation
failures.

Note that yaffsfs.h includes yportenv.h, but the latter only includes
the necessary system headers (if CONFIG_YAFFSFS_PROVIDE_VALUES is not
set) after including ydirectenv.h, which in turn includes yaffsfs.h
itself, so the required type definitions are still not available when
they are necessary.

Fix by including sys/stat.h directly from ydirectenv.h when
CONFIG_YAFFSFS_PROVIDE_VALUES is not set. Also include fcntl.h in that
case to enable pulling in the definition of loff_t when building against
musl.

Signed-off-by: Michał Kępień <>
---
Perhaps there are cleaner ways to address this issue, this one just
seemed to be one of the reasonable solutions based on my analysis of the
problem which I laid out in the commit message. It is certainly
possible that I got something wrong or missed some aspect of how the
header files are supposed to be used, in which case I apologize. All I
am 100% certain of is that build issues exist with at least musl libc.

direct/ydirectenv.h | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/direct/ydirectenv.h b/direct/ydirectenv.h
index b477343..d9259ad 100644
--- a/direct/ydirectenv.h
+++ b/direct/ydirectenv.h
@@ -25,6 +25,11 @@
#include "yaffs_osglue.h"
#include "yaffs_hweight.h"

+#ifndef CONFIG_YAFFSFS_PROVIDE_VALUES
+#include <fcntl.h>
+#include <sys/stat.h>
+#endif
+
void yaffs_bug_fn(const char *file_name, int line_no);

#define BUG() do { yaffs_bug_fn(__FILE__, __LINE__); } while (0)
--
2.33.0