From 40508b35b9c74171560dc9e627a35be2d7fb1db5 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 31 May 2023 16:26:26 +0100 Subject: [PATCH] glib-unix: Assert that O_NONBLOCK and FD_CLOEXEC are numerically distinct Since 5c65437d "glib-unix: Add O_NONBLOCK support to g_unix_open_pipe()" we have effectively been assuming that these two flags are distinguishable. If that's an assumption we want to make, we should make it a static assertion, so that GLib will fail to compile on platforms where it isn't true. Signed-off-by: Simon McVittie --- glib/glib-unix.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/glib/glib-unix.c b/glib/glib-unix.c index f671887c9..c25cd30f0 100644 --- a/glib/glib-unix.c +++ b/glib/glib-unix.c @@ -37,6 +37,12 @@ G_STATIC_ASSERT (G_ALIGNOF (gssize) == G_ALIGNOF (ssize_t)); G_STATIC_ASSERT (sizeof (GPid) == sizeof (pid_t)); G_STATIC_ASSERT (G_ALIGNOF (GPid) == G_ALIGNOF (pid_t)); +/* If this assertion fails, then the ABI of g_unix_open_pipe() would be + * ambiguous on this platform. + * On Linux, usually O_NONBLOCK == 04000 and FD_CLOEXEC == 1, but the same + * might not be true everywhere. */ +G_STATIC_ASSERT (O_NONBLOCK != FD_CLOEXEC); + /** * SECTION:gunix * @title: UNIX-specific utilities and integration