30 iconv_t guessConverter(
const char*
buffer,
size_t len)
32 char*
const target =
"utf-8";
34 iconv_t iconvCookie = NULL;
36 gchar* encoding = guessEncoding(buffer, len);
37 if (encoding && (strcmp(encoding, target) != 0))
39 iconvCookie = iconv_open(target, encoding);
46 gchar* guessEncoding(
const char* buffer,
size_t len) {
49 uchardet_t cd = uchardet_new();
50 if (!uchardet_handle_data(cd, buffer, len)) {
51 uchardet_data_end(cd);
53 const char* chardet = uchardet_get_charset(cd);
55 if (chardet && strcmp(chardet,
"")!=0) {
56 result = g_strdup(chardet);
62 magic_t cookie = magic_open(MAGIC_MIME);
63 magic_load(cookie, NULL);
65 const char* resp = magic_buffer(cookie, buffer, len);
69 printf(
"magic error: %s\n", magic_error(cookie));
73 char* charset = strstr(resp,
"charset=");
82 result = g_strdup(charset);
char buffer[2048]
The last thing received from the scheduler.