[glib/wip/3v1n0/more-unix-oses: 5/5] glib: Add generic G_OS_BSD definition on such platforms




commit 3e2dda55a2f2cefb93eb001d685b5aed07e1feb1
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Wed Oct 19 16:28:18 2022 +0200

    glib: Add generic G_OS_BSD definition on such platforms
    
    There is some downstream code and our tests that may at times need to
    check for all BSD kinds, so just a more generic way to handle this

 docs/reference/glib/glib-overrides.txt   |  5 +++++
 docs/reference/glib/glib-sections.txt.in |  1 +
 glib/docs.c                              | 17 ++++++++++++++---
 glib/gspawn.c                            |  4 ++--
 glib/tests/date.c                        |  2 +-
 glib/tests/macros.c                      | 13 +++++++++++++
 meson.build                              |  5 +++++
 7 files changed, 41 insertions(+), 6 deletions(-)
---
diff --git a/docs/reference/glib/glib-overrides.txt b/docs/reference/glib/glib-overrides.txt
index 20c6f8198c..afd7b0f631 100644
--- a/docs/reference/glib/glib-overrides.txt
+++ b/docs/reference/glib/glib-overrides.txt
@@ -196,6 +196,11 @@ GCond *cond
 
 # Definitions for different operating systems
 
+<MACRO>
+<NAME>G_OS_BSD</NAME>
+#define G_OS_BSD
+</MACRO>
+
 <MACRO>
 <NAME>G_OS_FREEBSD</NAME>
 #define G_OS_FREEBSD
diff --git a/docs/reference/glib/glib-sections.txt.in b/docs/reference/glib/glib-sections.txt.in
index 9219b44267..db8ff1e35f 100644
--- a/docs/reference/glib/glib-sections.txt.in
+++ b/docs/reference/glib/glib-sections.txt.in
@@ -140,6 +140,7 @@ GLIB_VERSION_PREV_STABLE
 <TITLE>Standard Macros</TITLE>
 <FILE>macros</FILE>
 <SUBSECTION>
+G_OS_BSD
 G_OS_DARWIN
 G_OS_FREEBSD
 G_OS_LINUX
diff --git a/glib/docs.c b/glib/docs.c
index 1e4ea9778a..91f5c83345 100644
--- a/glib/docs.c
+++ b/glib/docs.c
@@ -1647,13 +1647,24 @@
  * These macros provide a few commonly-used features.
  */
 
+/**
+ * G_OS_BSD:
+ *
+ * This macro is defined only on BSD operating systems. So you can bracket
+ * BSD-specific code in `\#ifdef G_OS_BSD`.
+ *
+ * Note that %G_OS_UNIX is also set.
+ *
+ * Since: 2.76
+ */
+
 /**
  * G_OS_DARWIN:
  *
  * This macro is defined only on Apple operating systems (macOS or iOS).
  * So you can bracket Apple-specific code in `\#ifdef G_OS_DARWIN`.
  *
- * Note that %G_OS_UNIX is also set.
+ * Note that %G_OS_UNIX and %G_OS_BSD is also set.
  *
  * Since: 2.76
  */
@@ -1664,7 +1675,7 @@
  * This macro is defined only on FreeBSD operating system. So you can bracket
  * FreeBSD-specific code in `\#ifdef G_OS_FREEBSD`.
  *
- * Note that %G_OS_UNIX is also set.
+ * Note that %G_OS_UNIX and %G_OS_BSD is also set.
  *
  * Since: 2.76
  */
@@ -1686,7 +1697,7 @@
  * This macro is defined only on OpenBSD operating system. So you can bracket
  * OpenBSD-specific code in `\#ifdef G_OS_OPENBSD`.
  *
- * Note that %G_OS_UNIX is also set.
+ * Note that %G_OS_UNIX and %G_OS_BSD is also set.
  *
  * Since: 2.76
  */
