Blob Blame History Raw
diff -up libxcb-1.1/configure.ac.abstract libxcb-1.1/configure.ac
--- libxcb-1.1/configure.ac.abstract	2008-10-13 14:03:41.000000000 -0400
+++ libxcb-1.1/configure.ac	2008-10-13 14:04:47.000000000 -0400
@@ -62,6 +62,8 @@
 AC_SEARCH_LIBS(getaddrinfo, socket)
 AC_SEARCH_LIBS(connect, socket)
 
+AC_DEFINE([HAVE_ABSTRACT_SOCKETS], 1, [Define if your platform supports abstract sockets])
+
 xcbincludedir='${includedir}/xcb'
 AC_SUBST(xcbincludedir)
 
--- libxcb-1.1/src/xcb_util.c.abstract	2007-10-23 12:44:59.000000000 -0400
+++ libxcb-1.1/src/xcb_util.c	2008-10-13 14:03:41.000000000 -0400
@@ -38,6 +38,7 @@
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <stddef.h>
 #include <unistd.h>
 #include <string.h>
 
@@ -123,6 +124,11 @@
 #ifdef DNETCONN
 static int _xcb_open_decnet(const char *host, char *protocol, const unsigned short port);
 #endif
+#ifdef HAVE_ABSTRACT_SOCKETS
+static int _xcb_open_abstract(char *protocol, const char *file);
+#else
+#error d'oh
+#endif
 
 static int _xcb_open(char *host, char *protocol, const int display)
 {
@@ -156,10 +162,13 @@
 
     /* display specifies Unix socket */
     snprintf(file, sizeof(file), "%s%d", base, display);
-    return  _xcb_open_unix(protocol, file);
-
+#ifdef HAVE_ABSTRACT_SOCKETS
+    fd = _xcb_open_abstract(protocol, file);
+    if (fd >= 0 || (errno != ENOENT && errno != ECONNREFUSED))
+        return fd;
 
-    return fd;
+#endif
+    return  _xcb_open_unix(protocol, file);
 }
 
 #ifdef DNETCONN
@@ -259,6 +268,33 @@
     return fd;
 }
 
+#ifdef HAVE_ABSTRACT_SOCKETS
+static int _xcb_open_abstract(char *protocol, const char *file)
+{
+    int fd;
+    struct sockaddr_un addr = {0};
+    socklen_t namelen;
+
+    if (protocol && strcmp("unix",protocol))
+        return -1;
+
+    strcpy(addr.sun_path + 1, file);
+    addr.sun_family = AF_UNIX;
+    namelen = offsetof(struct sockaddr_un, sun_path) + 1 + strlen(file);
+#ifdef HAVE_SOCKADDR_SUN_LEN
+    addr.sun_len = 1 + strlen(file);
+#endif
+    fd = socket(AF_UNIX, SOCK_STREAM, 0);
+    if (fd == -1)
+        return -1;
+    if (connect(fd, (struct sockaddr *) &addr, namelen) == -1) {
+        close(fd);
+        return -1;
+    }
+    return fd;
+}
+#endif
+
 xcb_connection_t *xcb_connect(const char *displayname, int *screenp)
 {
     int fd, display = 0;