1 /* vifm
2 * Copyright (C) 2015 xaizek.
3 *
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.
8 *
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.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 #include "fsddata.h"
20
21 #include <stddef.h> /* NULL */
22 #include <stdlib.h> /* free() */
23
24 #include "private/fsdata.h"
25 #include "fsdata.h"
26
27 static void cleanup(void *data);
28
29 fsddata_t *
fsddata_create(int prefix,int resolve_paths)30 fsddata_create(int prefix, int resolve_paths)
31 {
32 fsdata_t *const fsd = fsdata_create(prefix, resolve_paths);
33 if(fsd != NULL)
34 {
35 fsdata_set_cleanup(fsd, &cleanup);
36 }
37 return (fsddata_t *)fsd;
38 }
39
40 /* fsdata cleanup function that frees memory associated with a node. */
41 static void
cleanup(void * data)42 cleanup(void *data)
43 {
44 void **p = data;
45 free(*p);
46 }
47
48 void
fsddata_free(fsddata_t * fsdd)49 fsddata_free(fsddata_t *fsdd)
50 {
51 fsdata_free((fsdata_t *)fsdd);
52 }
53
54 int
fsddata_set(fsddata_t * fsdd,const char path[],void * data)55 fsddata_set(fsddata_t *fsdd, const char path[], void *data)
56 {
57 return fsdata_set((fsdata_t *)fsdd, path, &data, sizeof(data));
58 }
59
60 int
fsddata_get(fsddata_t * fsdd,const char path[],void ** data)61 fsddata_get(fsddata_t *fsdd, const char path[], void **data)
62 {
63 return fsdata_get((fsdata_t *)fsdd, path, data, sizeof(*data));
64 }
65
66 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
67 /* vim: set cinoptions+=t0 filetype=c : */
68