bool QofXmlBackendProvider::type_check (const char *uri) { GStatBuf sbuf; int rc; FILE* t; gchar* filename; QofBookFileType xml_type; gboolean result; if (!uri) { return FALSE; } filename = gnc_uri_get_path (uri); if (0 == g_strcmp0 (filename, QOF_STDOUT)) { result = FALSE; goto det_exit; } t = g_fopen (filename, "r"); if (!t) { PINFO (" new file"); result = TRUE; goto det_exit; } fclose (t); rc = g_stat (filename, &sbuf); if (rc < 0) { result = FALSE; goto det_exit; } if (sbuf.st_size == 0) { PINFO (" empty file"); result = TRUE; goto det_exit; } xml_type = gnc_is_xml_data_file_v2 (filename, NULL); if ((xml_type == GNC_BOOK_XML2_FILE) || (xml_type == GNC_BOOK_XML1_FILE) || (xml_type == GNC_BOOK_POST_XML2_0_0_FILE)) { result = TRUE; goto det_exit; } PINFO (" %s is not a gnc XML file", filename); result = FALSE; det_exit: g_free (filename); return result; }
int main (int argc, char** argv) { const char* directory = g_getenv ("GNC_TEST_FILES"); if (!directory) { directory = "test-files/xml2"; } char* filename = static_cast<decltype (filename)> (malloc (strlen ( directory) + 1 + strlen (FILENAME) + 1)); sprintf (filename, "%s/%s", directory, FILENAME); do_test (gnc_is_xml_data_file_v2 (filename, NULL), "gnc_is_xml_data_file_v2"); print_test_results (); exit (get_rv ()); }