diff mbox series

[FFmpeg-devel] configure: improve check for POSIX ioctl

Message ID 20240829134000.6907-1-ramiro.polla@gmail.com
State New
Headers show
Series [FFmpeg-devel] configure: improve check for POSIX ioctl | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Ramiro Polla Aug. 29, 2024, 1:40 p.m. UTC
Instead of relying on system #ifdefs which may or may not be correct,
detect the POSIX ioctl signature at configure time.
---
 configure          | 2 ++
 libavdevice/v4l2.c | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

Comments

James Almer Aug. 29, 2024, 2:44 p.m. UTC | #1
On 8/29/2024 10:40 AM, Ramiro Polla wrote:
> Instead of relying on system #ifdefs which may or may not be correct,
> detect the POSIX ioctl signature at configure time.
> ---
>   configure          | 2 ++
>   libavdevice/v4l2.c | 2 +-
>   2 files changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/configure b/configure
> index 63f0429b02..ebbec49993 100755
> --- a/configure
> +++ b/configure
> @@ -2524,6 +2524,7 @@ HAVE_LIST="
>       opencl_videotoolbox
>       perl
>       pod2man
> +    posix_ioctl
>       texi2html
>       xmllint
>       zlib_gzip
> @@ -7158,6 +7159,7 @@ xmllint --version  > /dev/null 2>&1 && enable xmllint   || disable xmllint
>   check_headers linux/fb.h
>   check_headers linux/videodev2.h
>   test_code cc linux/videodev2.h "struct v4l2_frmsizeenum vfse; vfse.discrete.width = 0;" && enable_sanitized struct_v4l2_frmivalenum_discrete
> +test_code cc sys/ioctl.h "int ioctl(int, int, ...);" && enable posix_ioctl

Is this check going to fail for the targets where ioctl_f has request as 
an unsigned long int?

