#include "ks_tables.h"
#include "keysym.h"
-XKB_EXPORT void
+XKB_EXPORT int
xkb_keysym_get_name(xkb_keysym_t ks, char *buffer, size_t size)
{
int i, n, h, idx;
if ((ks & ((unsigned long) ~0x1fffffff)) != 0) {
snprintf(buffer, size, "Invalid");
- return;
+ return -1;
}
/* Try to find it in our hash table. */
if ((entry[0] == val1) && (entry[1] == val2) &&
(entry[2] == val3) && (entry[3] == val4)) {
- snprintf(buffer, size, "%s", entry + 4);
- return;
+ return snprintf(buffer, size, "%s", entry + 4);
}
if (!--n)
if (ks >= 0x01000100 && ks <= 0x0110ffff)
/* Unnamed Unicode codepoint. */
- snprintf(buffer, size, "U%lx", ks & 0xffffffUL);
- else
- /* Unnamed, non-Unicode, symbol (shouldn't generally happen). */
- snprintf(buffer, size, "0x%08x", ks);
+ return snprintf(buffer, size, "U%lx", ks & 0xffffffUL);
+
+ /* Unnamed, non-Unicode, symbol (shouldn't generally happen). */
+ return snprintf(buffer, size, "0x%08x", ks);
}
XKB_EXPORT xkb_keysym_t
*
* @warning If the buffer passed is too small, the string is truncated
* (though still NUL-terminated); a size of at least 32 bytes is recommended.
+ *
+ * @returns The number of bytes in the name, excluding the NUL byte, if
+ * keysym is valid. Otherwise, -1 is returned.
+ *
+ * @remark You may check if truncation has occured by comparing the return
+ * value with the length of buffer, similarly to the snprintf(3) function.
*/
int
xkb_keysym_get_name(xkb_keysym_t keysym, char *buffer, size_t size);