9200094203
This has multiple effects: 1) The i3 codebase is now consistently formatted. clang-format uncovered plenty of places where inconsistent code made it into our code base. 2) When writing code, you don’t need to think or worry about our coding style. Write it in yours, then run clang-format-3.5 3) When submitting patches, we don’t need to argue about coding style. The basic idea is that we don’t want to care about _how_ we write the code, but _what_ it does :). The coding style that we use is defined in the .clang-format config file and is based on the google style, but adapted in such a way that the number of modifications to the i3 code base is minimal.
40 lines
1.0 KiB
C
40 lines
1.0 KiB
C
/*
|
|
* vim:ts=4:sw=4:expandtab
|
|
*
|
|
* i3 - an improved dynamic tiling window manager
|
|
* © 2009-2013 Michael Stapelberg and contributors (see also: LICENSE)
|
|
*
|
|
*/
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <sys/un.h>
|
|
#include <string.h>
|
|
#include <err.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
|
|
#include "libi3.h"
|
|
|
|
/*
|
|
* Connects to the i3 IPC socket and returns the file descriptor for the
|
|
* socket. die()s if anything goes wrong.
|
|
*
|
|
*/
|
|
int ipc_connect(const char *socket_path) {
|
|
int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
|
|
if (sockfd == -1)
|
|
err(EXIT_FAILURE, "Could not create socket");
|
|
|
|
(void)fcntl(sockfd, F_SETFD, FD_CLOEXEC);
|
|
|
|
struct sockaddr_un addr;
|
|
memset(&addr, 0, sizeof(struct sockaddr_un));
|
|
addr.sun_family = AF_LOCAL;
|
|
strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1);
|
|
if (connect(sockfd, (const struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0)
|
|
err(EXIT_FAILURE, "Could not connect to i3");
|
|
|
|
return sockfd;
|
|
}
|