>   
>   # check V4L2 codecs available in the API
>   if enabled v4l2_m2m; then
> diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
> index 42d4b97c8f..0ae6872338 100644
> --- a/libavdevice/v4l2.c
> +++ b/libavdevice/v4l2.c
> @@ -111,7 +111,7 @@ struct video_data {
>       int (*open_f)(const char *file, int oflag, ...);
>       int (*close_f)(int fd);
>       int (*dup_f)(int fd);
> -#if defined(__sun) || defined(__BIONIC__) || defined(__musl__) /* POSIX-like */
> +#if HAVE_POSIX_IOCTL
>       int (*ioctl_f)(int fd, int request, ...);
>   #else
>       int (*ioctl_f)(int fd, unsigned long int request, ...);
Ramiro Polla Aug. 29, 2024, 5:18 p.m. UTC | #2
On Thu, Aug 29, 2024 at 7:10 PM James Almer <jamrial@gmail.com> wrote:
> On 8/29/2024 10:40 AM, Ramiro Polla wrote:
> > Instead of relying on system #ifdefs which may or may not be correct,
> > detect the POSIX ioctl signature at configure time.
> > ---
> >   configure          | 2 ++
> >   libavdevice/v4l2.c | 2 +-
> >   2 files changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/configure b/configure
> > index 63f0429b02..ebbec49993 100755
> > --- a/configure
> > +++ b/configure
> > @@ -2524,6 +2524,7 @@ HAVE_LIST="
> >       opencl_videotoolbox
> >       perl
> >       pod2man
> > +    posix_ioctl
> >       texi2html
> >       xmllint
> >       zlib_gzip
> > @@ -7158,6 +7159,7 @@ xmllint --version  > /dev/null 2>&1 && enable xmllint   || disable xmllint
> >   check_headers linux/fb.h
> >   check_headers linux/videodev2.h
> >   test_code cc linux/videodev2.h "struct v4l2_frmsizeenum vfse; vfse.discrete.width = 0;" && enable_sanitized struct_v4l2_frmivalenum_discrete
> > +test_code cc sys/ioctl.h "int ioctl(int, int, ...);" && enable posix_ioctl
>
> Is this check going to fail for the targets where ioctl_f has request as
> an unsigned long int?

Yes. This is from config.log:

/tmp/ffconf.S7gHklXc/test.c: In function 'main':
/tmp/ffconf.S7gHklXc/test.c:2:22: error: conflicting types for
'ioctl'; have 'int(int,  int, ...)'
    2 | int main(void) { int ioctl(int, int, ...);; return 0; }
      |                      ^~~~~
In file included from /tmp/ffconf.S7gHklXc/test.c:1:
/usr/include/x86_64-linux-gnu/sys/ioctl.h:42:12: note: previous
declaration of 'ioctl' with type 'int(int,  long unsigned int, ...)'
   42 | extern int ioctl (int __fd, unsigned long int __request, ...) __THROW;
      |            ^~~~~
James Almer Aug. 29, 2024, 5:30 p.m. UTC | #3
On 8/29/2024 2:18 PM, Ramiro Polla wrote:
> On Thu, Aug 29, 2024 at 7:10 PM James Almer <jamrial@gmail.com> wrote:
>> On 8/29/2024 10:40 AM, Ramiro Polla wrote:
>>> Instead of relying on system #ifdefs which may or may not be correct,
>>> detect the POSIX ioctl signature at configure time.
>>> ---
>>>    configure          | 2 ++
>>>    libavdevice/v4l2.c | 2 +-
>>>    2 files changed, 3 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/configure b/configure
>>> index 63f0429b02..ebbec49993 100755
>>> --- a/configure
>>> +++ b/configure
>>> @@ -2524,6 +2524,7 @@ HAVE_LIST="
>>>        opencl_videotoolbox
>>>        perl
>>>        pod2man
>>> +    posix_ioctl
>>>        texi2html
>>>        xmllint
>>>        zlib_gzip
>>> @@ -7158,6 +7159,7 @@ xmllint --version  > /dev/null 2>&1 && enable xmllint   || disable xmllint
>>>    check_headers linux/fb.h
>>>    check_headers linux/videodev2.h
>>>    test_code cc linux/videodev2.h "struct v4l2_frmsizeenum vfse; vfse.discrete.width = 0;" && enable_sanitized struct_v4l2_frmivalenum_discrete
>>> +test_code cc sys/ioctl.h "int ioctl(int, int, ...);" && enable posix_ioctl
>>
>> Is this check going to fail for the targets where ioctl_f has request as
>> an unsigned long int?
> 
> Yes. This is from config.log:
> 
> /tmp/ffconf.S7gHklXc/test.c: In function 'main':
> /tmp/ffconf.S7gHklXc/test.c:2:22: error: conflicting types for
> 'ioctl'; have 'int(int,  int, ...)'
>      2 | int main(void) { int ioctl(int, int, ...);; return 0; }
>        |                      ^~~~~
> In file included from /tmp/ffconf.S7gHklXc/test.c:1:
> /usr/include/x86_64-linux-gnu/sys/ioctl.h:42:12: note: previous
> declaration of 'ioctl' with type 'int(int,  long unsigned int, ...)'
>     42 | extern int ioctl (int __fd, unsigned long int __request, ...) __THROW;
>        |            ^~~~~

Cool. Should be ok then. Just remove the colon at the end of the check 
since test_code() will add one. Some compiler settings like -pedantic 
may complain about it, so better safe than sorry.
Ramiro Polla Aug. 30, 2024, 11:14 a.m. UTC | #4
On Thu, Aug 29, 2024 at 7:55 PM James Almer <jamrial@gmail.com> wrote:
> On 8/29/2024 2:18 PM, Ramiro Polla wrote:
> > On Thu, Aug 29, 2024 at 7:10 PM James Almer <jamrial@gmail.com> wrote:
> >> On 8/29/2024 10:40 AM, Ramiro Polla wrote:
> >>> Instead of relying on system #ifdefs which may or may not be correct,
> >>> detect the POSIX ioctl signature at configure time.
> >>> ---
> >>>    configure          | 2 ++
> >>>    libavdevice/v4l2.c | 2 +-
> >>>    2 files changed, 3 insertions(+), 1 deletion(-)
> >>>
> >>> diff --git a/configure b/configure
> >>> index 63f0429b02..ebbec49993 100755
> >>> --- a/configure
> >>> +++ b/configure
> >>> @@ -2524,6 +2524,7 @@ HAVE_LIST="
> >>>        opencl_videotoolbox
> >>>        perl
> >>>        pod2man
> >>> +    posix_ioctl
> >>>        texi2html
> >>>        xmllint
> >>>        zlib_gzip
> >>> @@ -7158,6 +7159,7 @@ xmllint --version  > /dev/null 2>&1 && enable xmllint   || disable xmllint
> >>>    check_headers linux/fb.h
> >>>    check_headers linux/videodev2.h
> >>>    test_code cc linux/videodev2.h "struct v4l2_frmsizeenum vfse; vfse.discrete.width = 0;" && enable_sanitized struct_v4l2_frmivalenum_discrete
> >>> +test_code cc sys/ioctl.h "int ioctl(int, int, ...);" && enable posix_ioctl
> >>
> >> Is this check going to fail for the targets where ioctl_f has request as
> >> an unsigned long int?
> >
> > Yes. This is from config.log:
> >
> > /tmp/ffconf.S7gHklXc/test.c: In function 'main':
> > /tmp/ffconf.S7gHklXc/test.c:2:22: error: conflicting types for
> > 'ioctl'; have 'int(int,  int, ...)'
> >      2 | int main(void) { int ioctl(int, int, ...);; return 0; }
> >        |                      ^~~~~
> > In file included from /tmp/ffconf.S7gHklXc/test.c:1:
> > /usr/include/x86_64-linux-gnu/sys/ioctl.h:42:12: note: previous
> > declaration of 'ioctl' with type 'int(int,  long unsigned int, ...)'
> >     42 | extern int ioctl (int __fd, unsigned long int __request, ...) __THROW;
> >        |            ^~~~~
>
> Cool. Should be ok then. Just remove the colon at the end of the check
> since test_code() will add one. Some compiler settings like -pedantic
> may complain about it, so better safe than sorry.

Thanks. I'll apply without the colon at the end of the check.

By the way, the tests for struct_v4l2_frmivalenum_discrete and
v4l2_m2m all have the trailing colon as well.
Ramiro Polla Sept. 1, 2024, 4:05 p.m. UTC | #5
On Fri, Aug 30, 2024 at 1:14 PM Ramiro Polla <ramiro.polla@gmail.com> wrote:
> On Thu, Aug 29, 2024 at 7:55 PM James Almer <jamrial@gmail.com> wrote:
> > On 8/29/2024 2:18 PM, Ramiro Polla wrote:
> > > On Thu, Aug 29, 2024 at 7:10 PM James Almer <jamrial@gmail.com> wrote:
> > >> On 8/29/2024 10:40 AM, Ramiro Polla wrote:
> > >>> Instead of relying on system #ifdefs which may or may not be correct,
> > >>> detect the POSIX ioctl signature at configure time.
> > >>> ---
> > >>>    configure          | 2 ++
> > >>>    libavdevice/v4l2.c | 2 +-
> > >>>    2 files changed, 3 insertions(+), 1 deletion(-)
> > >>>
> > >>> diff --git a/configure b/configure
> > >>> index 63f0429b02..ebbec49993 100755
> > >>> --- a/configure
> > >>> +++ b/configure
> > >>> @@ -2524,6 +2524,7 @@ HAVE_LIST="
> > >>>        opencl_videotoolbox
> > >>>        perl
> > >>>        pod2man
> > >>> +    posix_ioctl
> > >>>        texi2html
> > >>>        xmllint
> > >>>        zlib_gzip
> > >>> @@ -7158,6 +7159,7 @@ xmllint --version  > /dev/null 2>&1 && enable xmllint   || disable xmllint
> > >>>    check_headers linux/fb.h
> > >>>    check_headers linux/videodev2.h
> > >>>    test_code cc linux/videodev2.h "struct v4l2_frmsizeenum vfse; vfse.discrete.width = 0;" && enable_sanitized struct_v4l2_frmivalenum_discrete
> > >>> +test_code cc sys/ioctl.h "int ioctl(int, int, ...);" && enable posix_ioctl
> > >>
> > >> Is this check going to fail for the targets where ioctl_f has request as
> > >> an unsigned long int?
> > >
> > > Yes. This is from config.log:
> > >
> > > /tmp/ffconf.S7gHklXc/test.c: In function 'main':
> > > /tmp/ffconf.S7gHklXc/test.c:2:22: error: conflicting types for
> > > 'ioctl'; have 'int(int,  int, ...)'
> > >      2 | int main(void) { int ioctl(int, int, ...);; return 0; }
> > >        |                      ^~~~~
> > > In file included from /tmp/ffconf.S7gHklXc/test.c:1:
> > > /usr/include/x86_64-linux-gnu/sys/ioctl.h:42:12: note: previous
> > > declaration of 'ioctl' with type 'int(int,  long unsigned int, ...)'
> > >     42 | extern int ioctl (int __fd, unsigned long int __request, ...) __THROW;
> > >        |            ^~~~~
> >
> > Cool. Should be ok then. Just remove the colon at the end of the check
> > since test_code() will add one. Some compiler settings like -pedantic
> > may complain about it, so better safe than sorry.
>
> Thanks. I'll apply without the colon at the end of the check.

Pushed.
diff mbox series

Patch

diff --git a/configure b/configure
index 63f0429b02..ebbec49993 100755
--- a/configure
+++ b/configure
@@ -2524,6 +2524,7 @@  HAVE_LIST="
     opencl_videotoolbox
     perl
     pod2man
+    posix_ioctl
     texi2html
     xmllint
     zlib_gzip
@@ -7158,6 +7159,7 @@  xmllint --version  > /dev/null 2>&1 && enable xmllint   || disable xmllint
 check_headers linux/fb.h
 check_headers linux/videodev2.h
 test_code cc linux/videodev2.h "struct v4l2_frmsizeenum vfse; vfse.discrete.width = 0;" && enable_sanitized struct_v4l2_frmivalenum_discrete
+test_code cc sys/ioctl.h "int ioctl(int, int, ...);" && enable posix_ioctl
 
 # check V4L2 codecs available in the API
 if enabled v4l2_m2m; then
diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
index 42d4b97c8f..0ae6872338 100644
--- a/libavdevice/v4l2.c
+++ b/libavdevice/v4l2.c
@@ -111,7 +111,7 @@  struct video_data {
     int (*open_f)(const char *file, int oflag, ...);
     int (*close_f)(int fd);
     int (*dup_f)(int fd);
-#if defined(__sun) || defined(__BIONIC__) || defined(__musl__) /* POSIX-like */
+#if HAVE_POSIX_IOCTL
     int (*ioctl_f)(int fd, int request, ...);
 #else
     int (*ioctl_f)(int fd, unsigned long int request, ...);