2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
14 #include <sys/param.h>
15 #include <sys/types.h>
19 #include "Ecore_Config.h"
20 #include "ecore_config_private.h"
23 * Loads the default configuration.
24 * @return @c ECORE_CONFIG_ERR_SUCC on success. @c ECORE_CONFIG_ERR_NODATA
25 * is returned if the file cannot be loaded.
26 * @ingroup Ecore_Config_File_Group
29 ecore_config_load(void)
33 if (!__ecore_config_app_name)
34 return ECORE_CONFIG_ERR_FAIL;
36 snprintf(file, PATH_MAX, "%s/.e/apps/%s/config.eet", getenv("HOME"),
37 __ecore_config_app_name);
38 return ecore_config_file_load(file);
42 * Saves the current configuration to the default file.
43 * @return @c ECORE_CONFIG_ERR_SUCC is returned on success.
44 * @c ECORE_CONFIG_ERR_FAIL is returned if the data cannot be
46 * @ingroup Ecore_Config_File_Group
49 ecore_config_save(void)
53 if (!__ecore_config_app_name)
54 return ECORE_CONFIG_ERR_FAIL;
56 snprintf(file, PATH_MAX, "%s/.e/apps/%s/config.eet", getenv("HOME"),
57 __ecore_config_app_name);
58 return ecore_config_file_save(file);
62 * Load the given configuration file to the local configuration.
63 * @param file Name of the file to load.
64 * @return @c ECORE_CONFIG_ERR_SUCC on success. @c ECORE_CONFIG_ERR_NODATA
65 * is returned if the file cannot be loaded.
66 * @ingroup Ecore_Config_File_Group
69 ecore_config_file_load(const char *file)
71 Ecore_Config_DB_File *db;
75 // double ftmp; UNUSED
78 // Ecore_Config_Type type; UNUSED
84 db = _ecore_config_db_open_read(file);
87 ERR("Cannot open database from file %s!", file);
88 return ECORE_CONFIG_ERR_NODATA;
91 keys = _ecore_config_db_keys_get(db, &key_count);
94 for (x = 0; x < key_count; x++)
96 _ecore_config_db_read(db, keys[x]);
99 _ecore_config_db_close(db);
102 for (x = 0; x < key_count; x++)
108 return ECORE_CONFIG_ERR_SUCC;
112 _ecore_config_recurse_mkdir(const char *file)
118 file_tmp = strdup(file);
119 file_ptr = file_tmp + strlen(file_tmp);
120 while (*file_ptr != '/' && file_ptr > file_tmp)
124 if ((file_tmp[0] != 0) && stat(file_tmp, &status))
126 _ecore_config_recurse_mkdir(file_tmp);
127 mkdir(file_tmp, S_IRUSR | S_IWUSR | S_IXUSR);
133 * Saves the local configuration to the given file.
134 * @param file Name of the file to save to.
135 * @return @c ECORE_CONFIG_ERR_SUCC is returned on success.
136 * @c ECORE_CONFIG_ERR_FAIL is returned if the data cannot be
138 * @ingroup Ecore_Config_File_Group
141 ecore_config_file_save(const char *file)
143 Ecore_Config_Prop *next;
144 Ecore_Config_DB_File *db;
147 next = __ecore_config_bundle_local->data;
150 /* if file does not exist check to see if the dirs exist, creating if not */
151 if (stat(file, &status))
152 _ecore_config_recurse_mkdir(file);
154 db = _ecore_config_db_open_write(file);
157 ERR("Cannot open database from file %s!", file);
158 return ECORE_CONFIG_ERR_FAIL;
163 /* let the config_db deal with this
164 * handyande: hmm, not sure that it ever does - reinstating until
165 * further discussions satisfy me!
167 if (!(next->flags & ECORE_CONFIG_FLAG_MODIFIED) || next->flags & ECORE_CONFIG_FLAG_CMDLN)
173 _ecore_config_db_write(db, next);
178 _ecore_config_db_close(db);
179 return ECORE_CONFIG_ERR_SUCC;