[3/5] linux: Replace zero-length array with flexible-array member on inotify struct

Message ID 20230621213444.2017-2-cristian@rodriguez.im
State New
Headers
Series None |

Commit Message

Cristian Rodríguez June 21, 2023, 9:34 p.m. UTC
  Current kernel versions require a compiler supporting -std=gnu11
and therefore supporting C99 flexible arrays. old versions require
a c89 compiler supporting this feature as an extension.

Signed-off-by: Cristian Rodríguez <cristian@rodriguez.im>
---
 sysdeps/unix/sysv/linux/sys/inotify.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Cristian Rodríguez June 21, 2023, 9:44 p.m. UTC | #1
This patch only syncs with the current kernel headers.

On Wed, Jun 21, 2023 at 5:35 PM Cristian Rodríguez <cristian@rodriguez.im>
wrote:

> Current kernel versions require a compiler supporting -std=gnu11
> and therefore supporting C99 flexible arrays. old versions require
> a c89 compiler supporting this feature as an extension.
>
> Signed-off-by: Cristian Rodríguez <cristian@rodriguez.im>
> ---
>  sysdeps/unix/sysv/linux/sys/inotify.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/sysdeps/unix/sysv/linux/sys/inotify.h
> b/sysdeps/unix/sysv/linux/sys/inotify.h
> index 1e8e68cd97..535f57e27b 100644
> --- a/sysdeps/unix/sysv/linux/sys/inotify.h
> +++ b/sysdeps/unix/sysv/linux/sys/inotify.h
> @@ -31,7 +31,7 @@ struct inotify_event
>    uint32_t mask;       /* Watch mask.  */
>    uint32_t cookie;     /* Cookie to synchronize two events.  */
>    uint32_t len;                /* Length (including NULs) of name.  */
> -  char name __flexarr; /* Name.  */
> +  char name[];         /* Name.  */
>  };
>
>
> --
> 2.41.0
>
>
  
Florian Weimer June 22, 2023, 5:23 a.m. UTC | #2
* Cristian Rodríguez via Libc-alpha:

> Current kernel versions require a compiler supporting -std=gnu11
> and therefore supporting C99 flexible arrays. old versions require
> a c89 compiler supporting this feature as an extension.

Ugh, you are right:

commit 94dfc73e7cf4a31da66b8843f0b9283ddd6b8381
Author: Gustavo A. R. Silva <gustavoars@kernel.org>
Date:   Wed Apr 6 19:36:51 2022 -0500

    treewide: uapi: Replace zero-length arrays with flexible-array members

It's specifically targeting UAPI headers, so it's not a (harmless)
kernel-internal change.

Do you know if anyone has looked at the compatibility impact of this
change on C parsers?  I'm not sure if we can do the same thing.  In
particular, if kernel headers are not C89-compatible, we may have to add
kludges to our own headers that avoid including them in C89 mode.

Thanks,
Florian
  
Cristian Rodríguez June 23, 2023, 3:57 p.m. UTC | #3
On Thu, Jun 22, 2023 at 1:23 AM Florian Weimer <fweimer@redhat.com> wrote:

>
> Do you know if anyone has looked at the compatibility impact of this
> change on C parsers?  I'm not sure if we can do the same thing.  In
> particular, if kernel headers are not C89-compatible, we may have to add
> kludges to our own headers that avoid including them in C89 mode.
>
>
>
On this case it is a linux feature, which has required this as an
extension, probably since forever. I have only checked kernel 3.2 as the
minimum and that version indeed uses c99 flex arrays at least *internally*
(I have not checked all headers though)
  

Patch

diff --git a/sysdeps/unix/sysv/linux/sys/inotify.h b/sysdeps/unix/sysv/linux/sys/inotify.h
index 1e8e68cd97..535f57e27b 100644
--- a/sysdeps/unix/sysv/linux/sys/inotify.h
+++ b/sysdeps/unix/sysv/linux/sys/inotify.h
@@ -31,7 +31,7 @@  struct inotify_event
   uint32_t mask;	/* Watch mask.  */
   uint32_t cookie;	/* Cookie to synchronize two events.  */
   uint32_t len;		/* Length (including NULs) of name.  */
-  char name __flexarr;	/* Name.  */
+  char name[];		/* Name.  */
 };