linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] libgpiod: Fix build failure with musl
@ 2021-12-09 11:58 Viresh Kumar
  0 siblings, 0 replies; only message in thread
From: Viresh Kumar @ 2021-12-09 11:58 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski
  Cc: Viresh Kumar, Vincent Guittot, linux-gpio, Kent Gibson,
	Arnd Bergmann

Musl defines the _IO*() macros in the files included via <sys/ioctl.h>
and hence we get redefinition errors during build as <linux/ioctl.h>,
included via <uapi/gpio.h>, defines them again.

Fix this by undefining the macros between both the includes, document it
all in musl-compat.h as well.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
V2-> Don't undef the macros for _GNU_SOURCE.

 lib/internal.h    |  1 +
 lib/musl-compat.h | 22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+)
 create mode 100644 lib/musl-compat.h

diff --git a/lib/internal.h b/lib/internal.h
index 32f36b5cd4cf..89c94cdd8ef6 100644
--- a/lib/internal.h
+++ b/lib/internal.h
@@ -8,6 +8,7 @@
 #include <stddef.h>
 #include <stdint.h>
 
+#include "musl-compat.h"
 #include "uapi/gpio.h"
 
 /* For internal library use only. */
diff --git a/lib/musl-compat.h b/lib/musl-compat.h
new file mode 100644
index 000000000000..2c5ff1e6a6dc
--- /dev/null
+++ b/lib/musl-compat.h
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/* SPDX-FileCopyrightText: 2021 Bartosz Golaszewski <bgolaszewski@baylibre.com> */
+
+#ifndef __LIBGPIOD_MUSL_COMPAT_H__
+#define __LIBGPIOD_MUSL_COMPAT_H__
+
+#ifndef _GNU_SOURCE
+
+/*
+ * Musl's <sys/ioctl.h> (<bits/ioctl.h>) also defines below macros, un-define
+ * them before adding the ones via <linux/gpio.h> to avoid build failures.
+ */
+
+#undef _IOWR
+#undef _IOR
+#undef _IOW
+#undef _IOC
+#undef _IO
+
+#endif
+
+#endif /* __LIBGPIOD_MUSL_COMPAT_H__ */
-- 
2.31.1.272.g89b43f80a514


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-12-09 11:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-09 11:58 [PATCH V2] libgpiod: Fix build failure with musl Viresh Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).