2 * Copyright (C) 2016 J. Ali Harlow <ali@juiblex.co.uk>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "plover/plover.h"
26 static GList *open_razor_files;
28 static void *file_get_contents(const char *uri,size_t *length,int private,
29 struct razor_error **error)
37 g_message("file_get_contents(%s)",uri);
38 file=g_file_new_for_uri(uri);
39 path=g_file_get_path(file);
43 addr=razor_file_default_get_contents(path,length,private,error);
45 open_razor_files=g_list_prepend(open_razor_files,addr);
48 else if (!g_file_load_contents(file,NULL,&contents,&len,NULL,&err))
50 plover_propagate_g_error(error,err);
64 static int file_free_contents(void *addr,size_t length)
68 g_message("file_free_contents(%p)",addr);
69 lnk=g_list_find(open_razor_files,addr);
72 open_razor_files=g_list_delete_link(open_razor_files,lnk);
73 retval=razor_file_default_free_contents(addr,length);
83 void plover__file_io_init(void)
86 struct razor_file_vtable file_vtable;
87 g_message("plover__file_io_init()");
88 if (g_once_init_enter(&init))
90 file_vtable.get_contents=file_get_contents;
91 file_vtable.free_contents=file_free_contents;
92 razor_file_set_vtable(&file_vtable);
93 g_once_init_leave(&init,1);