]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
test: handle POSIX ioctl prototype
authorSam James <sam@gentoo.org>
Sat, 30 Sep 2023 05:38:53 +0000 (06:38 +0100)
committerDaniel Wagner <wagi@monom.org>
Sat, 30 Sep 2023 10:21:36 +0000 (12:21 +0200)
glibc has the following prototype for ioctl: int ioctl(int fd, unsigned long request, ...)
POSIX (inc. musl) has the following for ioctl: int ioctl(int fd, int request, ...)

Check which prototype is used in <sys/ioctl.h> to avoid a conflict and conditionally
define the right one for the system.

Bug: https://bugs.gentoo.org/914921
Signed-off-by: Sam James <sam@gentoo.org>
meson.build
test/ioctl/mock.c

index 6fcf1da5da93c37701652ef5e924739b5b503a96..2c979ccb270e512506660264a7b352c55c00c44c 100644 (file)
@@ -230,6 +230,16 @@ conf.set(
     ),
     description: 'Is network address and service translation available'
 )
+conf.set(
+    'HAVE_GLIBC_IOCTL',
+    cc.compiles(
+        '''#include <sys/ioctl.h>
+        int ioctl(int fd, unsigned long request, ...);
+        ''',
+        name: 'ioctl has glibc-style prototype'
+    ),
+    description: 'Is ioctl the glibc interface (rather than POSIX)'
+)
 
 if cc.has_function_attribute('fallthrough')
   conf.set('fallthrough', '__attribute__((__fallthrough__))')
index e917244b97f8f78650b12c38b49bee8070c1fcba..5d2ac94e0840a3a8a66798db9296afdae6347139 100644 (file)
@@ -114,7 +114,11 @@ void end_mock_cmds(void)
        } \
 })
 
+#ifdef HAVE_GLIBC_IOCTL
 int ioctl(int fd, unsigned long request, ...)
+#else
+int ioctl(int fd, int request, ...)
+#endif
 {
        struct mock_cmds *mock_cmds;
        bool result64;
@@ -141,7 +145,7 @@ int ioctl(int fd, unsigned long request, ...)
                result64 = true;
                break;
        default:
-               fail("unexpected %s %lu", __func__, request);
+               fail("unexpected %s %lu", __func__, (unsigned long) request);
        }
        check(mock_cmds->remaining_cmds,
              "unexpected %s command", mock_cmds->name);