#include #include #include "lx.h" #include "proto.h" #include "internal.h" typedef struct priv_GetAtomName PRIV_GetAtomName; struct priv_GetAtomName { int *lenp; char **strp; } ; static void done_GetAtomName(LX_CONN *xc, const unsigned char *rep, void *pv) { PRIV_GetAtomName *p; int n; char *s; p = pv; do <"ret"> { n = r_card16(rep+8); if (r_card32(rep+4) != ((n+3)>>2)) { lx__protoerr(xc,"GetAtomName response length wrong (%u, expecting %d)",r_card32(rep+4),(n+3)>>2); break <"ret">; } do <"fail"> { do <"mem"> { if (p->strp) { s = malloc(n+1); if (! s) break <"mem">; bcopy(rep+32,s,n); s[n] = '\0'; *p->strp = s; } if (p->lenp) *p->lenp = n; break <"ret">; } while (0); lx__nomem_fail(xc); } while (0); } while (0); free(p); } LX_OP *lx_GetAtomName(LX_CONN *xc, LX_XID atom, int *lenp, char **strp) { unsigned char req[8]; PRIV_GetAtomName *p; if (xc->flags & XCF_FAIL) { lx__bad_call(xc,"lx_GetAtomName"); return(0); } lx__nochain(xc); p = malloc(sizeof(PRIV_GetAtomName)); if (! p) { lx__nomem_fail(xc); return(0); } p->lenp = lenp; p->strp = strp; req[0] = XP_REQ_GetAtomName; req[1] = 0; w_card16(&req[2],2); w_card32(&req[4],atom); return(lx__expect_reply(xc,&req[0],-1,&done_GetAtomName,p)); }