static void test_by_data (const char *dir, const char *filename, const char *mt_expected, int xfail) { FILE *file; const char *mt; int max_extent; char *data; int bytes_read; int result_prio; char path[1024]; snprintf (path, 1024, "%s/%s", dir, filename); file = fopen (path, "r"); if (file == NULL) { printf ("Could not open %s\n", path); error++; return; } max_extent = xdg_mime_get_max_buffer_extents (); data = malloc (max_extent); if (data == NULL) { printf ("Failed to allocate memory for file %s\n", filename); error++; return; } bytes_read = fread (data, 1, max_extent, file); if (ferror (file)) { printf ("Error reading file %s\n", path); error++; free (data); fclose (file); return; } mt = xdg_mime_get_mime_type_for_data (data, bytes_read, &result_prio); free (data); fclose (file); check_mime_type (mt, mt_expected, xfail, "data", filename); }
gsize _g_unix_content_type_get_sniff_len (void) { gsize size; G_LOCK (gio_xdgmime); size = xdg_mime_get_max_buffer_extents (); G_UNLOCK (gio_xdgmime); return size; }