int _XConnectDisplay ( char *display_name, char **fullnamep, /* RETURN */ int *dpynump, /* RETURN */ int *screenp, /* RETURN */ char **auth_namep, /* RETURN */ int *auth_namelenp, /* RETURN */ char **auth_datap, /* RETURN */ int *auth_datalenp) /* RETURN */ { XtransConnInfo trans_conn; trans_conn = _X11TransConnectDisplay ( display_name, fullnamep, dpynump, screenp, auth_namep, auth_namelenp, auth_datap, auth_datalenp); if (trans_conn) { int fd = _X11TransGetConnectionNumber (trans_conn); _X11TransFreeConnInfo (trans_conn); return (fd); } else return (-1); }
static Boolean display_exists_p (int number) { char buf[64]; void *conn; char *fullname = NULL; int idisplay, iscreen; char *conn_auth_name, *conn_auth_data; int conn_auth_namelen, conn_auth_datalen; #ifdef USE_XTRANS_INTERNALS extern void *_X11TransConnectDisplay (); extern void _XDisconnectDisplay (); #endif /* Since connecting to the display waits for a few seconds if the display doesn't exist, check for trivial non-existence - if the socket in /tmp exists or not.. (note: if the socket exists, the server may still not, so we need to try to connect in that case..) */ sprintf (buf, "/tmp/.X11-unix/X%d", number); if (access (buf, F_OK) != 0) return FALSE; #ifdef USE_XTRANS_INTERNALS /* This is a private function that we shouldn't really be calling, but it's the best way to see if the server exists (without needing to hold the necessary authentication to use it) */ sprintf (buf, ":%d", number); conn = _X11TransConnectDisplay (buf, &fullname, &idisplay, &iscreen, &conn_auth_name, &conn_auth_namelen, &conn_auth_data, &conn_auth_datalen); if (conn == NULL) return FALSE; _XDisconnectDisplay (conn); #endif return TRUE; }