Skip to content

Commit

Permalink
v4l2: v4l2_compat: Fix ioctl() prototype with musl C library
Browse files Browse the repository at this point in the history
The musl C library, as well as the POSIX standard, define the ioctl()
function's request argument as an int. glibc and uclibc, on the other
hand, define it as an unsigned long.

This difference between the function prototype and the implementation in
the V4L2 adaptation layer causes a compilation error with musl. Fix it
by detecting the function prototype and declaring the libcamera ioctl()
handler accordingly.

Signed-off-by: Laurent Pinchart <[email protected]>
Reviewed-by: Kieran Bingham <[email protected]>
Reviewed-by: Paul Elder <[email protected]>
Signed-off-by: Kieran Bingham <[email protected]>
  • Loading branch information
pinchartl authored and kbingham committed Jul 25, 2024
1 parent 0c9862d commit 83b3141
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ if cc.has_header_symbol('sys/mman.h', 'memfd_create', prefix : '#define _GNU_SOU
config_h.set('HAVE_MEMFD_CREATE', 1)
endif

ioctl_posix_test = '''
#include <sys/ioctl.h>
int ioctl (int, int, ...);
'''

if cc.compiles(ioctl_posix_test)
config_h.set('HAVE_POSIX_IOCTL', 1)
endif

if cc.has_header_symbol('stdlib.h', 'secure_getenv', prefix : '#define _GNU_SOURCE')
config_h.set('HAVE_SECURE_GETENV', 1)
endif
Expand Down
4 changes: 4 additions & 0 deletions src/v4l2/v4l2_compat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ LIBCAMERA_PUBLIC int munmap(void *addr, size_t length)
return V4L2CompatManager::instance()->munmap(addr, length);
}

#if HAVE_POSIX_IOCTL
LIBCAMERA_PUBLIC int ioctl(int fd, int request, ...)
#else
LIBCAMERA_PUBLIC int ioctl(int fd, unsigned long request, ...)
#endif
{
void *arg;
extract_va_arg(void *, arg, request);
Expand Down

0 comments on commit 83b3141

Please sign in to comment.