#include "setting.h"
#include "completion.h"
#include "hints.h"
+#include "util.h"
static CommandInfo cmd_list[] = {
/* command function arg mode */
gboolean result;
Arg a = {arg->i};
- g_file_get_contents(vp.files[FILES_CLOSED], &a.s, NULL, NULL);
+ a.s = util_get_file_contents(vp.files[FILES_CLOSED], NULL);
result = vp_load_uri(&a);
g_free(a.s);
fclose(f);
}
}
+
+/**
+ * Retrieves the length bytes from given file.
+ *
+ * The memory of returned string have to be freed!
+ */
+gchar* util_get_file_contents(const gchar* filename, gsize* length)
+{
+ GError* error = NULL;
+ gchar* content = NULL;
+ if (!(g_file_test(filename, G_FILE_TEST_IS_REGULAR)
+ && g_file_get_contents(filename, &content, length, &error))
+ ) {
+ fprintf(stderr, "Cannot open %s: %s\n", filename, error ? error->message : "file not found");
+ g_clear_error(&error);
+ }
+ return content;
+}
const gchar* util_get_home_dir(void);
void util_create_dir_if_not_exists(const gchar* dirpath);
void util_create_file_if_not_exists(const gchar* filename);
+gchar* util_get_file_contents(const gchar* filename, gsize* length);
#endif /* end of include guard: UTIL_H */