summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2022-10-19 16:14:34 +0200
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2022-10-20 16:12:39 +0200
commit62b5c727feeb254931cea2269395d63ecc7c34cd (patch)
treeac645e290f6307d6297d6931526b1a1de32773e7
parentaaa7632f2c9832398ce036a929b465713434d310 (diff)
downloadglib-62b5c727feeb254931cea2269395d63ecc7c34cd.tar.gz
glib: Add G_OS_OPENBSD and G_OS_FREEBSD
Add the most common types of BSD systems as public apis
-rw-r--r--docs/reference/glib/glib-overrides.txt10
-rw-r--r--docs/reference/glib/glib-sections.txt.in2
-rw-r--r--gio/gcredentialsprivate.h5
-rw-r--r--glib/docs.c22
-rw-r--r--glib/gspawn.c4
-rw-r--r--glib/tests/date.c2
-rw-r--r--glib/tests/macros.c18
-rw-r--r--glib/tests/option-argv0.c2
-rw-r--r--meson.build4
9 files changed, 62 insertions, 7 deletions
diff --git a/docs/reference/glib/glib-overrides.txt b/docs/reference/glib/glib-overrides.txt
index ea53ea1b7..20c6f8198 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_FREEBSD</NAME>
+#define G_OS_FREEBSD
+</MACRO>
+
+<MACRO>
<NAME>G_OS_DARWIN</NAME>
#define G_OS_DARWIN
</MACRO>
@@ -207,6 +212,11 @@ GCond *cond
</MACRO>
<MACRO>
+<NAME>G_OS_OPENBSD</NAME>
+#define G_OS_OPENBSD
+</MACRO>
+
+<MACRO>
<NAME>G_OS_UNIX</NAME>
#define G_OS_UNIX
</MACRO>
diff --git a/docs/reference/glib/glib-sections.txt.in b/docs/reference/glib/glib-sections.txt.in
index 5478c4795..9219b4426 100644
--- a/docs/reference/glib/glib-sections.txt.in
+++ b/docs/reference/glib/glib-sections.txt.in
@@ -141,7 +141,9 @@ GLIB_VERSION_PREV_STABLE
<FILE>macros</FILE>
<SUBSECTION>
G_OS_DARWIN
+G_OS_FREEBSD
G_OS_LINUX
+G_OS_OPENBSD
G_OS_WIN32
G_OS_UNIX
diff --git a/gio/gcredentialsprivate.h b/gio/gcredentialsprivate.h
index f692f1af7..0d83bf01a 100644
--- a/gio/gcredentialsprivate.h
+++ b/gio/gcredentialsprivate.h
@@ -114,8 +114,7 @@
#define G_CREDENTIALS_SPOOFING_SUPPORTED 1
#define G_CREDENTIALS_HAS_PID 1
-#elif defined(__FreeBSD__) || \
- defined(__FreeBSD_kernel__) /* Debian GNU/kFreeBSD */ || \
+#elif defined(G_OS_FREEBSD) || \
defined(__GNU__) /* GNU Hurd */ || \
defined(__DragonFly__) /* DragonFly BSD */
#define G_CREDENTIALS_SUPPORTED 1
@@ -141,7 +140,7 @@
#define G_CREDENTIALS_SPOOFING_SUPPORTED 1
#define G_CREDENTIALS_HAS_PID 1
-#elif defined(__OpenBSD__)
+#elif defined(G_OS_OPENBSD)
#define G_CREDENTIALS_SUPPORTED 1
#define G_CREDENTIALS_USE_OPENBSD_SOCKPEERCRED 1
#define G_CREDENTIALS_NATIVE_TYPE G_CREDENTIALS_TYPE_OPENBSD_SOCKPEERCRED
diff --git a/glib/docs.c b/glib/docs.c
index ff01b86c7..1e4ea9778 100644
--- a/glib/docs.c
+++ b/glib/docs.c
@@ -1659,6 +1659,17 @@
*/
/**
+ * G_OS_FREEBSD:
+ *
+ * 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.
+ *
+ * Since: 2.76
+ */
+
+/**
* G_OS_LINUX:
*
* This macro is defined only on Linux operating systems. So you can bracket
@@ -1670,6 +1681,17 @@
*/
/**
+ * G_OS_OPENBSD:
+ *
+ * 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.
+ *
+ * Since: 2.76
+ */
+
+/**
* G_OS_WIN32:
*
* This macro is defined only on Windows. So you can bracket
diff --git a/glib/gspawn.c b/glib/gspawn.c
index 6f860d1cb..28c277444 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(__FreeBSD__) || defined(__OpenBSD__) || defined(G_OS_DARWIN)
+#if defined(G_OS_FREEBSD) || defined(G_OS_OPENBSD) || defined(G_OS_DARWIN)
/* Use sysconf() function provided by the system if it is known to be
* async-signal safe.
*
@@ -1534,7 +1534,7 @@ safe_fdwalk_set_cloexec (int lowfd)
static int
safe_closefrom (int lowfd)
{
-#if defined(__FreeBSD__) || defined(__OpenBSD__) || \
+#if defined(G_OS_FREEBSD) || defined(G_OS_OPENBSD) || \
(defined(__sun__) && defined(F_CLOSEFROM))
/* Use closefrom function provided by the system if it is known to be
* async-signal safe.
diff --git a/glib/tests/date.c b/glib/tests/date.c
index 8113ad574..41ef5b6a9 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(__FreeBSD__) || defined(__OpenBSD__) || defined(G_OS_DARWIN)
+#if defined(G_OS_FREEBSD) || defined(G_OS_OPENBSD) || defined(G_OS_DARWIN)
{ "%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 e80128e5d..974d4c489 100644
--- a/glib/tests/macros.c
+++ b/glib/tests/macros.c
@@ -33,6 +33,24 @@
# endif
#endif
+#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
+# ifndef G_OS_UNIX
+ #error "G_OS_UNIX is not defined"
+# endif
+# ifndef G_OS_FREEBSD
+ #error "G_OS_FREEBSD is not defined"
+# endif
+#endif
+
+#if defined (__OpenBSD__)
+# ifndef G_OS_UNIX
+ #error "G_OS_UNIX is not defined"
+# endif
+# ifndef G_OS_OPENBSD
+ #error "G_OS_OPENBSD is not defined"
+# endif
+#endif
+
#if defined (__APPLE__) || defined (HAVE_COCOA) || defined (HAVE_CARBON)
# ifndef G_OS_UNIX
#error "G_OS_UNIX is not defined"
diff --git a/glib/tests/option-argv0.c b/glib/tests/option-argv0.c
index 70e25d946..47f18dadd 100644
--- a/glib/tests/option-argv0.c
+++ b/glib/tests/option-argv0.c
@@ -61,7 +61,7 @@ test_platform_argv0 (void)
* and make them call g_test_skip() instead.
*/
#if !defined HAVE_PROC_SELF_CMDLINE && \
- !defined __OpenBSD__ && \
+ !defined G_OS_OPENBSD && \
!defined G_OS_LINUX && \
!defined G_OS_WIN32
fatal_errors = FALSE;
diff --git a/meson.build b/meson.build
index e721fb356..92f45875e 100644
--- a/meson.build
+++ b/meson.build
@@ -243,6 +243,10 @@ else
glib_os += 'G_WITH_CYGWIN'
elif host_system in ['darwin', 'ios']
glib_os += 'G_OS_DARWIN'
+ elif host_system == 'freebsd'
+ glib_os += 'G_OS_FREEBSD'
+ elif host_system == 'openbsd'
+ glib_os += 'G_OS_OPENBSD'
endif
endif
glib_os_defines = []