Skip to content

Commit

Permalink
test: handle POSIX ioctl prototype
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
thesamesam authored and igaw committed Sep 30, 2023
1 parent 37a803c commit ca47ba3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 10 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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__))')
Expand Down
6 changes: 5 additions & 1 deletion test/ioctl/mock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit ca47ba3

Please sign in to comment.