#include #include #include #include #include "ximtext.h" char* ximcompound(const char *s, size_t len, size_t *outlen) { static const char utf8[] = "\033%G"; char *ct; if(s == NULL || len > SIZE_MAX - sizeof utf8) return NULL; ct = xcb_utf8_to_compound_text(s, len, outlen); if(ct != NULL) return ct; /* X11 Compound Text reserves ESC % G for an embedded UTF-8 run. */ ct = malloc(len + sizeof utf8); if(ct == NULL) return NULL; memcpy(ct, utf8, sizeof utf8 - 1); memcpy(ct + sizeof utf8 - 1, s, len); ct[len + sizeof utf8 - 1] = '\0'; if(outlen != NULL) *outlen = len + sizeof utf8 - 1; return ct; }