diff --git a/glib/gspawn.c b/glib/gspawn.c
index 28c277444a..26914cf03e 100644
--- a/glib/gspawn.c
+++ b/glib/gspawn.c
@@ -1475,7 +1475,7 @@ safe_fdwalk (int (*cb)(void *data, int fd), void *data)
   if (getrlimit (RLIMIT_NOFILE, &rl) == 0 && rl.rlim_max != RLIM_INFINITY)
     open_max = rl.rlim_max;
 #endif
-#if defined(G_OS_FREEBSD) || defined(G_OS_OPENBSD) || defined(G_OS_DARWIN)
+#ifdef G_OS_BSD
   /* Use sysconf() function provided by the system if it is known to be
    * async-signal safe.
    *
@@ -1490,7 +1490,7 @@ safe_fdwalk (int (*cb)(void *data, int fd), void *data)
    */
   if (open_max < 0)
     open_max = sysconf (_SC_OPEN_MAX);
-#endif
+#endif /*  G_OS_BSD */
   /* Hardcoded fallback: the default process hard limit in Linux as of 2020 */
   if (open_max < 0)
     open_max = 4096;
diff --git a/glib/tests/date.c b/glib/tests/date.c
index 41ef5b6a92..4419bac41c 100644
--- a/glib/tests/date.c
+++ b/glib/tests/date.c
@@ -725,7 +725,7 @@ test_strftime (void)
 #else
     { "%B", "January" },
     { "%b", "Jan" },
-#if defined(G_OS_FREEBSD) || defined(G_OS_OPENBSD) || defined(G_OS_DARWIN)
+#ifdef G_OS_BSD
     { "%C", "00" },
     { "%c", "Mon Jan  1 00:00:00 0001" },
     { "%E", "E" },
diff --git a/glib/tests/macros.c b/glib/tests/macros.c
index 974d4c489e..7779c164d1 100644
--- a/glib/tests/macros.c
+++ b/glib/tests/macros.c
@@ -40,6 +40,9 @@
 # ifndef G_OS_FREEBSD
   #error "G_OS_FREEBSD is not defined"
 # endif
+# ifndef G_OS_BSD
+  #error "G_OS_BSD is not defined"
+# endif
 #endif
 
 #if defined (__OpenBSD__)
@@ -49,6 +52,9 @@
 # ifndef G_OS_OPENBSD
   #error "G_OS_OPENBSD is not defined"
 # endif
+# ifndef G_OS_BSD
+  #error "G_OS_BSD is not defined"
+# endif
 #endif
 
 #if defined (__APPLE__) || defined (HAVE_COCOA) || defined (HAVE_CARBON)
@@ -58,12 +64,19 @@
 # ifndef G_OS_DARWIN
   #error "G_OS_DARWIN is not defined"
 # endif
+# ifndef G_OS_BSD
+  #error "G_OS_BSD is not defined"
+# endif
 #endif
 
 #if defined (G_OS_UNIX) && defined (G_OS_WIN32)
   #error "G_OS_WIN32 and G_OS_UNIX should not be defined together"
 #endif
 
+#if (defined (G_OS_LINUX) || !defined (G_OS_UNIX)) && defined (G_OS_BSD)
+  #error "G_OS_BSD should not be defined"
+#endif
+
 /* Test that G_STATIC_ASSERT_EXPR can be used as an expression */
 static void
 test_assert_static (void)
diff --git a/meson.build b/meson.build
index 92f45875ea..9197149c94 100644
--- a/meson.build
+++ b/meson.build
@@ -243,11 +243,16 @@ else
     glib_os += 'G_WITH_CYGWIN'
   elif host_system in ['darwin', 'ios']
     glib_os += 'G_OS_DARWIN'
+    glib_os += 'G_OS_BSD'
   elif host_system == 'freebsd'
     glib_os += 'G_OS_FREEBSD'
   elif host_system == 'openbsd'
     glib_os += 'G_OS_OPENBSD'
   endif
+
+  if host_system.to_lower().endswith('bsd')
+    glib_os += 'G_OS_BSD'
+  endif
 endif
 glib_os_defines = []
 foreach os : glib_os


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]