From 3e924f23451a3bcbad68d5250234e1eb1a987855 Mon Sep 17 00:00:00 2001
From: sghctoma <sghctoma@gmail.com>
Date: Wed, 26 Sep 2018 20:05:45 +0200
Subject: [PATCH 1/2] Add _C11_SOURCE feature test macro on FreeBSD

This will restrict the default namespace set on FreeBSD to the C11
standard (everything is visible by default), which will prevent possible
conflicts with symbols hidden behing __BSD_VISIBLE.
---
 meson.build | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/meson.build b/meson.build
index 82e4a96fd..76eaff203 100644
--- a/meson.build
+++ b/meson.build
@@ -22,6 +22,10 @@ datadir = get_option('datadir')
 sysconfdir = get_option('sysconfdir')
 prefix = get_option('prefix')
 
+if is_freebsd
+	add_project_arguments('-D_C11_SOURCE', language: 'c')
+endif
+
 swayidle_deps = []
 
 jsonc          = dependency('json-c', version: '>=0.13')

From 2f258eff6fd2c89a94caa658c1ea22beb76d728a Mon Sep 17 00:00:00 2001
From: sghctoma <sghctoma@gmail.com>
Date: Wed, 26 Sep 2018 20:10:53 +0200
Subject: [PATCH 2/2] Make sway/ipc-server.c POSIX 2001 compliant

This commit replaces the non-standard SOCK_NONBLOCK and SOCK_CLOEXEC
flags with two fcntl calls. This makes the file POSIX 2001 compliant,
thus it is no longer necessary to conditionally define, or use internal
(__BSD_VISIBLE) feature test macros.
---
 sway/ipc-server.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index 99959c97b..2d915502f 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -1,8 +1,5 @@
 // See https://i3wm.org/docs/ipc.html for protocol information
-#ifndef __FreeBSD__
-// Any value will hide SOCK_CLOEXEC on FreeBSD (__BSD_VISIBLE=0)
-#define _XOPEN_SOURCE 700
-#endif
+#define _POSIX_C_SOURCE 200112L
 #ifdef __linux__
 #include <linux/input-event-codes.h>
 #elif __FreeBSD__
@@ -89,10 +86,16 @@ static void handle_display_destroy(struct wl_listener *listener, void *data) {
 }
 
 void ipc_init(struct sway_server *server) {
-	ipc_socket = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
+	ipc_socket = socket(AF_UNIX, SOCK_STREAM, 0);
 	if (ipc_socket == -1) {
 		sway_abort("Unable to create IPC socket");
 	}
+	if (fcntl(ipc_socket, F_SETFD, FD_CLOEXEC) == -1) {
+		sway_abort("Unable to set CLOEXEC on IPC socket");
+	}
+	if (fcntl(ipc_socket, F_SETFL, O_NONBLOCK) == -1) {
+		sway_abort("Unable to set NONBLOCK on IPC socket");
+	}
 
 	ipc_sockaddr = ipc_user_sockaddr();