summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2022-10-19 16:28:18 +0200
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2022-10-20 16:12:39 +0200
commit3e2dda55a2f2cefb93eb001d685b5aed07e1feb1 (patch)
treee8da34d522c5b2d4cb49eb87e23c1dc94668bc4e
parent62b5c727feeb254931cea2269395d63ecc7c34cd (diff)
downloadglib-wip/3v1n0/more-unix-oses.tar.gz
glib: Add generic G_OS_BSD definition on such platformswip/3v1n0/more-unix-oses
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
-rw-r--r--docs/reference/glib/glib-overrides.txt5
-rw-r--r--docs/reference/glib/glib-sections.txt.in1
-rw-r--r--glib/docs.c17
-rw-r--r--glib/gspawn.c4
-rw-r--r--glib/tests/date.c2
-rw-r--r--glib/tests/macros.c13
-rw-r--r--meson.build5
7 files changed, 41 insertions, 6 deletions
diff --git a/docs/reference/glib/glib-overrides.txt b/docs/reference/glib/glib-overrides.txt
index 20c6f8198..afd7b0f63 100644
--- a/docs/reference/glib/glib-overrides.txt
+++ b/docs/reference/glib/glib-overrides.txt
@@ -197,6 +197,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
</MACRO>
diff --git a/docs/reference/glib/glib-sections.txt.in b/docs/reference/glib/glib-sections.txt.in
index 9219b4426..db8ff1e35 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 1e4ea9778..91f5c8334 100644
--- a/glib/docs.c
+++ b/glib/docs.c
@@ -1648,12 +1648,23 @@
*/
/**
+ * 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 28c277444..26914cf03 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 41ef5b6a9..4419bac41 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 974d4c489..7779c164d 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 92f45875e..9197149c9 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