Andrew Geissler | 2013739 | 2023-10-12 04:59:14 -0600 | [diff] [blame] | 1 | From ca47ba3119365eafac0ab25a86cab9d9a1b29bd4 Mon Sep 17 00:00:00 2001 |
| 2 | From: Sam James <sam@gentoo.org> |
| 3 | Date: Sat, 30 Sep 2023 06:38:53 +0100 |
| 4 | Subject: [PATCH] test: handle POSIX ioctl prototype |
| 5 | |
| 6 | glibc has the following prototype for ioctl: int ioctl(int fd, unsigned long request, ...) |
| 7 | POSIX (inc. musl) has the following for ioctl: int ioctl(int fd, int request, ...) |
| 8 | |
| 9 | Check which prototype is used in <sys/ioctl.h> to avoid a conflict and conditionally |
| 10 | define the right one for the system. |
| 11 | |
| 12 | Bug: https://bugs.gentoo.org/914921 |
| 13 | Signed-off-by: Sam James <sam@gentoo.org> |
| 14 | Upstream-Status: Backport [https://github.com/linux-nvme/libnvme/commit/ca47ba3119365eafac0ab25a86cab9d9a1b29bd4] |
| 15 | --- |
| 16 | meson.build | 10 ++++++++++ |
| 17 | test/ioctl/mock.c | 6 +++++- |
| 18 | 2 files changed, 15 insertions(+), 1 deletion(-) |
| 19 | |
| 20 | diff --git a/meson.build b/meson.build |
| 21 | index 6fcf1da..2c979cc 100644 |
| 22 | --- a/meson.build |
| 23 | +++ b/meson.build |
| 24 | @@ -230,6 +230,16 @@ conf.set( |
| 25 | ), |
| 26 | description: 'Is network address and service translation available' |
| 27 | ) |
| 28 | +conf.set( |
| 29 | + 'HAVE_GLIBC_IOCTL', |
| 30 | + cc.compiles( |
| 31 | + '''#include <sys/ioctl.h> |
| 32 | + int ioctl(int fd, unsigned long request, ...); |
| 33 | + ''', |
| 34 | + name: 'ioctl has glibc-style prototype' |
| 35 | + ), |
| 36 | + description: 'Is ioctl the glibc interface (rather than POSIX)' |
| 37 | +) |
| 38 | |
| 39 | if cc.has_function_attribute('fallthrough') |
| 40 | conf.set('fallthrough', '__attribute__((__fallthrough__))') |
| 41 | diff --git a/test/ioctl/mock.c b/test/ioctl/mock.c |
| 42 | index e917244..5d2ac94 100644 |
| 43 | --- a/test/ioctl/mock.c |
| 44 | +++ b/test/ioctl/mock.c |
| 45 | @@ -114,7 +114,11 @@ void end_mock_cmds(void) |
| 46 | } \ |
| 47 | }) |
| 48 | |
| 49 | +#ifdef HAVE_GLIBC_IOCTL |
| 50 | int ioctl(int fd, unsigned long request, ...) |
| 51 | +#else |
| 52 | +int ioctl(int fd, int request, ...) |
| 53 | +#endif |
| 54 | { |
| 55 | struct mock_cmds *mock_cmds; |
| 56 | bool result64; |
| 57 | @@ -141,7 +145,7 @@ int ioctl(int fd, unsigned long request, ...) |
| 58 | result64 = true; |
| 59 | break; |
| 60 | default: |
| 61 | - fail("unexpected %s %lu", __func__, request); |
| 62 | + fail("unexpected %s %lu", __func__, (unsigned long) request); |
| 63 | } |
| 64 | check(mock_cmds->remaining_cmds, |
| 65 | "unexpected %s command", mock_cmds->name); |
| 66 | -- |
| 67 | 2.40.1 |
| 68 | |