#include <assert.h>
#include <sys/types.h>
- #include <sys/socket.h>
+#include <limits.h>
- #include <sys/un.h>
- #include <netinet/in.h>
- #include <netinet/tcp.h>
#ifdef DNETCONN
#include <netdnet/dnetdb.h>
#include <netdnet/dn.h>
return _xcb_parse_display(name, host, NULL, displayp, screenp);
}
-static int _xcb_open_tcp(char *host, char *protocol, const unsigned short port);
+static int _xcb_open_tcp(const char *host, char *protocol, const unsigned short port);
+ #ifndef _WIN32
static int _xcb_open_unix(char *protocol, const char *file);
+ #endif /* !WIN32 */
#ifdef DNETCONN
static int _xcb_open_decnet(const char *host, char *protocol, const unsigned short port);
#endif
return _xcb_open_tcp(host, protocol, port);
}
}
+
+ #ifndef _WIN32
+ filelen = strlen(base) + 1 + sizeof(display) * 3 + 1;
+ file = malloc(filelen);
+ if(file == NULL)
+ return -1;
+
/* display specifies Unix socket */
- filelen = snprintf(file, sizeof(file), "%s%d", base, display);
- if(filelen < 0)
+#ifdef HAVE_LAUNCHD
+ if(strncmp(base, "/tmp/launch", 11) == 0)
+ actual_filelen = snprintf(file, filelen, "%s:%d", base, display);
+ else
+#endif
+ actual_filelen = snprintf(file, filelen, "%s%d", base, display);
+ if(actual_filelen < 0)
+ {
+ free(file);
return -1;
+ }
/* snprintf may truncate the file */
- filelen = MIN(filelen, sizeof(file) - 1);
+ filelen = MIN(actual_filelen, filelen - 1);
#ifdef HAVE_ABSTRACT_SOCKETS
fd = _xcb_open_abstract(protocol, file, filelen);
if (fd >= 0 || (errno != ENOENT && errno != ECONNREFUSED))
+ {
+ free(file);
return fd;
+ }
+
#endif
- return _xcb_open_unix(protocol, file);
+ fd = _xcb_open_unix(protocol, file);
+ free(file);
+
+ return fd;
+ #endif /* !_WIN32 */
+ return -1; /* if control reaches here then something has gone wrong */
}
static int _xcb_socket(int family, int type, int proto)