* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
- * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
+ * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
*
*/
#include <err.h>
*/
char *convert_ucs2_to_utf8(xcb_char2b_t *text, size_t num_glyphs) {
/* Allocate the output buffer (UTF-8 is at most 4 bytes per glyph) */
- size_t buffer_size = num_glyphs * 4 * sizeof(char) + 1;
- char *buffer = scalloc(buffer_size * sizeof(char));
+ size_t buffer_size = num_glyphs * 4 + 1;
+ char *buffer = scalloc(buffer_size, 1);
/* We need to use an additional pointer, because iconv() modifies it */
char *output = buffer;
utf8_conversion_descriptor = iconv_open("UTF-8", "UCS-2BE");
if (utf8_conversion_descriptor == (iconv_t)-1)
err(EXIT_FAILURE, "Error opening the conversion context");
- }
- else {
+ } else {
/* Reset the existing conversion descriptor */
iconv(utf8_conversion_descriptor, NULL, NULL, NULL, NULL);
}
/* Do the conversion */
size_t input_len = num_glyphs * sizeof(xcb_char2b_t);
- size_t rc = iconv(utf8_conversion_descriptor, (char**)&text,
- &input_len, &output, &output_size);
+ size_t rc = iconv(utf8_conversion_descriptor, (char **)&text,
+ &input_len, &output, &output_size);
if (rc == (size_t)-1) {
perror("Converting to UTF-8 failed");
free(buffer);
* returned. It has to be freed when done.
*
*/
-xcb_char2b_t *convert_utf8_to_ucs2(char *input, int *real_strlen) {
+xcb_char2b_t *convert_utf8_to_ucs2(char *input, size_t *real_strlen) {
/* Calculate the input buffer size (UTF-8 is strlen-safe) */
size_t input_size = strlen(input);
ucs2_conversion_descriptor = iconv_open("UCS-2BE", "UTF-8");
if (ucs2_conversion_descriptor == (iconv_t)-1)
err(EXIT_FAILURE, "Error opening the conversion context");
- }
- else {
+ } else {
/* Reset the existing conversion descriptor */
iconv(ucs2_conversion_descriptor, NULL, NULL, NULL, NULL);
}
/* Do the conversion */
- size_t rc = iconv(ucs2_conversion_descriptor, (char**)&input,
- &input_size, (char**)&output, &output_size);
+ size_t rc = iconv(ucs2_conversion_descriptor, (char **)&input,
+ &input_size, (char **)&output, &output_size);
if (rc == (size_t)-1) {
perror("Converting to UCS-2 failed");
free(buffer);