+ iconv_t handle = iconv_open ("UTF-8", "");
+ if (handle == (iconv_t)(-1))
+ return NULL;
+
+ size_t str_len = strlen (str);
+ char *out = NULL;
+ for (unsigned mul = 4; mul < 8; mul++)
+ {
+ size_t in_size = str_len;
+ const char *in = str;
+ size_t out_max = mul * str_len;
+ char *tmp = out = malloc (1 + out_max);
+ if (!out)
+ break;
+
+ if (iconv (handle, &in, &in_size, &tmp, &out_max) != (size_t)(-1)) {
+ *tmp = '\0';
+ break;
+ }
+ free(out);
+ out = NULL;
+
+ if (errno != E2BIG)
+ break;
+ }
+ iconv_close(handle);
+ return out;