_config_edd = NULL;
}
-static int _cb_sort_files(char *f1, char *f2)
+static int
+_sort_files_cb(const void *f1, const void *f2)
{
return strcmp(f1, f2);
}
Eina_List *
_elm_config_profiles_list(void)
{
+ const Eina_File_Direct_Info *info;
const char *home = NULL;
Eina_List *flist = NULL;
- char buf[PATH_MAX], *p;
- Eina_List *files;
+ Eina_Iterator *file_it;
+ struct stat buffer;
+ char buf[PATH_MAX];
+ const char *dir;
size_t len;
home = getenv("HOME");
".elementary/config",
sizeof(".elementary/config") - 1);
- files = ecore_file_ls(buf);
+ file_it = eina_file_direct_ls(buf);
+ if (!file_it)
+ goto sys;
buf[len] = '/';
len++;
- p = buf + len;
len = sizeof(buf) - len;
- if (files)
+
+ EINA_ITERATOR_FOREACH(file_it, info)
{
- char *file;
-
- files = eina_list_sort(files, 0, (Eina_Compare_Cb)_cb_sort_files);
- EINA_LIST_FREE(files, file)
- {
- if (eina_strlcpy(p, file, len) >= len)
- {
- free(file);
- continue;
- }
- if (ecore_file_is_dir(buf))
- flist = eina_list_append(flist, file);
- else
- free(file);
- }
+ if (info->name_length >= len)
+ continue;
+
+ switch (info->dirent->d_type)
+ {
+ case DT_UNKNOWN:
+ if (stat(info->path, &buffer) != 0)
+ goto it_free;
+
+ if (S_ISDIR(buffer.st_mode))
+ flist =
+ eina_list_sorted_insert(flist, _sort_files_cb,
+ eina_stringshare_add(info->path +
+ info->name_start));
+ break;
+
+ case DT_DIR:
+ flist =
+ eina_list_sorted_insert(flist, _sort_files_cb,
+ eina_stringshare_add(info->path +
+ info->name_start));
+ break;
+
+ default:
+ continue;
+ }
}
+ eina_iterator_free(file_it);
+
+ sys:
len = eina_str_join_len(buf, sizeof(buf), '/', _elm_data_dir,
strlen(_elm_data_dir), "config",
sizeof("config") - 1);
- files = ecore_file_ls(buf);
+ file_it = eina_file_direct_ls(buf);
+ if (!file_it)
+ goto list_free;
buf[len] = '/';
len++;
- p = buf + len;
+#define S_ISDIR_CASE_DO \
+ { \
+ const Eina_List *l; \
+ const char *tmp; \
+ EINA_LIST_FOREACH(flist, l, tmp) \
+ if (!strcmp(info->path + info->name_start, tmp)) \
+ break; \
+ \
+ if (!l) \
+ flist = \
+ eina_list_sorted_insert(flist, _sort_files_cb, \
+ eina_stringshare_add(info->path + \
+ info->name_start)); \
+ } \
+
len = sizeof(buf) - len;
- if (files)
+ EINA_ITERATOR_FOREACH(file_it, info)
{
- char *file;
- files = eina_list_sort(files, 0, (Eina_Compare_Cb)_cb_sort_files);
- EINA_LIST_FREE(files, file)
- {
- if (eina_strlcpy(p, file, len) >= len)
- {
- free(file);
- continue;
- }
- if (ecore_file_is_dir(buf))
- {
- const Eina_List *l;
- const char *tmp;
- EINA_LIST_FOREACH(flist, l, tmp)
- if (!strcmp(file, tmp)) break;
-
- if (!l)
- flist = eina_list_append(flist, file);
- else free(file);
- }
- else
- free(file);
- }
+ if (info->name_length >= len)
+ continue;
+
+ switch (info->dirent->d_type)
+ {
+ case DT_UNKNOWN:
+ if (stat(info->path, &buffer) != 0)
+ goto it_free;
+
+ if (S_ISDIR(buffer.st_mode))
+ S_ISDIR_CASE_DO
+ break;
+
+ case DT_DIR:
+ S_ISDIR_CASE_DO
+ break;
+
+ default:
+ continue;
+ }
}
return flist;
+
+#undef S_ISDIR_CASE_DO
+
+ it_free:
+ eina_iterator_free(file_it);
+
+ list_free:
+ EINA_LIST_FREE(flist, dir)
+ eina_stringshare_del(dir);
+
+ return NULL;
}
static void
* @return The profile's directory path.
* @ingroup Profile
*
- * @note You must free() the return value after usage.
+ * @note You must free it with elm_profile_dir_free().
*/
EAPI char *
elm_profile_dir_get(const char *profile)
return _elm_config_profile_dir_get(profile);
}
+/**
+ * Free an Elementary's profile directory path, as returned by
+ * elm_profile_dir_get().
+ *
+ * @param p_dir The profile's path
+ * @ingroup Profile
+ *
+ */
+EAPI void
+elm_profile_dir_free(const char *p_dir)
+{
+ free((void *)p_dir);
+}
+
/**
* Get Elementary's list of available profiles.
*
* @return The profiles list.
* @ingroup Profile
*
- * @note You must free() the strings which came as list data after
- * usage of the return value. Consider using the @c EINA_LIST_FREE()
- * macro.
+ * @note One must free this list, after usage, with the function
+ * elm_profile_list_free().
*/
EAPI Eina_List *
elm_profile_list_get(void)
return _elm_config_profiles_list();
}
+/**
+ * Free Elementary's list of available profiles.
+ *
+ * @param The profiles list, as returned by elm_profile_list_get().
+ * @ingroup Profile
+ *
+ */
+EAPI void
+elm_profile_list_free(Eina_List *l)
+{
+ const char *dir;
+
+ EINA_LIST_FREE(l, dir)
+ eina_stringshare_del(dir);
+}
+
/**
* Set Elementary's profile.
*