move set_nonblock, create_socket and path_exists to libi3

This commit is contained in:
Michael Stapelberg
2021-01-15 14:48:10 +01:00
committed by Michael Stapelberg
parent e4f12ac349
commit 131a6158c8
8 changed files with 139 additions and 76 deletions

20
libi3/nonblock.c Normal file
View File

@ -0,0 +1,20 @@
#include "libi3.h"
#include <err.h>
#include <fcntl.h>
/*
* Puts the given socket file descriptor into non-blocking mode or dies if
* setting O_NONBLOCK failed. Non-blocking sockets are a good idea for our
* IPC model because we should by no means block the window manager.
*
*/
void set_nonblock(int sockfd) {
int flags = fcntl(sockfd, F_GETFL, 0);
if (flags & O_NONBLOCK) {
return;
}
flags |= O_NONBLOCK;
if (fcntl(sockfd, F_SETFL, flags) < 0)
err(-1, "Could not set O_NONBLOCK");
}