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




commit 9510105a86c1ec182e4fa7f68941f24fa8b30ed9
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 +-
 meson.build                              |  5 +++++
 6 files changed, 28 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 e317ea8c7d..9f6fe0cde2 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 macOS (OS X 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 c2007d99a8..9501ed981a 100644
--- a/glib/gspawn.c
+++ b/glib/gspawn.c
@@ -1493,7 +1493,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.
    *
@@ -1508,7 +1508,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/meson.build b/meson.build
index fbfd4eff8f..4218028c72 100644
--- a/meson.build
+++ b/meson.build
@@ -243,11 +243,16 @@ else
     glib_os += 'G_WITH_CYGWIN'
   elif host_system == 'darwin'
     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]