static int
strcmplen(const void *data1, const void *data2)
{
- return strncmp(data1, data2, strlen(data2));
+ return strncmp(data1, data2, eina_stringshare_strlen(data2));
}
static int
int priority = 0;
char *dir = NULL;
char *map = MAP_FAILED;
+ char *path;
int fd = -1, tmpfd, dirsfd = -1;
struct stat st;
int changed = 0;
{
unsigned int size = *(unsigned int *)p;
p += sizeof(unsigned int);
- user_dirs = eina_list_append(user_dirs, strdup(p));
+ user_dirs = eina_list_append(user_dirs, eina_stringshare_add(p));
p += size;
}
munmap(map, st.st_size);
if (ftruncate(dirsfd, 0) < 0) goto error;
}
- while (dirs)
+ EINA_LIST_FREE(dirs, path)
{
char file_id[PATH_MAX] = { '\0' };
- char *path;
Eina_List *l;
- path = eina_list_data_get(dirs);
- if (path)
+ if (!cache_scan(path, file_id, priority++, 1, &changed)) goto error;
+ l = eina_list_search_unsorted_list(user_dirs, strcmplen, path);
+ if (l)
{
- if (!cache_scan(path, file_id, priority++, 1, &changed)) goto error;
- l = eina_list_search_unsorted_list(user_dirs, strcmplen, path);
- if (l)
- {
- free(eina_list_data_get(l));
- user_dirs = eina_list_remove_list(user_dirs, l);
- }
- free(path);
+ eina_stringshare_del(eina_list_data_get(l));
+ user_dirs = eina_list_remove_list(user_dirs, l);
}
- dirs = eina_list_remove_list(dirs, dirs);
+ eina_stringshare_del(path);
}
EINA_LIST_FREE(user_dirs, dir)
{
write(dirsfd, dir, size);
}
if (!cache_scan(dir, NULL, priority, 0, &changed)) goto error;
- free(dir);
+ eina_stringshare_del(dir);
}
eina_hash_free(file_ids);
eina_hash_free(paths);
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <limits.h>
#include "Efreet.h"
#include "efreet_private.h"
efreet_parse_locale_setting(const char *env)
{
int found = 0;
- char *setting;
+ char setting[PATH_MAX];
char *p;
- setting = getenv(env);
- if (!setting) return 0;
- setting = strdup(setting);
+ p = getenv(env);
+ if (!p) return 0;
+ strncpy(setting, p, sizeof(setting));
+ setting[PATH_MAX - 1] = '\0';
/* pull the modifier off the end */
p = strrchr(setting, '@');
found = 1;
}
- if (setting && (*setting != '\0'))
+ if (*setting != '\0')
{
efreet_lang = eina_stringshare_add(setting);
found = 1;
}
- FREE(setting);
-
return found;
}
#include <stdio.h>
#include <string.h>
+#include <limits.h>
#include "Efreet.h"
#include "efreet_private.h"
{
Eina_List *dirs = NULL;
const char *path;
- char *tmp, *s, *p;
+ char tmp[PATH_MAX], *s, *p;
path = getenv(key);
if (!path || (path[0] == '\0')) path = fallback;
if (!path) return dirs;
- tmp = strdup(path);
+ strncpy(tmp, path, sizeof(tmp));
+ tmp[PATH_MAX - 1] = '\0';
s = tmp;
p = strchr(s, EFREET_PATH_SEP);
while (p)
}
if (!eina_list_search_unsorted(dirs, EINA_COMPARE_CB(strcmp), s))
dirs = eina_list_append(dirs, (void *)eina_stringshare_add(s));
- FREE(tmp);
return dirs;
}
static const char *efreet_menu_prefix = NULL; /**< The $XDG_MENU_PREFIX env var */
Eina_List *efreet_menu_kde_legacy_dirs = NULL; /**< The directories to use for KDELegacy entries */
static const char *efreet_tag_menu = NULL;
-static char *efreet_menu_file = NULL; /**< A menu file set explicityl as default */
+static const char *efreet_menu_file = NULL; /**< A menu file set explicityl as default */
static Eina_Hash *efreet_merged_menus = NULL;
static Eina_Hash *efreet_merged_dirs = NULL;
void
efreet_menu_shutdown(void)
{
- IF_FREE(efreet_menu_file);
+ IF_RELEASE(efreet_menu_file);
IF_FREE_HASH(efreet_menu_handle_cbs);
IF_FREE_HASH(efreet_menu_filter_cbs);
EAPI void
efreet_menu_file_set(const char *file)
{
- IF_FREE(efreet_menu_file);
+ IF_RELEASE(efreet_menu_file);
efreet_menu_file = NULL;
- if (file) efreet_menu_file = strdup(file);
+ if (file) efreet_menu_file = eina_stringshare_add(file);
}
/**
Eina_List *l;
snprintf(dir, sizeof(dir), "%s/%s", user_dir, suffix);
- list = eina_list_append(list, strdup(dir));
+ list = eina_list_append(list, eina_stringshare_add(dir));
EINA_LIST_FOREACH(system_dirs, l, xdg_dir)
{
snprintf(dir, sizeof(dir), "%s/%s", xdg_dir, suffix);
- list = eina_list_append(list, strdup(dir));
+ list = eina_list_append(list, eina_stringshare_add(dir));
}
return list;
"applications");
EINA_LIST_FREE(dirs, dir)
{
- Efreet_Menu_App_Dir *app_dir;
-
- if (eina_list_search_unsorted(parent->app_dirs,
- EINA_COMPARE_CB(efreet_menu_cb_app_dirs_compare),
- dir))
- continue;
+ if (!eina_list_search_unsorted(parent->app_dirs,
+ EINA_COMPARE_CB(efreet_menu_cb_app_dirs_compare),
+ dir))
+ {
+ Efreet_Menu_App_Dir *app_dir;
- app_dir = efreet_menu_app_dir_new();
- app_dir->path = strdup(dir);
+ app_dir = efreet_menu_app_dir_new();
+ app_dir->path = strdup(dir);
- prepend = eina_list_append(prepend, app_dir);
+ prepend = eina_list_append(prepend, app_dir);
+ }
- free(dir);
+ eina_stringshare_del(dir);
}
parent->app_dirs = eina_list_merge(prepend, parent->app_dirs);
static int
efreet_menu_handle_default_directory_dirs(Efreet_Menu_Internal *parent, Efreet_Xml *xml __UNUSED__)
{
- Eina_List *dirs, *l;
+ Eina_List *dirs;
char *dir;
if (!parent) return 0;
efreet_menu_create_directory_dirs_list(parent);
dirs = efreet_default_dirs_get(efreet_data_home_get(), efreet_data_dirs_get(),
"desktop-directories");
- EINA_LIST_FOREACH(dirs, l, dir)
- {
- if (eina_list_search_unsorted(parent->directory_dirs, EINA_COMPARE_CB(strcmp), dir))
- continue;
-
- parent->directory_dirs = eina_list_prepend(parent->directory_dirs, strdup(dir));
- }
-
- while (dirs)
+ EINA_LIST_FREE(dirs, dir)
{
- free(eina_list_data_get(dirs));
- dirs = eina_list_remove_list(dirs, dirs);
+ if (!eina_list_search_unsorted(parent->directory_dirs, EINA_COMPARE_CB(strcmp), dir))
+ parent->directory_dirs = eina_list_prepend(parent->directory_dirs, strdup(dir));
+ eina_stringshare_del(dir);
}
return 1;
dirs = efreet_default_dirs_get(efreet_config_home_get(),
efreet_config_dirs_get(), path);
- while ((p = eina_list_data_get(dirs)))
+ EINA_LIST_FREE(dirs, p)
{
- dirs = eina_list_remove_list(dirs, dirs);
efreet_menu_merge_dir(parent, xml, p);
- FREE(p);
+ eina_stringshare_del(p);
}
#ifndef STRICT_SPEC
/* Also check the path of the parent file */
if (!strncmp(path, dir, strlen(dir)))
ret = dir;
else
- free(dir);
+ eina_stringshare_del(dir);
}
return ret;
efreet_util_path_to_file_id(const char *path)
{
size_t len;
- char *tmp, *p;
+ char tmp[PATH_MAX], *p;
char *base;
const char *file_id;
len = strlen(base);
if (strlen(path) <= len)
{
- free(base);
+ eina_stringshare_del(base);
return NULL;
}
if (strncmp(path, base, len))
{
- free(base);
+ eina_stringshare_del(base);
return NULL;
}
- tmp = strdup(path + len + 1);
+ strncpy(tmp, path + len + 1, sizeof(tmp));
+ tmp[PATH_MAX - 1] = '\0';
p = tmp;
while (*p)
{
if (*p == '/') *p = '-';
p++;
}
- free(base);
+ eina_stringshare_del(base);
file_id = eina_stringshare_add(tmp);
- free(tmp);
eina_hash_del(file_id_by_desktop_path, path, NULL);
eina_hash_add(file_id_by_desktop_path, path, (void *)file_id);
return file_id;