Rewrite gfec_eval_file to avoid opening the file itself in guile

This is a continuation of
Bug 711567 - Cannot save a custom report if a path contain diacritic chars
However this commit deals with reading the file
This commit is contained in:
Geert Janssens 2014-09-21 22:01:30 +02:00
parent db6c83cdb6
commit 2e4021978d

View File

@ -151,41 +151,28 @@ gfec_eval_string(const char *str, gfec_error_handler error_handler)
return result;
}
static SCM
gfec_file_helper(void *data)
{
char *string = data;
return scm_c_primitive_load(file);
}
SCM
gfec_eval_file(const char *file, gfec_error_handler error_handler)
{
char *err_msg = NULL;
gchar *contents = NULL;
GError *save_error = NULL;
SCM result;
result = scm_internal_stack_catch(SCM_BOOL_T,
gfec_file_helper,
(void *) file,
gfec_catcher,
&err_msg);
if (err_msg != NULL)
if (!g_file_get_contents (file, &contents, NULL, &save_error))
{
if (error_handler)
{
gchar *full_msg = g_strdup_printf("Could not load file %s: %s",
file, err_msg);
error_handler(full_msg);
g_free(full_msg);
}
gchar *full_msg = g_strdup_printf ("Couldn't read contents of %s.\nReason: %s", file, save_error->message);
error_handler(full_msg);
free(err_msg);
g_error_free (save_error);
g_free(full_msg);
return SCM_UNDEFINED;
}
result = gfec_eval_string (contents, error_handler);
g_free (contents);
return result;
}