X-Git-Url: http://git.demorecorder.com/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fxcb_util.c;h=ba0f10867d8b1c6659e967460bba2a0700380097;hb=c3cfa04b09ff042fed731b17dac3e40de1a10187;hp=1625742b1a440bdbab8f868bfda6b928e9502d75;hpb=d84dd752ef571491b015443fefedca53c7f81282;p=free-sw%2Fxcb%2Flibxcb diff --git a/src/xcb_util.c b/src/xcb_util.c index 1625742..ba0f108 100644 --- a/src/xcb_util.c +++ b/src/xcb_util.c @@ -60,6 +60,10 @@ # include #endif +#ifdef HAVE_LAUNCHD +#include +#endif + int xcb_popcount(uint32_t mask) { uint32_t y; @@ -78,6 +82,59 @@ int xcb_sumof(uint8_t *list, int len) return s; } +#ifdef HAVE_LAUNCHD +/* Return true and parse if name matches [.] + * Upon success: + * host = + * protocol = "unix" + * display = 0 + * screen = + */ +static int _xcb_parse_display_path_to_socket(const char *name, char **host, char **protocol, + int *displayp, int *screenp) +{ + struct stat sbuf; + char path[PATH_MAX]; + int _screen = 0; + + strlcpy(path, name, sizeof(path)); + if (0 != stat(path, &sbuf)) { + char *dot = strrchr(path, '.'); + if (!dot) + return 0; + *dot = '\0'; + + if (0 != stat(path, &sbuf)) + return 0; + + _screen = atoi(dot + 1); + } + + if (host) { + *host = strdup(path); + if (!*host) + return 0; + } + + if (protocol) { + *protocol = strdup("unix"); + if (!*protocol) { + if (host) + free(*host); + return 0; + } + } + + if (displayp) + *displayp = 0; + + if (screenp) + *screenp = _screen; + + return 1; +} +#endif + static int _xcb_parse_display(const char *name, char **host, char **protocol, int *displayp, int *screenp) { @@ -90,10 +147,11 @@ static int _xcb_parse_display(const char *name, char **host, char **protocol, return 0; #ifdef HAVE_LAUNCHD - if(strncmp(name, "/tmp/launch", 11) == 0) - slash = NULL; - else + /* First check for [.] */ + if (_xcb_parse_display_path_to_socket(name, host, protocol, displayp, screenp)) + return 1; #endif + slash = strrchr(name, '/'); if (slash) { @@ -178,14 +236,6 @@ static int _xcb_open(const char *host, char *protocol, const int display) char *file = NULL; int actual_filelen; -#ifdef HAVE_LAUNCHD - if(strncmp(host, "/tmp/launch", 11) == 0) { - base = host; - host = ""; - protocol = "unix"; - } -#endif - /* If protocol or host is "unix", fall through to Unix socket code below */ if ((!protocol || (strcmp("unix",protocol) != 0)) && (*host != '\0') && (strcmp("unix",host) != 0)) @@ -211,18 +261,23 @@ static int _xcb_open(const char *host, char *protocol, const int display) } #endif - filelen = strlen(base) + 1 + sizeof(display) * 3 + 1; - file = malloc(filelen); - if(file == NULL) - return -1; - - /* display specifies Unix socket */ #ifdef HAVE_LAUNCHD - if(strncmp(base, "/tmp/launch", 11) == 0) - actual_filelen = snprintf(file, filelen, "%s:%d", base, display); - else + struct stat sbuf; + if (0 == stat(host, &sbuf)) { + file = strdup(host); + filelen = actual_filelen = strlen(file); + } else #endif + { + filelen = strlen(base) + 1 + sizeof(display) * 3 + 1; + file = malloc(filelen); + if(file == NULL) + return -1; + + /* display specifies Unix socket */ actual_filelen = snprintf(file, filelen, "%s%d", base, display); + } + if(actual_filelen < 0) { free(file); @@ -438,16 +493,17 @@ xcb_connection_t *xcb_connect_to_display_with_auth_info(const char *displayname, if(!parsed) { c = _xcb_conn_ret_error(XCB_CONN_CLOSED_PARSE_ERR); goto out; - } else { + } + #ifdef _WIN32 - WSADATA wsaData; - if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) { - c = _xcb_conn_ret_error(XCB_CONN_ERROR); - goto out; - } -#endif - fd = _xcb_open(host, protocol, display); + WSADATA wsaData; + if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) { + c = _xcb_conn_ret_error(XCB_CONN_ERROR); + goto out; } +#endif + + fd = _xcb_open(host, protocol, display); if(fd == -1) { c = _xcb_conn_ret_error(XCB_CONN_ERROR);