From e0040cefb950f9943697df0a39b35c4f236b30d4 Mon Sep 17 00:00:00 2001 From: Gustavo Sverzut Barbieri Date: Mon, 13 Apr 2009 14:56:38 +0000 Subject: [PATCH] major cleanup of path creation to $DATADIR and $HOME/.e/e This cleanup replaces snprintf() usage with specific calls, they have the benefit of being cleaner (so easier to grep), typing less and also marginal speed up compared to the other (specially concat_static), although those are rarely used in critical paths. I'm testing it for some time and seems to not break anything, but let me know of any problem. If you can review the patch and try to spot incorrect names, please do. SVN revision: 40014 --- src/bin/e_about.c | 2 +- src/bin/e_config.c | 117 ++++++-------- src/bin/e_fm.c | 12 +- src/bin/e_fm_custom.c | 14 +- src/bin/e_fm_hal.c | 33 ++-- src/bin/e_fm_mime.c | 55 ++++--- src/bin/e_int_border_menu.c | 19 ++- src/bin/e_int_menus.c | 6 +- src/bin/e_intl.c | 4 +- src/bin/e_main.c | 49 +++--- src/bin/e_prefix.c | 76 ++++++--- src/bin/e_prefix.h | 12 +- src/bin/e_startup.c | 16 +- src/bin/e_thumb_main.c | 5 +- src/bin/e_user.c | 151 ++++++++++++++++-- src/bin/e_user.h | 21 +++ src/bin/e_widget_fsel.c | 31 ++-- .../conf_applications/e_int_config_apps.c | 12 +- .../conf_desklock/e_int_config_desklock.c | 48 +++--- .../conf_profiles/e_int_config_profiles.c | 16 +- .../conf_startup/e_int_config_startup.c | 48 +++--- src/modules/conf_theme/e_int_config_theme.c | 50 +++--- .../conf_theme/e_int_config_theme_import.c | 5 +- .../conf_theme/e_int_config_theme_web.c | 2 +- .../conf_wallpaper/e_int_config_wallpaper.c | 33 ++-- .../e_int_config_wallpaper_gradient.c | 9 +- .../e_int_config_wallpaper_import.c | 22 ++- .../e_int_config_wallpaper_web.c | 2 +- .../conf_wallpaper2/e_int_config_wallpaper.c | 4 +- src/modules/gadman/e_mod_config.c | 27 ++-- src/modules/ibar/e_mod_config.c | 56 ++++--- src/modules/ibar/e_mod_main.c | 10 +- src/modules/illume/e_kbd.c | 5 +- src/modules/illume/e_kbd_buf.c | 42 +++-- src/modules/illume/e_kbd_int.c | 70 ++++---- src/modules/illume/e_mod_win.c | 30 ++-- src/modules/wizard/page_010.c | 6 +- src/modules/wizard/page_020.c | 16 +- src/modules/wizard/page_080.c | 8 +- src/modules/wizard/page_200.c | 22 +-- 40 files changed, 663 insertions(+), 503 deletions(-) diff --git a/src/bin/e_about.c b/src/bin/e_about.c index 1dcd884af..a39e49040 100644 --- a/src/bin/e_about.c +++ b/src/bin/e_about.c @@ -43,7 +43,7 @@ e_about_new(E_Container *con) FILE *f; char buf[4096], buf2[4096], *tbuf; - snprintf(buf, sizeof(buf), "%s/AUTHORS", e_prefix_data_get()); + e_prefix_data_concat_static(buf, "AUTHORS"); f = fopen(buf, "r"); if (f) { diff --git a/src/bin/e_config.c b/src/bin/e_config.c index 0b4bca6be..6f1d8f180 100644 --- a/src/bin/e_config.c +++ b/src/bin/e_config.c @@ -60,18 +60,14 @@ e_config_init(void) { Eet_File *ef; char buf[4096]; - const char *homedir; /* try user profile config */ - homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/config/profile.cfg", - homedir); + e_user_dir_concat_static(buf, "config/profile.cfg"); ef = eet_open(buf, EET_FILE_MODE_READ); if (!ef) { /* use system if no user profile config */ - snprintf(buf, sizeof(buf), "%s/data/config/profile.cfg", - e_prefix_data_get()); + e_prefix_data_concat_static(buf, "data/config/profile.cfg"); ef = eet_open(buf, EET_FILE_MODE_READ); } if (ef) @@ -99,8 +95,7 @@ e_config_init(void) char *link = NULL; /* check symlink - if default is a symlink to another dir */ - snprintf(buf, sizeof(buf), "%s/data/config/default", - e_prefix_data_get()); + e_prefix_data_concat_static(buf, "data/config/default"); link = ecore_file_readlink(buf); /* if so use just the filename as the priofle - must be a local link */ if (link) @@ -1079,14 +1074,10 @@ EAPI char * e_config_profile_dir_get(const char *prof) { char buf[PATH_MAX]; - const char *homedir; - const char *dir; - homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/config/%s", homedir, prof); + e_user_dir_snprintf(buf, sizeof(buf), "config/%s", prof); if (ecore_file_is_dir(buf)) return strdup(buf); - dir = e_prefix_data_get(); - snprintf(buf, sizeof(buf), "%s/data/config/%s", dir, prof); + e_prefix_data_snprintf(buf, sizeof(buf), "data/config/%s", prof); if (ecore_file_is_dir(buf)) return strdup(buf); return NULL; } @@ -1101,19 +1092,20 @@ e_config_profile_list(void) { Eina_List *files; char buf[PATH_MAX], *p; - const char *homedir; - const char *dir; Eina_List *flist = NULL; - int len; + size_t len; - homedir = e_user_homedir_get(); - len = snprintf(buf, sizeof(buf), "%s/.e/e/config/", homedir); - if (len >= (int)sizeof(buf)) + len = e_user_dir_concat_static(buf, "config"); + if (len + 1 >= (int)sizeof(buf)) return NULL; + files = ecore_file_ls(buf); + + buf[len] = '/'; + len++; + p = buf + len; len = sizeof(buf) - len; - files = ecore_file_ls(buf); if (files) { char *file; @@ -1132,14 +1124,17 @@ e_config_profile_list(void) free(file); } } - dir = e_prefix_data_get(); - len = snprintf(buf, sizeof(buf), "%s/data/config/", dir); - if (len >= (int)sizeof(buf)) + len = e_prefix_data_concat_static(buf, "data/config"); + if (len >= sizeof(buf)) return NULL; + files = ecore_file_ls(buf); + + buf[len] = '/'; + len++; + p = buf + len; len = sizeof(buf) - len; - files = ecore_file_ls(buf); if (files) { char *file; @@ -1172,37 +1167,18 @@ EAPI void e_config_profile_add(const char *prof) { char buf[4096]; - const char *homedir; - - homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/config/%s", homedir, prof); + if (e_user_dir_snprintf(buf, sizeof(buf), "config/%s", prof) >= sizeof(buf)) + return; ecore_file_mkdir(buf); } EAPI void e_config_profile_del(const char *prof) { - Eina_List *files; char buf[4096]; - const char *homedir; - - homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/config/%s", homedir, prof); - files = ecore_file_ls(buf); - if (files) - { - char *file; - - EINA_LIST_FREE(files, file) - { - snprintf(buf, sizeof(buf), "%s/.e/e/config/%s/%s", - homedir, prof, file); - ecore_file_unlink(buf); - free(file); - } - } - snprintf(buf, sizeof(buf), "%s/.e/e/config/%s", homedir, prof); - ecore_file_rmdir(buf); + if (e_user_dir_snprintf(buf, sizeof(buf), "config/%s", prof) >= sizeof(buf)) + return; + ecore_file_recursive_rm(buf); } EAPI Eina_List * @@ -1243,12 +1219,10 @@ e_config_domain_load(const char *domain, E_Config_DD *edd) { Eet_File *ef; char buf[4096]; - const char *homedir; void *data = NULL; - homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/config/%s/%s.cfg", - homedir, _e_config_profile, domain); + e_user_dir_snprintf(buf, sizeof(buf), "config/%s/%s.cfg", + _e_config_profile, domain); ef = eet_open(buf, EET_FILE_MODE_READ); if (ef) { @@ -1266,8 +1240,8 @@ e_config_domain_system_load(const char *domain, E_Config_DD *edd) char buf[4096]; void *data = NULL; - snprintf(buf, sizeof(buf), "%s/data/config/%s/%s.cfg", - e_prefix_data_get(), _e_config_profile, domain); + e_prefix_data_snprintf(buf, sizeof(buf), "data/config/%s/%s.cfg", + _e_config_profile, domain); ef = eet_open(buf, EET_FILE_MODE_READ); if (ef) { @@ -1284,13 +1258,11 @@ e_config_profile_save(void) { Eet_File *ef; char buf[4096], buf2[4096]; - const char *homedir; int ok = 0; /* FIXME: check for other sessions fo E running */ - homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/config/profile.cfg", homedir); - snprintf(buf2, sizeof(buf2), "%s.tmp", buf); + e_user_dir_concat_static(buf, "config/profile.cfg"); + e_user_dir_concat_static(buf2, "config/profile.cfg.tmp"); ef = eet_open(buf2, EET_FILE_MODE_WRITE); if (ef) @@ -1317,18 +1289,31 @@ e_config_domain_save(const char *domain, E_Config_DD *edd, const void *data) { Eet_File *ef; char buf[4096], buf2[4096]; - const char *homedir; int ok = 0, ret; + size_t len, len2; if (_e_config_save_block) return 0; /* FIXME: check for other sessions fo E running */ - homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/config/%s", - homedir, _e_config_profile); + len = e_user_dir_snprintf(buf, sizeof(buf), "config/%s", _e_config_profile); + if (len + 1 >= sizeof(buf)) return 0; + ecore_file_mkdir(buf); - snprintf(buf, sizeof(buf), "%s/.e/e/config/%s/%s.cfg", - homedir, _e_config_profile, domain); - snprintf(buf2, sizeof(buf2), "%s.tmp", buf); + + buf[len] = '/'; + len++; + + len2 = ecore_strlcpy(buf + len, domain, sizeof(buf) - len); + if (len2 + sizeof(".cfg") >= sizeof(buf) - len) return 0; + + len += len2; + + memcpy(buf + len, ".cfg", sizeof(".cfg")); + len += sizeof(".cfg") - 1; + + if (len + sizeof(".tmp") >= sizeof(buf)) return 0; + memcpy(buf2, buf, len); + memcpy(buf2 + len, ".tmp", sizeof(".tmp")); + ef = eet_open(buf2, EET_FILE_MODE_WRITE); if (ef) { diff --git a/src/bin/e_fm.c b/src/bin/e_fm.c index c8651f720..50720d450 100644 --- a/src/bin/e_fm.c +++ b/src/bin/e_fm.c @@ -651,14 +651,12 @@ static Ecore_Event_Handler *_e_fm2_op_registry_entry_changed_handler = NULL; EAPI int e_fm2_init(void) { - const char *homedir; char path[PATH_MAX]; eina_stringshare_init(); ecore_job_init(); _e_storage_volume_edd_init(); - homedir = e_user_homedir_get(); - snprintf(path, sizeof(path), "%s/.e/e/fileman/metadata", homedir); + e_user_dir_concat_static(path, "fileman/metadata"); ecore_file_mkpath(path); _e_fm2_meta_path = strdup(path); @@ -3037,8 +3035,7 @@ _e_fm2_dev_path_map(const char *dev, const char *path) .desktop files or symlinks (in fact anything * you like */ - s = (char *)e_user_homedir_get(); - if (PRT("%s/.e/e/fileman/favorites", s) >= sizeof(buf)) + if (e_user_dir_concat_static(buf, "fileman/favorites") >= sizeof(buf)) return NULL; } else if (strcmp(dev, "desktop") == 0) @@ -3048,15 +3045,14 @@ _e_fm2_dev_path_map(const char *dev, const char *path) .desktop files or symlinks (in fact anything * you like */ - s = (char *)e_user_homedir_get(); if (strcmp(path, "/") == 0) { - if (PRT("%s/Desktop", s) >= sizeof(buf)) + if (e_user_homedir_concat_static(buf, "Desktop") >= sizeof(buf)) return NULL; } else { - if (PRT("%s/Desktop-%s", s, path) >= sizeof(buf)) + if (e_user_homedir_snprintf(buf, sizeof(buf), "Desktop-%s", path) >= sizeof(buf)) return NULL; } ecore_file_mkpath(buf); diff --git a/src/bin/e_fm_custom.c b/src/bin/e_fm_custom.c index 20dc8d12d..649cd7ef3 100644 --- a/src/bin/e_fm_custom.c +++ b/src/bin/e_fm_custom.c @@ -359,8 +359,7 @@ _e_fm2_custom_file_info_load(void) if (_e_fm2_custom_file) return; _e_fm2_custom_writes = 0; - snprintf(buf, sizeof(buf), "%s/.e/e/fileman/custom.cfg", - e_user_homedir_get()); + e_user_dir_concat_static(buf, "fileman/custom.cfg"); _e_fm2_custom_file = eet_open(buf, EET_FILE_MODE_READ); if (!_e_fm2_custom_file) _e_fm2_custom_file = eet_open(buf, EET_FILE_MODE_WRITE); @@ -390,19 +389,22 @@ _e_fm2_custom_file_info_save(void) { Eet_File *ef; char buf[PATH_MAX], buf2[PATH_MAX]; + size_t len; int ret; if (!_e_fm2_custom_file) return; if (!_e_fm2_custom_writes) return; - snprintf(buf, sizeof(buf), "%s/.e/e/fileman/custom.cfg.tmp", - e_user_homedir_get()); + + len = e_user_dir_concat_static(buf, "fileman/custom.cfg.tmp"); + if (len >= sizeof(buf)) return; ef = eet_open(buf, EET_FILE_MODE_WRITE); if (!ef) return; eina_hash_foreach(_e_fm2_custom_hash, _e_fm2_custom_file_hash_foreach_save, ef); eet_close(ef); - snprintf(buf2, sizeof(buf2), "%s/.e/e/fileman/custom.cfg", - e_user_homedir_get()); + + memcpy(buf2, buf, len - sizeof(".tmp") - 1); + buf2[len - sizeof(".tmp") - 1] = '\0'; eet_close(_e_fm2_custom_file); _e_fm2_custom_file = NULL; ret = rename(buf, buf2); diff --git a/src/bin/e_fm_hal.c b/src/bin/e_fm_hal.c index b313ac7aa..f9d7d6a82 100644 --- a/src/bin/e_fm_hal.c +++ b/src/bin/e_fm_hal.c @@ -286,8 +286,8 @@ _e_fm2_volume_write(E_Volume *v) if (!v->storage) return; id = ecore_file_file_get(v->storage->udi); // printf("vol write %s\n", id); - snprintf(buf, sizeof(buf) - 1, "%s/.e/e/fileman/favorites/|%s_%d.desktop", - e_user_homedir_get(), id, v->partition_number); + e_user_dir_snprintf(buf, sizeof(buf), "fileman/favorites/|%s_%d.desktop", + id, v->partition_number); f = fopen(buf, "w"); if (f) @@ -313,8 +313,9 @@ _e_fm2_volume_write(E_Volume *v) if (e_config->hal_desktop) { - snprintf(buf2, sizeof(buf2) - 1, "%s/Desktop/|%s_%d.desktop", - e_user_homedir_get(), id, v->partition_number); + e_user_homedir_snprintf(buf2, sizeof(buf2), + "Desktop/|%s_%d.desktop", + id, v->partition_number); ecore_file_symlink(buf, buf2); } @@ -337,15 +338,16 @@ _e_fm2_volume_erase(E_Volume *v) if (!v->storage) return; id = ecore_file_file_get(v->storage->udi); - snprintf(buf, sizeof(buf) - 1, "%s/Desktop/|%s_%d.desktop", - e_user_homedir_get(), id, v->partition_number); + e_user_homedir_snprintf(buf, sizeof(buf), "Desktop/|%s_%d.desktop", + id, v->partition_number); ecore_file_unlink(buf); _e_fm2_file_force_update(buf); if (e_config->hal_desktop) { - snprintf(buf, sizeof(buf) - 1, "%s/.e/e/fileman/favorites/|%s_%d.desktop", - e_user_homedir_get(), id, v->partition_number); + e_user_dir_snprintf(buf, sizeof(buf), + "fileman/favorites/|%s_%d.desktop", + id, v->partition_number); ecore_file_unlink(buf); _e_fm2_file_force_update(buf); } @@ -530,11 +532,13 @@ e_fm2_hal_show_desktop_icons(void) id = ecore_file_file_get(v->storage->udi); - snprintf(buf, sizeof(buf) - 1, "%s/.e/e/fileman/favorites/|%s_%d.desktop", - e_user_homedir_get(), id, v->partition_number); + e_user_dir_snprintf(buf, sizeof(buf), + "fileman/favorites/|%s_%d.desktop", + id, v->partition_number); - snprintf(buf2, sizeof(buf2) - 1, "%s/Desktop/|%s_%d.desktop", - e_user_homedir_get(), id, v->partition_number); + e_user_homedir_snprintf(buf2, sizeof(buf2), + "Desktop/|%s_%d.desktop", + id, v->partition_number); if (ecore_file_exists(buf) && !ecore_file_exists(buf2)) { @@ -561,8 +565,9 @@ e_fm2_hal_hide_desktop_icons(void) id = ecore_file_file_get(v->storage->udi); - snprintf(buf, sizeof(buf) - 1, "%s/Desktop/|%s_%d.desktop", - e_user_homedir_get(), id, v->partition_number); + e_user_homedir_snprintf(buf, sizeof(buf), + "Desktop/|%s_%d.desktop", + id, v->partition_number); if (ecore_file_exists(buf)) { diff --git a/src/bin/e_fm_mime.c b/src/bin/e_fm_mime.c index 3cab54708..7ae715486 100644 --- a/src/bin/e_fm_mime.c +++ b/src/bin/e_fm_mime.c @@ -37,9 +37,9 @@ EAPI const char * e_fm_mime_icon_get(const char *mime) { char buf[4096], buf2[4096], *val; - const char *homedir = NULL; Eina_List *l = NULL; E_Config_Mime_Icon *mi; + size_t len; /* 0.0 clean out hash cache once it has mroe than 512 entries in it */ if (eina_hash_population(icon_map) > 512) e_fm_mime_icon_cache_flush(); @@ -64,41 +64,60 @@ e_fm_mime_icon_get(const char *mime) } /* 2. look up in ~/.e/e/icons */ - homedir = e_user_homedir_get(); + len = e_user_dir_snprintf(buf, sizeof(buf), "icons/%s.edj", mime); + if (len >= sizeof(buf)) + goto try_e_icon_generic; - snprintf(buf, sizeof(buf), "%s/.e/e/icons/%s.edj", homedir, mime); if (ecore_file_exists(buf)) goto ok; - snprintf(buf, sizeof(buf), "%s/.e/e/icons/%s.svg", homedir, mime); + memcpy(buf + len - sizeof("edj") - 1, "svg", sizeof("svg")); if (ecore_file_exists(buf)) goto ok; - snprintf(buf, sizeof(buf), "%s/.e/e/icons/%s.png", homedir, mime); + memcpy(buf + len - sizeof("edj") - 1, "png", sizeof("png")); if (ecore_file_exists(buf)) goto ok; - snprintf(buf, sizeof(buf), "%s/.e/e/icons/%s.edj", homedir, buf2); + + try_e_icon_generic: + len = e_user_dir_snprintf(buf, sizeof(buf), "icons/%s.edj", buf2); + if (len >= sizeof(buf)) + goto try_theme; + if (ecore_file_exists(buf)) goto ok; - snprintf(buf, sizeof(buf), "%s/.e/e/icons/%s.svg", homedir, buf2); + memcpy(buf + len - sizeof("edj") - 1, "svg", sizeof("svg")); if (ecore_file_exists(buf)) goto ok; - snprintf(buf, sizeof(buf), "%s/.e/e/icons/%s.png", homedir, buf2); + memcpy(buf + len - sizeof("edj") - 1, "png", sizeof("png")); if (ecore_file_exists(buf)) goto ok; - + /* 3. look up icon in theme */ - snprintf(buf, sizeof(buf), "e/icons/fileman/mime/%s", mime); + try_theme: + memcpy(buf, "e/icons/fileman/mime/", sizeof("e/icons/fileman/mime/") - 1); + ecore_strlcpy(buf + sizeof("e/icons/fileman/mime/") - 1, mime, + sizeof(buf) - sizeof("e/icons/fileman/mime/") - 1); val = (char *)e_theme_edje_file_get("base/theme/fileman", buf); if ((val) && (e_util_edje_collection_exists(val, buf))) goto ok; - snprintf(buf, sizeof(buf), "e/icons/fileman/mime/%s", buf2); + + ecore_strlcpy(buf + sizeof("e/icons/fileman/mime/") - 1, buf2, + sizeof(buf) - sizeof("e/icons/fileman/mime/") - 1); val = (char *)e_theme_edje_file_get("base/theme/fileman", buf); if ((val) && (e_util_edje_collection_exists(val, buf))) goto ok; - + /* 4. look up icon in PREFIX/share/enlightent/data/icons */ - snprintf(buf, sizeof(buf), "%s/data/icons/%s.edj", e_prefix_data_get(), mime); + len = e_prefix_data_snprintf(buf, sizeof(buf), "data/icons/%s.edj", mime); + if (len >= sizeof(buf)) + goto try_efreet_icon_generic; + if (ecore_file_exists(buf)) goto ok; - snprintf(buf, sizeof(buf), "%s/data/icons/%s.svg", e_prefix_data_get(), mime); + memcpy(buf + len - sizeof("edj") - 1, "svg", sizeof("svg")); if (ecore_file_exists(buf)) goto ok; - snprintf(buf, sizeof(buf), "%s/data/icons/%s.png", e_prefix_data_get(), mime); + memcpy(buf + len - sizeof("edj") - 1, "png", sizeof("png")); if (ecore_file_exists(buf)) goto ok; - snprintf(buf, sizeof(buf), "%s/data/icons/%s.edj", e_prefix_data_get(), buf2); + + try_efreet_icon_generic: + len = e_prefix_data_snprintf(buf, sizeof(buf), "data/icons/%s.edj", buf2); + if (len >= sizeof(buf)) + goto try_efreet_icon_generic; + if (ecore_file_exists(buf)) goto ok; - snprintf(buf, sizeof(buf), "%s/data/icons/%s.svg", e_prefix_data_get(), buf2); + memcpy(buf + len - sizeof("edj") - 1, "svg", sizeof("svg")); if (ecore_file_exists(buf)) goto ok; - snprintf(buf, sizeof(buf), "%s/data/icons/%s.png", e_prefix_data_get(), buf2); + memcpy(buf + len - sizeof("edj") - 1, "png", sizeof("png")); if (ecore_file_exists(buf)) goto ok; return NULL; diff --git a/src/bin/e_int_border_menu.c b/src/bin/e_int_border_menu.c index b09ef3e3e..10f49e3dd 100644 --- a/src/bin/e_int_border_menu.c +++ b/src/bin/e_int_border_menu.c @@ -1065,8 +1065,7 @@ _e_border_menu_cb_fav_add(void *data, E_Menu *m, E_Menu_Item *mi) char buf[4096]; if (!(bd = data)) return; - snprintf(buf, sizeof(buf), "%s/.e/e/applications/menu/favorite.menu", - e_user_homedir_get()); + e_user_dir_concat_static(buf, "applications/menu/favorite.menu"); menu = efreet_menu_parse(buf); if (!menu) return; efreet_menu_desktop_insert(menu, bd->desktop, -1); @@ -1095,21 +1094,25 @@ _e_border_menu_cb_ibar_add_pre(void *data, E_Menu *m, E_Menu_Item *mi) Eina_List *dirs; Eina_List *l; char buf[4096], *file; - const char *homedir; + size_t len; if (!(bd = data)) return; - homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/applications/bar", homedir); + len = e_user_dir_concat_static(buf, "applications/bar"); + if (len + 1 >= sizeof(buf)) return; dirs = ecore_file_ls(buf); if (!dirs) return; + buf[len] = '/'; + len++; + sm = e_menu_new(); EINA_LIST_FOREACH(dirs, l, file) { E_Menu_Item *smi; if (file[0] == '.') continue; - snprintf(buf, sizeof(buf), "%s/.e/e/applications/bar/%s", homedir, file); + + ecore_strlcpy(buf + len, file, sizeof(buf) - len); if (ecore_file_is_dir(buf)) { smi = e_menu_item_new(sm); @@ -1131,8 +1134,8 @@ _e_border_menu_cb_ibar_add(void *data, E_Menu *m, E_Menu_Item *mi) bd = e_object_data_get(E_OBJECT(m)); if ((!bd) || (!bd->desktop)) return; - snprintf(buf, sizeof(buf), "%s/.e/e/applications/bar/%s/.order", - e_user_homedir_get(), (char *)data); + e_user_dir_snprintf(buf, sizeof(buf), "applications/bar/%s/.order", + (const char *)data); od = e_order_new(buf); if (!od) return; e_order_append(od, bd->desktop); diff --git a/src/bin/e_int_menus.c b/src/bin/e_int_menus.c index a4fc24faa..571ed7cfa 100644 --- a/src/bin/e_int_menus.c +++ b/src/bin/e_int_menus.c @@ -281,12 +281,8 @@ e_int_menus_favorite_apps_new(void) { E_Menu *m = NULL; char buf[PATH_MAX]; - const char *homedir; - - homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), - "%s/.e/e/applications/menu/favorite.menu", homedir); + e_user_dir_concat_static(buf, "applications/menu/favorite.menu"); if (ecore_file_exists(buf)) m = e_int_menus_apps_new(buf); return m; } diff --git a/src/bin/e_intl.c b/src/bin/e_intl.c index 65c8fe10a..9713342e0 100644 --- a/src/bin/e_intl.c +++ b/src/bin/e_intl.c @@ -397,7 +397,7 @@ e_intl_imc_personal_path_get(void) { char buf[4096]; - snprintf(buf, sizeof(buf), "%s/.e/e/input_methods", e_user_homedir_get()); + e_user_dir_concat_static(buf, "input_methods"); _e_intl_imc_personal_path = eina_stringshare_add(buf); } return _e_intl_imc_personal_path; @@ -410,7 +410,7 @@ e_intl_imc_system_path_get(void) { char buf[4096]; - snprintf(buf, sizeof(buf), "%s/data/input_methods", e_prefix_data_get()); + e_prefix_data_concat_static(buf, "data/input_methods"); _e_intl_imc_system_path = eina_stringshare_add(buf); } return _e_intl_imc_system_path; diff --git a/src/bin/e_main.c b/src/bin/e_main.c index b218899fc..ad3c9de92 100644 --- a/src/bin/e_main.c +++ b/src/bin/e_main.c @@ -217,9 +217,8 @@ main(int argc, char **argv) { /* do some extra tests to see if the prefix really is right */ char buf[4096]; - - snprintf(buf, sizeof(buf), "%s/data/themes/default.edj", - e_prefix_data_get()); + + e_prefix_data_concat_static(buf, "data/themes/default.edj"); if (!ecore_file_exists(buf)) { printf("WARNING: Prefix guess was wrong. Guessed:\n" @@ -378,10 +377,7 @@ main(int argc, char **argv) TS("arg parse done"); /* fixes for FOOLS that keep cp'ing default.edj into ~/.e/e/themes */ { - const char *homedir; - - homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/themes/default.edj", homedir); + e_user_dir_concat_static(buf, "themes/default.edj"); if (ecore_file_exists(buf)) ecore_file_unlink(buf); } @@ -693,7 +689,7 @@ main(int argc, char **argv) e_canvas_add(ee); im = evas_object_image_add(ecore_evas_get(ee)); - snprintf(buf, sizeof(buf), "%s/data/images/test.png", e_prefix_data_get()); + e_prefix_data_concat_static(buf, "data/images/test.png"); evas_object_image_file_set(im, buf, NULL); if (evas_object_image_load_error_get(im) != EVAS_LOAD_ERROR_NONE) { @@ -702,7 +698,7 @@ main(int argc, char **argv) _e_main_shutdown(-1); } - snprintf(buf, sizeof(buf), "%s/data/images/test.jpg", e_prefix_data_get()); + e_prefix_data_concat_static(buf, "data/images/test.jpg"); evas_object_image_file_set(im, buf, NULL); if (evas_object_image_load_error_get(im) != EVAS_LOAD_ERROR_NONE) { @@ -711,7 +707,7 @@ main(int argc, char **argv) _e_main_shutdown(-1); } - snprintf(buf, sizeof(buf), "%s/data/images/test.edj", e_prefix_data_get()); + e_prefix_data_concat_static(buf, "data/images/test.edj"); evas_object_image_file_set(im, buf, "images/0"); if (evas_object_image_load_error_get(im) != EVAS_LOAD_ERROR_NONE) { @@ -782,9 +778,9 @@ main(int argc, char **argv) list = efreet_icon_extra_list_get(); if (list) { - snprintf(buf, sizeof(buf), "%s/.e/e/icons", e_user_homedir_get()); + e_user_dir_concat_static(buf, "icons"); *list = eina_list_prepend(*list, (void *)eina_stringshare_add(buf)); - snprintf(buf, sizeof(buf), "%s/data/icons", e_prefix_data_get()); + e_prefix_data_concat_static(buf, "data/icons"); *list = eina_list_prepend(*list, (void *)eina_stringshare_add(buf)); } } @@ -1169,8 +1165,7 @@ _e_main_x_shutdown(void) static int _e_main_dirs_init(void) { - const char *homedir; - char buf[PATH_MAX]; + const char *base; const char *dirs[] = { "images", "fonts", @@ -1192,20 +1187,12 @@ _e_main_dirs_init(void) "input_methods", NULL }; - int baselen; - homedir = e_user_homedir_get(); - baselen = snprintf(buf, sizeof(buf), "%s/.e/e", homedir); - if (baselen >= (int)sizeof(buf)) - { - e_error_message_show("Error could not join:\n'%s'\nand\n'/.e/e", - homedir); - return 0; - } - if (ecore_file_mksubdirs(buf, dirs) != sizeof(dirs)/sizeof(dirs[0]) - 1) + base = e_user_dir_get(); + if (ecore_file_mksubdirs(base, dirs) != sizeof(dirs)/sizeof(dirs[0]) - 1) { e_error_message_show - ("Could not create one of the required subdirectories of '%s'", buf); + ("Could not create one of the required subdirectories of '%s'", base); return 0; } @@ -1334,7 +1321,7 @@ _e_main_path_init(void) e_error_message_show("Cannot allocate path for path_data\n"); return 0; } - snprintf(buf, sizeof(buf), "%s/data", e_prefix_data_get()); + e_prefix_data_concat_static(buf, "data"); e_path_default_path_append(path_data, buf); e_path_user_path_set(path_data, &(e_config->path_append_data)); @@ -1346,7 +1333,7 @@ _e_main_path_init(void) return 0; } e_path_default_path_append(path_images, "~/.e/e/images"); - snprintf(buf, sizeof(buf), "%s/data/images", e_prefix_data_get()); + e_prefix_data_concat_static(buf, "data/images"); e_path_default_path_append(path_images, buf); e_path_user_path_set(path_images, &(e_config->path_append_images)); @@ -1358,7 +1345,7 @@ _e_main_path_init(void) return 0; } e_path_default_path_append(path_fonts, "~/.e/e/fonts"); - snprintf(buf, sizeof(buf), "%s/data/fonts", e_prefix_data_get()); + e_prefix_data_concat_static(buf, "data/fonts"); e_path_default_path_append(path_fonts, buf); e_path_user_path_set(path_fonts, &(e_config->path_append_fonts)); @@ -1370,7 +1357,7 @@ _e_main_path_init(void) return 0; } e_path_default_path_append(path_themes, "~/.e/e/themes"); - snprintf(buf, sizeof(buf), "%s/data/themes", e_prefix_data_get()); + e_prefix_data_concat_static(buf, "data/themes"); e_path_default_path_append(path_themes, buf); e_path_user_path_set(path_themes, &(e_config->path_append_themes)); @@ -1382,7 +1369,7 @@ _e_main_path_init(void) return 0; } e_path_default_path_append(path_icons, "~/.e/e/icons"); - snprintf(buf, sizeof(buf), "%s/data/icons", e_prefix_data_get()); + e_prefix_data_concat_static(buf, "data/icons"); e_path_default_path_append(path_icons, buf); e_path_user_path_set(path_icons, &(e_config->path_append_icons)); @@ -1412,7 +1399,7 @@ _e_main_path_init(void) return 0; } e_path_default_path_append(path_backgrounds, "~/.e/e/backgrounds"); - snprintf(buf, sizeof(buf), "%s/data/backgrounds", e_prefix_data_get()); + e_prefix_data_concat_static(buf, "data/backgrounds"); e_path_default_path_append(path_backgrounds, buf); e_path_user_path_set(path_backgrounds, &(e_config->path_append_backgrounds)); diff --git a/src/bin/e_prefix.c b/src/bin/e_prefix.c index cb441f59d..1daa3e0eb 100644 --- a/src/bin/e_prefix.c +++ b/src/bin/e_prefix.c @@ -17,6 +17,8 @@ static char *_prefix_path_bin = NULL; static char *_prefix_path_data = NULL; static char *_prefix_path_lib = NULL; +static size_t _prefix_path_data_len = 0; + #define PREFIX_CACHE_FILE 1 #define SHARE_D "share/enlightenment" #define MAGIC_FILE "AUTHORS" @@ -56,10 +58,13 @@ e_prefix_determine(char *argv0) } if (getenv("E_DATA_DIR")) - _prefix_path_data = strdup(getenv("E_DATA_DIR")); + { + _prefix_path_data = strdup(getenv("E_DATA_DIR")); + _prefix_path_data_len = strlen(_prefix_path_data); + } else { - snprintf(buf, sizeof(buf), "%s/"SHARE_D, _prefix_path); + _prefix_path_data_len = snprintf(buf, sizeof(buf), "%s/"SHARE_D, _prefix_path); _prefix_path_data = strdup(buf); e_util_env_set("E_DATA_DIR", _prefix_path_data); } @@ -122,7 +127,7 @@ e_prefix_determine(char *argv0) snprintf(buf, sizeof(buf), "%s/"MAGIC_DAT, _prefix_path); if (ecore_file_exists(buf)) { - snprintf(buf, sizeof(buf), "%s/"SHARE_D, _prefix_path); + _prefix_path_data_len = snprintf(buf, sizeof(buf), "%s/"SHARE_D, _prefix_path); _prefix_path_data = strdup(buf); snprintf(buf, sizeof(buf), "%s/"LOCALE_D, _prefix_path); _prefix_path_locale = strdup(buf); @@ -226,9 +231,6 @@ _e_prefix_share_hunt(void) { char buf[4096], buf2[4096], *p; FILE *f; -#ifdef PREFIX_CACHE_FILE - const char *home; -#endif /* sometimes this isnt the case - so we need to do a more exhaustive search * through more parent and subdirs. hre is an example i have seen: @@ -245,9 +247,7 @@ _e_prefix_share_hunt(void) #ifdef PREFIX_CACHE_FILE /* 1. check cache file - as a first attempt. this will speed up subsequent * hunts - if needed */ - home = e_user_homedir_get(); - - snprintf(buf, sizeof(buf), "%s/.e/e/prefix_share_cache.txt", home); + e_user_dir_concat_static(buf, "prefix_share_cache.txt"); f = fopen(buf, "r"); if (f) { @@ -262,7 +262,7 @@ _e_prefix_share_hunt(void) { /* path is ok - magic file found */ _prefix_path_data = strdup(buf2); - snprintf(buf, sizeof(buf), "%s", buf2); + _prefix_path_data_len = ecore_strlcpy(buf, buf2, sizeof(buf)); p = strrchr(buf, '/'); if (p) *p = 0; snprintf(buf2, sizeof(buf2), "%s/locale", buf); @@ -285,8 +285,8 @@ _e_prefix_share_hunt(void) { Eina_List *files; Eina_List *l; - - snprintf(buf, sizeof(buf), "%s", _prefix_path); + + ecore_strlcpy(buf, _prefix_path, sizeof(buf)); p = strrchr(buf, '/'); if (p) *p = 0; files = ecore_file_ls(buf); @@ -299,17 +299,16 @@ _e_prefix_share_hunt(void) snprintf(buf2, sizeof(buf2), "%s/%s/"MAGIC_DAT, buf, file); if (ecore_file_exists(buf2)) { - snprintf(buf2, sizeof(buf2), "%s/%s/"SHARE_D, buf, file); + _prefix_path_data_len = snprintf(buf2, sizeof(buf2), "%s/%s/"SHARE_D, buf, file); _prefix_path_data = strdup(buf2); snprintf(buf2, sizeof(buf2), "%s/%s/"LOCALE_D, buf, file); _prefix_path_locale = strdup(buf2); break; } } - while (files) + EINA_LIST_FREE(files, p) { - free(eina_list_data_get(files)); - files = eina_list_remove_list(files, files); + free(p); } } } @@ -320,13 +319,13 @@ _e_prefix_share_hunt(void) */ if (!_prefix_path_data) { - snprintf(buf, sizeof(buf), "%s", _prefix_path); + ecore_strlcpy(buf, _prefix_path, sizeof(buf)); p = strrchr(buf, '/'); if (p) *p = 0; snprintf(buf2, sizeof(buf2), "%s/"MAGIC_DAT, buf); if (ecore_file_exists(buf2)) { - snprintf(buf2, sizeof(buf2), "%s/"SHARE_D, buf); + _prefix_path_data_len = snprintf(buf2, sizeof(buf2), "%s/"SHARE_D, buf); _prefix_path_data = strdup(buf2); snprintf(buf2, sizeof(buf2), "%s/"LOCALE_D, buf); _prefix_path_locale = strdup(buf2); @@ -343,9 +342,8 @@ _e_prefix_share_hunt(void) if (_prefix_path_data) { #ifdef PREFIX_CACHE_FILE - snprintf(buf, sizeof(buf), "%s/.e/e", home); - ecore_file_mkpath(buf); - snprintf(buf, sizeof(buf), "%s/.e/e/prefix_share_cache.txt", home); + ecore_file_mkpath(e_user_dir_get()); + e_user_dir_concat_static(buf, "prefix_share_cache.txt"); f = fopen(buf, "w"); if (f) { @@ -370,6 +368,7 @@ _e_prefix_fallbacks(void) _prefix_path_locale = strdup(LOCALE_DIR); _prefix_path_bin = strdup(PACKAGE_BIN_DIR); _prefix_path_data = strdup(PACKAGE_DATA_DIR); + _prefix_path_data_len = strlen(_prefix_path_data); _prefix_path_lib = strdup(PACKAGE_LIB_DIR); printf("WARNING: Enlightenment could not determine its installed prefix\n" " and is falling back on the compiled in default:\n" @@ -519,3 +518,38 @@ _e_prefix_try_argv(char *argv0) /* 4. big problems. arg[0] != executable - weird execution */ return 0; } + +size_t +e_prefix_data_concat_len(char *dst, size_t size, const char *path, size_t path_len) +{ + return ecore_str_join_len(dst, size, '/', _prefix_path_data, _prefix_path_data_len, path, path_len); +} + +size_t +e_prefix_data_snprintf(char *dst, size_t size, const char *fmt, ...) +{ + size_t off, ret; + va_list ap; + + va_start(ap, fmt); + + off = _prefix_path_data_len + 1; + if (size < _prefix_path_data_len + 2) + { + if (size > 1) + { + memcpy(dst, _prefix_path_data, size - 1); + dst[size - 1] = '\0'; + } + ret = off + vsnprintf(dst + off, size - off, fmt, ap); + va_end(ap); + return ret; + } + + memcpy(dst, _prefix_path_data, _prefix_path_data_len); + dst[_prefix_path_data_len] = '/'; + + ret = off + vsnprintf(dst + off, size - off, fmt, ap); + va_end(ap); + return ret; +} diff --git a/src/bin/e_prefix.h b/src/bin/e_prefix.h index cccdef4c2..f563d0318 100644 --- a/src/bin/e_prefix.h +++ b/src/bin/e_prefix.h @@ -15,6 +15,16 @@ EAPI const char *e_prefix_locale_get(void); EAPI const char *e_prefix_bin_get(void); EAPI const char *e_prefix_data_get(void); EAPI const char *e_prefix_lib_get(void); - + +EAPI size_t e_prefix_data_concat_len(char *dst, size_t size, const char *path, size_t path_len); +EAPI size_t e_prefix_data_snprintf(char *dst, size_t size, const char *fmt, ...) EINA_PRINTF(3, 4); + +static inline size_t e_prefix_data_concat(char *dst, size_t size, const char *path) +{ + return e_prefix_data_concat_len(dst, size, path, strlen(path)); +} +#define e_prefix_data_concat_static(dst, path) e_prefix_data_concat_len(dst, sizeof(dst), path, (sizeof(path) > 0) ? sizeof(path) - 1 : 0) + + #endif #endif diff --git a/src/bin/e_startup.c b/src/bin/e_startup.c index 9a8e218a6..59ed53cf9 100644 --- a/src/bin/e_startup.c +++ b/src/bin/e_startup.c @@ -20,22 +20,18 @@ static int start_app_pos = -1; EAPI void e_startup(E_Startup_Mode mode) { - const char *homedir, *prefixdir; char buf[PATH_MAX]; - - homedir = e_user_homedir_get(); - prefixdir = e_prefix_data_get(); if (mode == E_STARTUP_START) { - snprintf(buf, sizeof(buf), "%s/.e/e/applications/startup/.order", homedir); - if (!ecore_file_exists(buf)) - snprintf(buf, sizeof(buf), "%s/data/applications/startup/.order", prefixdir); + e_user_dir_concat_static(buf, "applications/startup/.order"); + if (!ecore_file_exists(buf)) + e_prefix_data_concat_static(buf, "data/applications/startup/.order"); } else if (mode == E_STARTUP_RESTART) { - snprintf(buf, sizeof(buf), "%s/.e/e/applications/restart/.order", homedir); - if (!ecore_file_exists(buf)) - snprintf(buf, sizeof(buf), "%s/data/applications/restart/.order", prefixdir); + e_user_dir_concat_static(buf, "applications/restart/.order"); + if (!ecore_file_exists(buf)) + e_prefix_data_concat_static(buf, "data/applications/restart/.order"); } startup_apps = e_order_new(buf); if (!startup_apps) return; diff --git a/src/bin/e_thumb_main.c b/src/bin/e_thumb_main.c index 915e247e2..0899af935 100644 --- a/src/bin/e_thumb_main.c +++ b/src/bin/e_thumb_main.c @@ -77,10 +77,9 @@ main(int argc, char **argv) ecore_file_init(); ecore_ipc_init(); - snprintf(_thumbdir, sizeof(_thumbdir), "%s/.e/e/fileman/thumbnails", - e_user_homedir_get()); + e_user_dir_concat_static(_thumbdir, "fileman/thumbnails"); ecore_file_mkpath(_thumbdir); - + if (_e_ipc_init()) ecore_main_loop_begin(); if (_e_ipc_server) diff --git a/src/bin/e_user.c b/src/bin/e_user.c index e778be0c5..5a54ebe32 100644 --- a/src/bin/e_user.c +++ b/src/bin/e_user.c @@ -3,22 +3,85 @@ */ #include "e.h" + +static const char *_e_user_homedir = NULL; +static size_t _e_user_homedir_len = 0; + /* externally accessible functions */ EAPI const char * e_user_homedir_get(void) { - char *homedir; - int len; + char *d; - homedir = getenv("HOME"); - if (!homedir) return "/tmp"; - len = strlen(homedir); - while ((len > 1) && (homedir[len - 1] == '/')) + if (_e_user_homedir) + return _e_user_homedir; + + _e_user_homedir = d = getenv("HOME"); + if (!_e_user_homedir) { - homedir[len - 1] = 0; - len--; + _e_user_homedir = "/tmp"; + _e_user_homedir_len = sizeof("/tmp") - 1; + return _e_user_homedir; } - return homedir; + + _e_user_homedir_len = strlen(_e_user_homedir); + while ((_e_user_homedir_len > 1) && + (d[_e_user_homedir_len - 1] == '/')) + { + _e_user_homedir_len--; + d[_e_user_homedir_len] = '\0'; + } + return _e_user_homedir; +} + +/** + * Concatenate '~/' and @a path. + * + * @return similar to snprintf(), this returns the number of bytes written or + * that would be required to write if greater or equal than size. + */ +EAPI size_t +e_user_homedir_concat_len(char *dst, size_t size, const char *path, size_t path_len) +{ + if (!_e_user_homedir) + e_user_homedir_get(); + + return ecore_str_join_len(dst, size, '/', _e_user_homedir, _e_user_homedir_len, path, path_len); +} + +/** + * same as snprintf("~/"fmt, ...). + */ +EAPI size_t +e_user_homedir_snprintf(char *dst, size_t size, const char *fmt, ...) +{ + size_t off, ret; + va_list ap; + + if (!_e_user_homedir) + e_user_homedir_get(); + + va_start(ap, fmt); + + off = _e_user_homedir_len + 1; + if (size < _e_user_homedir_len + 2) + { + if (size > 1) + { + memcpy(dst, _e_user_homedir, size - 1); + dst[size - 1] = '\0'; + } + ret = off + vsnprintf(dst + off, size - off, fmt, ap); + va_end(ap); + return ret; + } + + memcpy(dst, _e_user_homedir, _e_user_homedir_len); + dst[_e_user_homedir_len] = '/'; + + ret = off + vsnprintf(dst + off, size - off, fmt, ap); + va_end(ap); + return ret; } /** @@ -52,3 +115,73 @@ e_user_icon_dir_get(void) return dir; } + +static const char *_e_user_dir = NULL; +static size_t _e_user_dir_len = 0; + +/** + * Return ~/.e/e + */ +EAPI const char * +e_user_dir_get(void) +{ + static char dir[PATH_MAX] = ""; + + if (!dir[0]) + { + _e_user_dir_len = e_user_homedir_concat(dir, sizeof(dir), ".e/e"); + _e_user_dir = dir; + } + + return dir; +} + +/** + * Concatenate '~/.e/e' and @a path. + * + * @return similar to snprintf(), this returns the number of bytes written or + * that would be required to write if greater or equal than size. + */ +EAPI size_t +e_user_dir_concat_len(char *dst, size_t size, const char *path, size_t path_len) +{ + if (!_e_user_dir) + e_user_dir_get(); + + return ecore_str_join_len(dst, size, '/', _e_user_dir, _e_user_dir_len, path, path_len); +} + +/** + * same as snprintf("~/.e/e/"fmt, ...). + */ +EAPI size_t +e_user_dir_snprintf(char *dst, size_t size, const char *fmt, ...) +{ + size_t off, ret; + va_list ap; + + if (!_e_user_dir) + e_user_dir_get(); + + va_start(ap, fmt); + + off = _e_user_dir_len + 1; + if (size < _e_user_dir_len + 2) + { + if (size > 1) + { + memcpy(dst, _e_user_dir, size - 1); + dst[size - 1] = '\0'; + } + ret = off + vsnprintf(dst + off, size - off, fmt, ap); + va_end(ap); + return ret; + } + + memcpy(dst, _e_user_dir, _e_user_dir_len); + dst[_e_user_dir_len] = '/'; + + ret = off + vsnprintf(dst + off, size - off, fmt, ap); + va_end(ap); + return ret; +} diff --git a/src/bin/e_user.h b/src/bin/e_user.h index 4d2ae217a..d7a727f80 100644 --- a/src/bin/e_user.h +++ b/src/bin/e_user.h @@ -6,7 +6,28 @@ #ifndef E_USER_H #define E_USER_H +#include + EAPI const char *e_user_homedir_get(void); +EAPI size_t e_user_homedir_concat_len(char *dst, size_t size, const char *path, size_t path_len); +EAPI size_t e_user_homedir_snprintf(char *dst, size_t size, const char *fmt, ...) EINA_PRINTF(3, 4); + +static inline size_t e_user_homedir_concat(char *dst, size_t size, const char *path) +{ + return e_user_homedir_concat_len(dst, size, path, strlen(path)); +} +#define e_user_homedir_concat_static(dst, path) e_user_homedir_concat_len(dst, sizeof(dst), path, (sizeof(path) > 0) ? sizeof(path) - 1 : 0) + +EAPI const char *e_user_dir_get(void); +EAPI size_t e_user_dir_concat_len(char *dst, size_t size, const char *path, size_t path_len); +EAPI size_t e_user_dir_snprintf(char *dst, size_t size, const char *fmt, ...) EINA_PRINTF(3, 4); + +static inline size_t e_user_dir_concat(char *dst, size_t size, const char *path) +{ + return e_user_dir_concat_len(dst, size, path, strlen(path)); +} +#define e_user_dir_concat_static(dst, path) e_user_dir_concat_len(dst, sizeof(dst), path, (sizeof(path) > 0) ? sizeof(path) - 1 : 0) + EAPI const char *e_user_desktop_dir_get(void); EAPI const char *e_user_icon_dir_get(void); diff --git a/src/bin/e_widget_fsel.c b/src/bin/e_widget_fsel.c index 1d6a40251..0500c045c 100644 --- a/src/bin/e_widget_fsel.c +++ b/src/bin/e_widget_fsel.c @@ -70,34 +70,39 @@ static void _e_wid_fsel_favorites_add(void *data1, void *data2) { E_Widget_Data *wd; - const char *current_path, *homedir; + const char *current_path; char buf[4096], *fname; struct stat st; - int i = 1; FILE *f; - + size_t len; + wd = data1; current_path = e_fm2_real_path_get(wd->o_files_fm); if (!ecore_file_is_dir(current_path)) return; - homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/fileman/favorites/%s", - homedir, ecore_file_file_get(current_path)); + + len = e_user_dir_snprintf(buf, sizeof(buf), "fileman/favorites/%s", + ecore_file_file_get(current_path)); + if (len >= sizeof(buf)) return; if (stat(buf, &st) < 0) symlink(current_path, buf); else { - while (stat(buf, &st) == 0) + unsigned int i = 1, maxlen; + buf[len] = '-'; + len++; + if (len == sizeof(buf)) return; + maxlen = sizeof(buf) - len; + do { - snprintf(buf, sizeof(buf), - "%s/.e/e/fileman/favorites/%s-%d", - homedir, - ecore_file_file_get(current_path), i); + if (snprintf(buf + len, maxlen, "%d", i) >= maxlen) + return; i++; } - symlink(current_path, buf); + while (stat(buf, &st) == 0); + symlink(current_path, buf); } fname = alloca(strlen(ecore_file_file_get(buf)) + 1); strcpy(fname, ecore_file_file_get(buf)); - snprintf(buf, sizeof(buf), "%s/.e/e/fileman/favorites/.order", homedir); + e_user_dir_concat_static(buf, "fileman/favorites/.order"); if (ecore_file_exists(buf)) { f = fopen(buf, "a"); diff --git a/src/modules/conf_applications/e_int_config_apps.c b/src/modules/conf_applications/e_int_config_apps.c index 88224493e..309285b24 100644 --- a/src/modules/conf_applications/e_int_config_apps.c +++ b/src/modules/conf_applications/e_int_config_apps.c @@ -45,8 +45,7 @@ e_int_config_apps_favs(E_Container *con, const char *params __UNUSED__) E_Config_Data *data; char buf[4096]; - snprintf(buf, sizeof(buf), "%s/.e/e/applications/menu/favorite.menu", - e_user_homedir_get()); + e_user_dir_concat_static(buf, "applications/menu/favorite.menu"); data = E_NEW(E_Config_Data, 1); data->title = eina_stringshare_add(_("Favorites Menu")); data->dialog = eina_stringshare_add("_config_apps_favs_dialog"); @@ -100,8 +99,7 @@ e_int_config_apps_ibar(E_Container *con, const char *params __UNUSED__) E_Config_Data *data; char buf[4096]; - snprintf(buf, sizeof(buf), "%s/.e/e/applications/bar/default/.order", - e_user_homedir_get()); + e_user_dir_concat_static(buf, "applications/bar/default/.order"); data = E_NEW(E_Config_Data, 1); data->title = eina_stringshare_add(_("IBar Applications")); data->dialog = eina_stringshare_add("_config_apps_ibar_dialog"); @@ -132,8 +130,7 @@ e_int_config_apps_startup(E_Container *con, const char *params __UNUSED__) E_Config_Data *data; char buf[4096]; - snprintf(buf, sizeof(buf), "%s/.e/e/applications/startup/.order", - e_user_homedir_get()); + e_user_dir_concat_static(buf, "applications/startup/.order"); data = E_NEW(E_Config_Data, 1); data->title = eina_stringshare_add(_("Startup Applications")); data->dialog = eina_stringshare_add("_config_apps_startup_dialog"); @@ -149,8 +146,7 @@ e_int_config_apps_restart(E_Container *con, const char *params __UNUSED__) E_Config_Data *data; char buf[4096]; - snprintf(buf, sizeof(buf), "%s/.e/e/applications/restart/.order", - e_user_homedir_get()); + e_user_dir_concat_static(buf, "applications/restart/.order"); data = E_NEW(E_Config_Data, 1); data->title = eina_stringshare_add(_("Restart Applications")); data->dialog = eina_stringshare_add("_config_apps_restart_dialog"); diff --git a/src/modules/conf_desklock/e_int_config_desklock.c b/src/modules/conf_desklock/e_int_config_desklock.c index b585d771a..abebb38a6 100644 --- a/src/modules/conf_desklock/e_int_config_desklock.c +++ b/src/modules/conf_desklock/e_int_config_desklock.c @@ -213,9 +213,9 @@ _adv_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata) e_widget_table_object_append(ft, cfdata->o_btn, 0, 1, 1, 1, 0, 0, 0, 0); if (cfdata->fmdir == 1) - snprintf(path, sizeof(path), "%s/data/backgrounds", e_prefix_data_get()); + e_prefix_data_concat_static(path, "data/backgrounds"); else - snprintf(path, sizeof(path), "%s/.e/e/backgrounds", e_user_homedir_get()); + e_user_dir_concat_static(path, "backgrounds"); ow = e_fm2_add(evas); cfdata->o_fm = ow; @@ -421,11 +421,11 @@ _cb_method_change(void *data, Evas_Object *obj, void *event_info) if (!ic) return; e_fm2_select_set(cfdata->o_fm, ic->file, 1); if (cfdata->fmdir == 0) - snprintf(path, sizeof(path), "%s/.e/e/backgrounds/%s", - e_user_homedir_get(), ic->file); + e_user_dir_snprintf(path, sizeof(path), "backgrounds/%s", + ic->file); else - snprintf(path, sizeof(path), "%s/data/backgrounds/%s", - e_prefix_data_get(), ic->file); + e_prefix_data_snprintf(path, sizeof(path), "data/backgrounds/%s", + ic->file); if (ecore_file_is_dir(path)) return; E_FREE(cfdata->bg); cfdata->bg = strdup(path); @@ -442,10 +442,10 @@ _cb_radio_change(void *data, Evas_Object *obj) cfdata = data; if (!cfdata->o_fm) return; - if (cfdata->fmdir == 0) - snprintf(path, sizeof(path), "%s/.e/e/backgrounds", e_user_homedir_get()); - else - snprintf(path, sizeof(path), "%s/data/backgrounds", e_prefix_data_get()); + if (cfdata->fmdir == 0) + e_user_dir_concat_static(path, "backgrounds"); + else + e_prefix_data_concat_static(path, "%s/data/backgrounds"); e_fm2_path_set(cfdata->o_fm, path, "/"); } @@ -503,13 +503,13 @@ _cb_fm_sel_change(void *data, Evas_Object *obj, void *event_info) if (cfdata->fmdir == 0) { - snprintf(path, sizeof(path), "%s/.e/e/backgrounds/%s", - e_user_homedir_get(), ic->file); + e_user_dir_snprintf(path, sizeof(path), "backgrounds/%s", + ic->file); } else { - snprintf(path, sizeof(path), "%s/data/backgrounds/%s", - e_prefix_data_get(), ic->file); + e_prefix_data_snprintf(path, sizeof(path), "data/backgrounds/%s", + ic->file); } if (ecore_file_is_dir(path)) return; E_FREE(cfdata->bg); @@ -525,7 +525,8 @@ _cb_fm_change(void *data, Evas_Object *obj, void *event_info) E_Config_Dialog_Data *cfdata; const char *p; char path[PATH_MAX]; - + size_t len; + cfdata = data; if (!cfdata->bg) return; if (!cfdata->o_fm) return; @@ -536,16 +537,15 @@ _cb_fm_change(void *data, Evas_Object *obj, void *event_info) } else return; - - snprintf(path, sizeof(path), "%s/.e/e/backgrounds", e_user_homedir_get()); - if (!strncmp(cfdata->bg, path, strlen(path))) - p = cfdata->bg + strlen(path) + 1; - else + + len = e_user_dir_concat_static(path, "backgrounds"); + if (!strncmp(cfdata->bg, path, len)) + p = cfdata->bg + len + 1; + else { - snprintf(path, sizeof(path), "%s/data/backgrounds", - e_prefix_data_get()); - if (!strncmp(cfdata->bg, path, strlen(path))) - p = cfdata->bg + strlen(path) + 1; + len = e_prefix_data_concat_static(path, "data/backgrounds"); + if (!strncmp(cfdata->bg, path, len)) + p = cfdata->bg + len + 1; else p = cfdata->bg; } diff --git a/src/modules/conf_profiles/e_int_config_profiles.c b/src/modules/conf_profiles/e_int_config_profiles.c index f6c2ad42b..b4a27fac9 100644 --- a/src/modules/conf_profiles/e_int_config_profiles.c +++ b/src/modules/conf_profiles/e_int_config_profiles.c @@ -100,7 +100,6 @@ static Evas_Object * _create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata) { Evas_Object *o, *of, *ot, *ob; - const char *dir; char buf[PATH_MAX]; o = e_widget_list_add(evas, 0, 0); @@ -127,8 +126,7 @@ _create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata) e_widget_table_object_align_append(ot, cfdata->o_reset, 2, 0, 1, 1, 0, 1, 1, 1, 1.0, 0.5); // if there is a system version of the profile - allow reset - dir = e_prefix_data_get(); - snprintf(buf, sizeof(buf), "%s/data/config/%s/", dir, e_config_profile_get()); + e_prefix_data_snprintf(buf, sizeof(buf), "data/config/%s/", e_config_profile_get()); if (ecore_file_is_dir(buf)) e_widget_disabled_set(cfdata->o_reset, 0); else @@ -170,7 +168,7 @@ _ilist_fill(E_Config_Dialog_Data *cfdata) Efreet_Desktop *desk = NULL; Evas_Object *ic; char buf[PATH_MAX], *prof, *pdir; - const char *label, *dir; + const char *label; prof = l->data; if (e_config_profile_get()) @@ -182,8 +180,7 @@ _ilist_fill(E_Config_Dialog_Data *cfdata) desk = efreet_desktop_get(buf); if (!desk) { - dir = e_prefix_data_get(); - snprintf(buf, sizeof(buf), "%s/data/config/%s/", dir, prof); + e_prefix_data_snprintf(buf, sizeof(buf), "data/config/%s/", prof); pdir = strdup(buf); if (pdir) { @@ -199,7 +196,7 @@ _ilist_fill(E_Config_Dialog_Data *cfdata) if ((desk) && (desk->icon) && (pdir)) snprintf(buf, sizeof(buf), "%s/%s", pdir, desk->icon); else - snprintf(buf, sizeof(buf), "%s/data/images/enlightenment.png", e_prefix_data_get()); + e_prefix_data_concat_static(buf, "data/images/enlightenment.png"); ic = e_util_icon_add(buf, evas); e_widget_ilist_append(cfdata->o_list, ic, label, _ilist_cb_selected, cfdata, prof); if (pdir) free(pdir); @@ -221,7 +218,7 @@ static void _ilist_cb_selected(void *data) { E_Config_Dialog_Data *cfdata; - const char *cur_profile, *dir; + const char *cur_profile; unsigned char v; Efreet_Desktop *desk = NULL; char *pdir, buf[PATH_MAX]; @@ -240,8 +237,7 @@ _ilist_cb_selected(void *data) desk = efreet_desktop_get(buf); if (!desk) { - dir = e_prefix_data_get(); - snprintf(buf, sizeof(buf), "%s/data/config/%s/", dir, cfdata->sel_profile); + e_prefix_data_snprintf(buf, sizeof(buf), "data/config/%s/", cfdata->sel_profile); pdir = strdup(buf); if (pdir) { diff --git a/src/modules/conf_startup/e_int_config_startup.c b/src/modules/conf_startup/e_int_config_startup.c index b6af9b0a1..34aa377ad 100644 --- a/src/modules/conf_startup/e_int_config_startup.c +++ b/src/modules/conf_startup/e_int_config_startup.c @@ -116,9 +116,10 @@ static void _cb_files_files_changed(void *data, Evas_Object *obj, void *event_info) { E_Config_Dialog_Data *cfdata; - const char *p, *homedir; char buf[4096]; - + const char *p; + size_t len; + cfdata = data; if (!cfdata->splash) return; if (!cfdata->o_fm) return; @@ -127,16 +128,15 @@ _cb_files_files_changed(void *data, Evas_Object *obj, void *event_info) { if (strncmp(p, cfdata->splash, strlen(p))) return; } - homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/themes", homedir); + len = e_user_dir_concat_static(buf, "themes"); if (!p) return; - if (!strncmp(cfdata->splash, buf, strlen(buf))) - p = cfdata->splash + strlen(buf) + 1; + if (!strncmp(cfdata->splash, buf, len)) + p = cfdata->splash + len + 1; else { - snprintf(buf, sizeof(buf), "%s/data/themes", e_prefix_data_get()); - if (!strncmp(cfdata->splash, buf, strlen(buf))) - p = cfdata->splash + strlen(buf) + 1; + len = e_prefix_data_concat_static(buf, "data/themes"); + if (!strncmp(cfdata->splash, buf, len)) + p = cfdata->splash + len + 1; else p = cfdata->splash; } @@ -149,17 +149,15 @@ _cb_dir(void *data, Evas_Object *obj, void *event_info) { E_Config_Dialog_Data *cfdata; char path[4096]; - const char *homedir; - + cfdata = data; if (cfdata->fmdir == 1) { - snprintf(path, sizeof(path), "%s/data/themes", e_prefix_data_get()); + e_prefix_data_concat_static(path, "data/themes"); } else { - homedir = e_user_homedir_get(); - snprintf(path, sizeof(path), "%s/.e/e/themes", homedir); + e_user_dir_concat_static(path, "themes"); } e_fm2_path_set(cfdata->o_fm, path, "/"); } @@ -168,7 +166,7 @@ static void _fill_data(E_Config_Dialog_Data *cfdata) { char path[4096]; - const char *homedir; + size_t len; cfdata->show_splash = e_config->show_splash; cfdata->splash = NULL; @@ -176,13 +174,12 @@ _fill_data(E_Config_Dialog_Data *cfdata) cfdata->splash = strdup(e_config->init_default_theme); else { - snprintf(path, sizeof(path), "%s/data/themes/default.edj", e_prefix_data_get()); + e_prefix_data_concat_static(path, "data/themes/default.edj"); cfdata->splash = strdup(path); } if (cfdata->splash[0] != '/') { - homedir = e_user_homedir_get(); - snprintf(path, sizeof(path), "%s/.e/e/themes/%s", homedir, cfdata->splash); + e_user_dir_snprintf(path, sizeof(path), "themes/%s", cfdata->splash); if (ecore_file_exists(path)) { E_FREE(cfdata->splash); @@ -190,7 +187,7 @@ _fill_data(E_Config_Dialog_Data *cfdata) } else { - snprintf(path, sizeof(path), "%s/data/themes/%s", e_prefix_data_get(), cfdata->splash); + e_prefix_data_snprintf(path, sizeof(path), "data/themes/%s", cfdata->splash); if (ecore_file_exists(path)) { E_FREE(cfdata->splash); @@ -198,9 +195,9 @@ _fill_data(E_Config_Dialog_Data *cfdata) } } } - - snprintf(path, sizeof(path), "%s/data/themes", e_prefix_data_get()); - if (!strncmp(cfdata->splash, path, strlen(path))) + + len = e_prefix_data_concat_static(path, "data/themes"); + if (!strncmp(cfdata->splash, path, len)) cfdata->fmdir = 1; } @@ -251,13 +248,10 @@ _basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cf { Evas_Object *o, *ot, *of, *il, *ol; char path[4096]; - const char *homedir; E_Fm2_Config fmc; E_Zone *z; E_Radio_Group *rg; - homedir = e_user_homedir_get(); - z = e_zone_current_get(cfd->con); ot = e_widget_table_add(evas, 0); @@ -284,9 +278,9 @@ _basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cf e_widget_table_object_append(ol, o, 0, 1, 1, 1, 0, 0, 0, 0); if (cfdata->fmdir == 1) - snprintf(path, sizeof(path), "%s/data/themes", e_prefix_data_get()); + e_prefix_data_concat_static(path, "data/themes"); else - snprintf(path, sizeof(path), "%s/.e/e/themes", homedir); + e_user_dir_concat_static(path, "themes"); o = e_fm2_add(evas); cfdata->o_fm = o; diff --git a/src/modules/conf_theme/e_int_config_theme.c b/src/modules/conf_theme/e_int_config_theme.c index 67647cdd2..cf61fb753 100644 --- a/src/modules/conf_theme/e_int_config_theme.c +++ b/src/modules/conf_theme/e_int_config_theme.c @@ -122,7 +122,7 @@ e_int_config_theme_update(E_Config_Dialog *dia, char *file) cfdata->fmdir = 1; e_widget_radio_toggle_set(cfdata->o_personal, 1); - snprintf(path, sizeof(path), "%s/.e/e/themes", e_user_homedir_get()); + e_user_dir_concat_static(path, "themes"); eina_stringshare_del(cfdata->theme); cfdata->theme = eina_stringshare_add(file); @@ -201,6 +201,7 @@ _cb_files_files_changed(void *data, Evas_Object *obj, void *event_info) E_Config_Dialog_Data *cfdata; const char *p; char buf[4096]; + size_t len; cfdata = data; if ((!cfdata->theme) || (!cfdata->o_fm)) return; @@ -212,14 +213,14 @@ _cb_files_files_changed(void *data, Evas_Object *obj, void *event_info) } if (!p) return; - snprintf(buf, sizeof(buf), "%s/.e/e/themes", e_user_homedir_get()); - if (!strncmp(cfdata->theme, buf, strlen(buf))) - p = cfdata->theme + strlen(buf) + 1; + len = e_user_dir_concat_static(buf, "themes"); + if (!strncmp(cfdata->theme, buf, len)) + p = cfdata->theme + len + 1; else { - snprintf(buf, sizeof(buf), "%s/data/themes", e_prefix_data_get()); - if (!strncmp(cfdata->theme, buf, strlen(buf))) - p = cfdata->theme + strlen(buf) + 1; + len = e_prefix_data_concat_static(buf, "data/themes"); + if (!strncmp(cfdata->theme, buf, len)) + p = cfdata->theme + len + 1; else p = cfdata->theme; } @@ -235,9 +236,9 @@ _cb_dir(void *data, Evas_Object *obj, void *event_info) cfdata = data; if (cfdata->fmdir == 1) - snprintf(path, sizeof(path), "%s/data/themes", e_prefix_data_get()); + e_prefix_data_concat_static(path, "data/themes"); else - snprintf(path, sizeof(path), "%s/.e/e/themes", e_user_homedir_get()); + e_user_dir_concat_static(path, "themes"); e_widget_flist_path_set(cfdata->o_fm, path, "/"); } @@ -305,20 +306,19 @@ _fill_data(E_Config_Dialog_Data *cfdata) { E_Config_Theme * c; char path[4096]; + size_t len; c = e_theme_config_get("theme"); if (c) cfdata->theme = eina_stringshare_add(c->file); else { - snprintf(path, sizeof(path), "%s/data/themes/default.edj", - e_prefix_data_get()); + e_prefix_data_concat_static(path, "data/themes/default.edj"); cfdata->theme = eina_stringshare_add(path); } if (cfdata->theme[0] != '/') { - snprintf(path, sizeof(path), "%s/.e/e/themes/%s", - e_user_homedir_get(), cfdata->theme); + e_user_dir_snprintf(path, sizeof(path), "themes/%s", cfdata->theme); if (ecore_file_exists(path)) { eina_stringshare_del(cfdata->theme); @@ -326,8 +326,8 @@ _fill_data(E_Config_Dialog_Data *cfdata) } else { - snprintf(path, sizeof(path), "%s/data/themes/%s", - e_prefix_data_get(), cfdata->theme); + e_prefix_data_snprintf(path, sizeof(path), "data/themes/%s", + cfdata->theme); if (ecore_file_exists(path)) { eina_stringshare_del(cfdata->theme); @@ -338,8 +338,8 @@ _fill_data(E_Config_Dialog_Data *cfdata) cfdata->theme_list = _get_theme_categories_list(); - snprintf(path, sizeof(path), "%s/data/themes", e_prefix_data_get()); - if (!strncmp(cfdata->theme, path, strlen(path))) + len = e_prefix_data_concat_static(path, "data/themes"); + if (!strncmp(cfdata->theme, path, len)) cfdata->fmdir = 1; } @@ -405,9 +405,9 @@ _basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cf e_widget_table_object_append(ol, o, 0, 1, 1, 1, 0, 0, 0, 0); if (cfdata->fmdir == 1) - snprintf(path, sizeof(path), "%s/data/themes", e_prefix_data_get()); + e_prefix_data_concat_static(path, "data/themes"); else - snprintf(path, sizeof(path), "%s/.e/e/themes", e_user_homedir_get()); + e_user_dir_concat_static(path, "themes"); o = e_widget_flist_add(evas); cfdata->o_fm = o; @@ -599,12 +599,10 @@ _files_ilist_nth_label_to_file(void *data, int n) if (!cfdata->o_files_ilist) return NULL; if (n > cfdata->personal_file_count) - snprintf(file, sizeof(file), "%s/data/themes/%s.edj", - e_prefix_data_get(), + e_prefix_data_snprintf(file, sizeof(file), "data/themes/%s.edj", e_widget_ilist_nth_label_get(cfdata->o_files_ilist, n)); else - snprintf(file, sizeof(file), "%s/.e/e/themes/%s.edj", - e_user_homedir_get(), + e_user_dir_snprintf(file, sizeof(file), "themes/%s.edj", e_widget_ilist_nth_label_get(cfdata->o_files_ilist, n)); return eina_stringshare_add(file); @@ -787,14 +785,12 @@ _fill_files_ilist(E_Config_Dialog_Data *cfdata) e_widget_ilist_clear(o); /* Grab the "Personal" themes. */ - snprintf(theme_dir, sizeof(theme_dir), "%s/.e/e/themes", - e_user_homedir_get()); + e_user_dir_concat_static(theme_dir, "themes"); cfdata->personal_file_count = _ilist_files_add(cfdata, _("Personal"), theme_dir); /* Grab the "System" themes. */ - snprintf(theme_dir, sizeof(theme_dir), - "%s/data/themes", e_prefix_data_get()); + e_prefix_data_concat_static(theme_dir, "data/themes"); _ilist_files_add(cfdata, _("System"), theme_dir); e_widget_ilist_go(o); diff --git a/src/modules/conf_theme/e_int_config_theme_import.c b/src/modules/conf_theme/e_int_config_theme_import.c index 3a30499bf..4d4846bf7 100644 --- a/src/modules/conf_theme/e_int_config_theme_import.c +++ b/src/modules/conf_theme/e_int_config_theme_import.c @@ -242,15 +242,12 @@ _theme_import_cb_ok(void *data, void *data2) E_Win *win; const char *path; const char *file; - const char *homedir; char buf[4096]; win = data; import = win->data; if (!import) return; - homedir = e_user_homedir_get(); - path = e_widget_fsel_selection_path_get(import->fsel_obj); E_FREE(import->cfdata->file); if (path) @@ -261,7 +258,7 @@ _theme_import_cb_ok(void *data, void *data2) char *strip; file = ecore_file_file_get(import->cfdata->file); - snprintf(buf, sizeof(buf), "%s/.e/e/themes/%s", homedir, file); + e_user_dir_snprintf(buf, sizeof(buf), "themes/%s", file); strip = ecore_file_strip_ext(file); if (!strip) diff --git a/src/modules/conf_theme/e_int_config_theme_web.c b/src/modules/conf_theme/e_int_config_theme_web.c index bf4d18e02..067a35cb9 100644 --- a/src/modules/conf_theme/e_int_config_theme_web.c +++ b/src/modules/conf_theme/e_int_config_theme_web.c @@ -137,7 +137,7 @@ e_int_config_theme_web(E_Config_Dialog *parent) ol = e_widget_list_add(e_win_evas_get(dia->win), 0, 1); /* The Exchange Smart Object*/ - snprintf(usr_dir, sizeof(usr_dir), "%s/.e/e/themes", e_user_homedir_get()); + e_user_dir_concat_static(usr_dir, "themes"); exsm = exchange_smart_object_add(e_win_evas_get(dia->win)); exchange_smart_object_remote_group_set(exsm, "Border"); exchange_smart_object_local_path_set(exsm, usr_dir); diff --git a/src/modules/conf_wallpaper/e_int_config_wallpaper.c b/src/modules/conf_wallpaper/e_int_config_wallpaper.c index 66f65fd70..bcbeb2cc0 100644 --- a/src/modules/conf_wallpaper/e_int_config_wallpaper.c +++ b/src/modules/conf_wallpaper/e_int_config_wallpaper.c @@ -122,7 +122,7 @@ e_int_config_wallpaper_update(E_Config_Dialog *dia, char *file) cfdata = dia->cfdata; cfdata->fmdir = 1; e_widget_radio_toggle_set(cfdata->o_personal, 1); - snprintf(path, sizeof(path), "%s/.e/e/backgrounds", e_user_homedir_get()); + e_user_dir_concat_static(path, "backgrounds"); E_FREE(cfdata->bg); cfdata->bg = strdup(file); cfdata->use_theme_bg = 0; @@ -255,6 +255,7 @@ _cb_files_files_changed(void *data, Evas_Object *obj, void *event_info) E_Config_Dialog_Data *cfdata; const char *p = NULL; char buf[PATH_MAX]; + size_t len; cfdata = data; if ((!cfdata->bg) || (!cfdata->o_fm)) return; @@ -265,14 +266,14 @@ _cb_files_files_changed(void *data, Evas_Object *obj, void *event_info) } else return; - snprintf(buf, sizeof(buf), "%s/.e/e/backgrounds", e_user_homedir_get()); - if (!strncmp(cfdata->bg, buf, strlen(buf))) - p = cfdata->bg + strlen(buf) + 1; + len = e_user_dir_concat_static(buf, "backgrounds"); + if (!strncmp(cfdata->bg, buf, len)) + p = cfdata->bg + len + 1; else { - snprintf(buf, sizeof(buf), "%s/data/backgrounds", e_prefix_data_get()); - if (!strncmp(cfdata->bg, buf, strlen(buf))) - p = cfdata->bg + strlen(buf) + 1; + len = e_prefix_data_concat_static(buf, "data/backgrounds"); + if (!strncmp(cfdata->bg, buf, len)) + p = cfdata->bg + len + 1; else p = cfdata->bg; } @@ -351,9 +352,9 @@ _cb_dir(void *data, Evas_Object *obj, void *event_info) cfdata = data; if (cfdata->fmdir == 1) - snprintf(path, sizeof(path), "%s/data/backgrounds", e_prefix_data_get()); + e_prefix_data_concat_static(path, "data/backgrounds"); else - snprintf(path, sizeof(path), "%s/.e/e/backgrounds", e_user_homedir_get()); + e_user_dir_concat_static(path, "backgrounds"); e_widget_flist_path_set(cfdata->o_fm, path, "/"); } @@ -444,13 +445,13 @@ _fill_data(E_Config_Dialog_Data *cfdata) if (cfdata->bg) { const char *f; + size_t len; f = e_theme_edje_file_get("base/theme/backgrounds", "e/desktop/background"); if (!strcmp(cfdata->bg, f)) cfdata->use_theme_bg = 1; - snprintf(path, sizeof(path), "%s/data/backgrounds", - e_prefix_data_get()); - if (!strncmp(cfdata->bg, path, strlen(path))) cfdata->fmdir = 1; + len = e_prefix_data_concat_static(path, "data/backgrounds"); + if (!strncmp(cfdata->bg, path, len)) cfdata->fmdir = 1; } else cfdata->use_theme_bg = 1; @@ -521,9 +522,9 @@ _basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata) e_widget_table_object_append(ot, ow, 0, 1, 1, 1, 0, 0, 0, 0); if (cfdata->fmdir == 1) - snprintf(path, sizeof(path), "%s/data/backgrounds", e_prefix_data_get()); + e_prefix_data_concat_static(path, "data/backgrounds"); else - snprintf(path, sizeof(path), "%s/.e/e/backgrounds", e_user_homedir_get()); + e_user_dir_concat_static(path, "backgrounds"); ow = e_widget_flist_add(evas); cfdata->o_fm = ow; @@ -651,9 +652,9 @@ _adv_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata) e_widget_table_object_append(ot, ow, 0, 1, 1, 1, 0, 0, 0, 0); if (cfdata->fmdir == 1) - snprintf(path, sizeof(path), "%s/data/backgrounds", e_prefix_data_get()); + e_prefix_data_concat_static(path, "data/backgrounds"); else - snprintf(path, sizeof(path), "%s/.e/e/backgrounds", e_user_homedir_get()); + e_user_dir_concat_static(path, "backgrounds"); ow = e_widget_flist_add(evas); cfdata->o_fm = ow; diff --git a/src/modules/conf_wallpaper/e_int_config_wallpaper_gradient.c b/src/modules/conf_wallpaper/e_int_config_wallpaper_gradient.c index cd435be01..a7d2413a3 100644 --- a/src/modules/conf_wallpaper/e_int_config_wallpaper_gradient.c +++ b/src/modules/conf_wallpaper/e_int_config_wallpaper_gradient.c @@ -254,21 +254,22 @@ _import_edj_gen(Import *import) Evas *evas; int fd, num = 1; const char *file; - const char *homedir; char buf[4096], cmd[4096], tmpn[4096]; char *fstrip; FILE *f; + size_t len, off; evas = e_win_evas_get(import->dia->win); file = import->cfdata->name; - homedir = e_user_homedir_get(); fstrip = ecore_file_strip_ext(file); if (!fstrip) return; - snprintf(buf, sizeof(buf), "%s/.e/e/backgrounds/%s.edj", homedir, fstrip); + len = e_user_dir_snprintf(buf, sizeof(buf), "backgrounds/%s.edj", fstrip); + if (len >= sizeof(buf)) return; + off = len - sizeof(".edj") - 1; while (ecore_file_exists(buf)) { - snprintf(buf, sizeof(buf), "%s/.e/e/backgrounds/%s-%i.edj", homedir, fstrip, num); + snprintf(buf + off, sizeof(buf) - off, "-%d.edj", num); num++; } free(fstrip); diff --git a/src/modules/conf_wallpaper/e_int_config_wallpaper_import.c b/src/modules/conf_wallpaper/e_int_config_wallpaper_import.c index 80294c9f7..dbcf59089 100644 --- a/src/modules/conf_wallpaper/e_int_config_wallpaper_import.c +++ b/src/modules/conf_wallpaper/e_int_config_wallpaper_import.c @@ -416,22 +416,23 @@ _import_edj_gen(Import *import) Evas_Object *img; int fd, num = 1; int w = 0, h = 0; - const char *file, *homedir, *locale; + const char *file, *locale; char buf[4096], cmd[4096], tmpn[4096], ipart[4096], enc[128]; char *imgdir = NULL, *fstrip; int cr = 255, cg = 255, cb = 255, ca = 255; FILE *f; + size_t len, off; evas = e_win_evas_get(import->win); file = ecore_file_file_get(import->cfdata->file); - homedir = e_user_homedir_get(); fstrip = ecore_file_strip_ext(file); if (!fstrip) return; - snprintf(buf, sizeof(buf), "%s/.e/e/backgrounds/%s.edj", homedir, fstrip); + len = e_user_dir_snprintf(buf, sizeof(buf), "backgrounds/%s.edj", fstrip); + if (len >= sizeof(buf)) return; + off = len - sizeof(".edj") - 1; while (ecore_file_exists(buf)) { - snprintf(buf, sizeof(buf), "%s/.e/e/backgrounds/%s-%i.edj", - homedir, fstrip, num); + snprintf(buf + off, sizeof(buf) - off, "-%d.edj", num); num++; } free(fstrip); @@ -664,7 +665,6 @@ _import_cb_ok(void *data, void *data2) FSel *fsel; E_Win *win; const char *file; - const char *homedir; char buf[4096]; int is_bg, is_theme; int r; @@ -683,9 +683,7 @@ _import_cb_ok(void *data, void *data2) } else { - homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/backgrounds/%s", - homedir, file); + e_user_dir_snprintf(buf, sizeof(buf), "backgrounds/%s", file); is_bg = edje_file_group_exists(import->cfdata->file, "e/desktop/background"); @@ -775,14 +773,12 @@ _fsel_cb_ok(void *data, void *data2) { int r; int is_bg, is_theme; - const char *homedir, *file; + const char *file; char buf[4096]; r = 0; file = ecore_file_file_get(path); - homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/backgrounds/%s", - homedir, file); + e_user_dir_snprintf(buf, sizeof(buf), "backgrounds/%s", file); is_bg = edje_file_group_exists(path, "e/desktop/background"); diff --git a/src/modules/conf_wallpaper/e_int_config_wallpaper_web.c b/src/modules/conf_wallpaper/e_int_config_wallpaper_web.c index 842d3c705..14a1f8af5 100644 --- a/src/modules/conf_wallpaper/e_int_config_wallpaper_web.c +++ b/src/modules/conf_wallpaper/e_int_config_wallpaper_web.c @@ -132,7 +132,7 @@ e_int_config_wallpaper_web(E_Config_Dialog *parent) ol = e_widget_list_add(e_win_evas_get(dia->win), 0, 1); /* The Exchange Smart Object*/ - snprintf(usr_dir, sizeof(usr_dir), "%s/.e/e/backgrounds", e_user_homedir_get()); + e_user_dir_concat_static(usr_dir, "backgrounds"); exsm = exchange_smart_object_add(e_win_evas_get(dia->win)); exchange_smart_object_remote_group_set(exsm, "Wallpaper"); exchange_smart_object_local_path_set(exsm, usr_dir); diff --git a/src/modules/conf_wallpaper2/e_int_config_wallpaper.c b/src/modules/conf_wallpaper2/e_int_config_wallpaper.c index eb14fd5d5..f25367046 100644 --- a/src/modules/conf_wallpaper2/e_int_config_wallpaper.c +++ b/src/modules/conf_wallpaper2/e_int_config_wallpaper.c @@ -851,9 +851,9 @@ wp_browser_new(E_Container *con) info->win = win; win->data = info; - snprintf(buf, sizeof(buf), "%s/.e/e/backgrounds", e_user_homedir_get()); + e_user_dir_concat_static(buf, "backgrounds"); info->dirs = eina_list_append(info->dirs, strdup(buf)); - snprintf(buf, sizeof(buf), "%s/data/backgrounds", e_prefix_data_get()); + e_prefix_data_concat_static(buf, "data/backgrounds"); info->dirs = eina_list_append(info->dirs, strdup(buf)); e_win_title_set(win, _("Wallpaper Settings")); diff --git a/src/modules/gadman/e_mod_config.c b/src/modules/gadman/e_mod_config.c index eb4b2920c..452d151e6 100644 --- a/src/modules/gadman/e_mod_config.c +++ b/src/modules/gadman/e_mod_config.c @@ -197,9 +197,9 @@ _adv_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfda if (cfdata->fmdir == 1) - snprintf(path, sizeof(path), "%s/data/backgrounds", e_prefix_data_get()); + e_prefix_data_concat_static(path, "data/backgrounds"); else - snprintf(path, sizeof(path), "%s/.e/e/backgrounds", e_user_homedir_get()); + e_user_dir_concat_static(path, "backgrounds"); ow = e_fm2_add(evas); cfdata->o_fm = ow; @@ -362,13 +362,13 @@ _cb_fm_radio_change(void *data, Evas_Object *obj) { E_Config_Dialog_Data *cfdata; char path[PATH_MAX]; - + cfdata = data; if (!cfdata->o_fm) return; - if (cfdata->fmdir == 0) - snprintf(path, sizeof(path), "%s/.e/e/backgrounds", e_user_homedir_get()); - else - snprintf(path, sizeof(path), "%s/data/backgrounds", e_prefix_data_get()); + if (cfdata->fmdir == 0) + e_user_dir_concat_static(path, "backgrounds"); + else + e_prefix_data_concat_static(path, "data/backgrounds"); e_fm2_path_set(cfdata->o_fm, path, "/"); } @@ -378,6 +378,7 @@ _cb_fm_change(void *data, Evas_Object *obj, void *event_info) E_Config_Dialog_Data *cfdata; const char *p; char path[PATH_MAX]; + size_t len; cfdata = data; if (!Man->conf->custom_bg) return; @@ -388,14 +389,14 @@ _cb_fm_change(void *data, Evas_Object *obj, void *event_info) if (strncmp(p, Man->conf->custom_bg, strlen(p))) return; - snprintf(path, sizeof(path), "%s/.e/e/backgrounds", e_user_homedir_get()); - if (!strncmp(Man->conf->custom_bg, path, strlen(path))) - p = Man->conf->custom_bg + strlen(path) + 1; + len = e_user_dir_concat_static(path, "backgrounds"); + if (!strncmp(Man->conf->custom_bg, path, len)) + p = Man->conf->custom_bg + len + 1; else { - snprintf(path, sizeof(path), "%s/data/backgrounds", e_prefix_data_get()); - if (!strncmp(Man->conf->custom_bg, path, strlen(path))) - p = Man->conf->custom_bg + strlen(path) + 1; + len = e_prefix_data_concat_static(path, "data/backgrounds"); + if (!strncmp(Man->conf->custom_bg, path, len)) + p = Man->conf->custom_bg + len + 1; else p = Man->conf->custom_bg; } diff --git a/src/modules/ibar/e_mod_config.c b/src/modules/ibar/e_mod_config.c index aeea54f78..3519ce57b 100644 --- a/src/modules/ibar/e_mod_config.c +++ b/src/modules/ibar/e_mod_config.c @@ -197,8 +197,7 @@ _cb_config(void *data, void *data2) E_Config_Dialog_Data *cfdata; cfdata = data; - snprintf(path, sizeof(path), "%s/.e/e/applications/bar/%s/.order", - e_user_homedir_get(), cfdata->dir); + e_user_dir_snprintf(path, sizeof(path), "applications/bar/%s/.order", cfdata->dir); e_configure_registry_call("internal/ibar_other", e_container_current_get(e_manager_current_get()), path); @@ -210,17 +209,16 @@ _cb_entry_ok(char *text, void *data) char buf[4096]; char tmp[4096]; FILE *f; - - snprintf(buf, sizeof(buf), "%s/.e/e/applications/bar/%s", - e_user_homedir_get(), text); + size_t len; - if (!ecore_file_exists(buf)) + len = e_user_dir_snprintf(buf, sizeof(buf), "applications/bar/%s", text); + if (len + sizeof("/.order") >= sizeof(buf)) return; + if (!ecore_file_exists(buf)) { ecore_file_mkdir(buf); - snprintf(buf, sizeof(buf), "%s/.e/e/applications/bar/%s/.order", - e_user_homedir_get(), text); + memcpy(buf + len, "/.order", sizeof("/.order")); f = fopen(buf, "w"); - if (f) + if (f) { /* Populate this .order file with some defaults */ snprintf(tmp, sizeof(tmp), "xterm.desktop\n" "sylpheed.desktop\n" @@ -239,12 +237,13 @@ _cb_confirm_dialog_yes(void *data) { E_Config_Dialog_Data *cfdata; char buf[4096]; - + cfdata = data; - snprintf(buf, sizeof(buf), "%s/.e/e/applications/bar/%s", e_user_homedir_get(), cfdata->dir); + if (e_user_dir_snprintf(buf, sizeof(buf), "applications/bar/%s", cfdata->dir) >= sizeof(buf)) + return; if (ecore_file_is_dir(buf)) ecore_file_recursive_rm(buf); - + _load_tlist(cfdata); } @@ -261,30 +260,35 @@ static void _load_tlist(E_Config_Dialog_Data *cfdata) { Eina_List *dirs; - const char *home; char buf[4096], *file; int selnum = -1; int i = 0; + size_t len; e_widget_ilist_clear(cfdata->tlist); - - home = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/applications/bar", home); + + len = e_user_dir_concat_static(buf, "applications/bar"); + if (len + 2 >= sizeof(buf)) return; dirs = ecore_file_ls(buf); + + buf[len] = '/'; + len++; + EINA_LIST_FREE(dirs, file) + { + if (file[0] == '.') continue; + if (ecore_strlcpy(buf + len, file, sizeof(buf) - len) >= sizeof(buf) - len) + continue; + if (ecore_file_is_dir(buf)) { - if (file[0] == '.') continue; - snprintf(buf, sizeof(buf), "%s/.e/e/applications/bar/%s", home, file); - if (ecore_file_is_dir(buf)) - { - e_widget_ilist_append(cfdata->tlist, NULL, file, NULL, NULL, file); - if ((cfdata->dir) && (!strcmp(cfdata->dir, file))) - selnum = i; - i++; - } + e_widget_ilist_append(cfdata->tlist, NULL, file, NULL, NULL, file); + if ((cfdata->dir) && (!strcmp(cfdata->dir, file))) + selnum = i; + i++; + } free(file); - } + } e_widget_ilist_go(cfdata->tlist); if (selnum >= 0) diff --git a/src/modules/ibar/e_mod_main.c b/src/modules/ibar/e_mod_main.c index 9b1e096f4..1ca9b83da 100644 --- a/src/modules/ibar/e_mod_main.c +++ b/src/modules/ibar/e_mod_main.c @@ -277,10 +277,7 @@ _ibar_new(Evas *evas, Instance *inst) e_box_align_set(b->o_box, 0.5, 0.5); if (inst->ci->dir[0] != '/') { - const char *homedir; - - homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/applications/bar/%s/.order", homedir, inst->ci->dir); + e_user_dir_snprintf(buf, sizeof(buf), "applications/bar/%s/.order", inst->ci->dir); } else ecore_strlcpy(buf, inst->ci->dir, sizeof(buf)); @@ -496,10 +493,7 @@ _ibar_config_update(Config_Item *ci) e_object_del(E_OBJECT(inst->ibar->apps)); if (inst->ci->dir[0] != '/') { - const char *homedir; - - homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/applications/bar/%s/.order", homedir, inst->ci->dir); + e_user_dir_snprintf(buf, sizeof(buf), "applications/bar/%s/.order", inst->ci->dir); } else ecore_strlcpy(buf, inst->ci->dir, sizeof(buf)); diff --git a/src/modules/illume/e_kbd.c b/src/modules/illume/e_kbd.c index 989df1b56..3bad3fc6c 100644 --- a/src/modules/illume/e_kbd.c +++ b/src/modules/illume/e_kbd.c @@ -835,11 +835,8 @@ _e_kbd_dbus_ignore_keyboards_file_load(const char *file) static void _e_kbd_dbus_ignore_keyboards_load(void) { - const char *homedir; char buf[PATH_MAX]; - - homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/keyboards/ignore_built_in_keyboards", homedir); + e_user_dir_concat_static(buf, "keyboards/ignore_built_in_keyboards"); _e_kbd_dbus_ignore_keyboards_file_load(buf); snprintf(buf, sizeof(buf), "%s/keyboards/ignore_built_in_keyboards", e_module_dir_get(mod)); _e_kbd_dbus_ignore_keyboards_file_load(buf); diff --git a/src/modules/illume/e_kbd_buf.c b/src/modules/illume/e_kbd_buf.c index 4ea9b1fd4..0b9689a40 100644 --- a/src/modules/illume/e_kbd_buf.c +++ b/src/modules/illume/e_kbd_buf.c @@ -225,14 +225,12 @@ _e_kbd_buf_cb_data_dict_reload(void *data) { E_Kbd_Buf *kb; char buf[PATH_MAX]; - const char *homedir; - + kb = data; kb->dict.data_reload_delay = NULL; e_kbd_buf_clear(kb); if (kb->dict.data) e_kbd_dict_free(kb->dict.data); - homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/dicts-dynamic/data.dic", homedir); + e_user_dir_concat_static(buf, "dicts-dynamic/data.dic"); kb->dict.data = e_kbd_dict_new(buf); return 0; } @@ -252,28 +250,26 @@ e_kbd_buf_new(const char *sysdicts, const char *dict) { E_Kbd_Buf *kb; char buf[PATH_MAX]; - const char *homedir; - + kb = E_NEW(E_Kbd_Buf, 1); if (!kb) return NULL; kb->sysdicts = evas_stringshare_add(sysdicts); - - homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/dicts", homedir); + + e_user_dir_concat_static(buf, "dicts"); if (!ecore_file_exists(buf)) ecore_file_mkpath(buf); - - snprintf(buf, sizeof(buf), "%s/.e/e/dicts/%s", homedir, dict); + + e_user_dir_snprintf(buf, sizeof(buf), "dicts/%s", dict); kb->dict.sys = e_kbd_dict_new(buf); if (!kb->dict.sys) { snprintf(buf, sizeof(buf), "%s/dicts/%s", kb->sysdicts, dict); kb->dict.sys = e_kbd_dict_new(buf); } - - snprintf(buf, sizeof(buf), "%s/.e/e/dicts-dynamic", homedir); + + e_user_dir_concat_static(buf, "dicts-dynamic"); if (!ecore_file_exists(buf)) ecore_file_mkpath(buf); - - snprintf(buf, sizeof(buf), "%s/.e/e/dicts-dynamic/personal.dic", homedir); + + e_user_dir_concat_static(buf, "dicts-dynamic/personal.dic"); kb->dict.personal = e_kbd_dict_new(buf); if (!kb->dict.personal) { @@ -287,7 +283,7 @@ e_kbd_buf_new(const char *sysdicts, const char *dict) } kb->dict.personal = e_kbd_dict_new(buf); } - snprintf(buf, sizeof(buf), "%s/.e/e/dicts-dynamic/data.dic", homedir); + e_user_dir_concat_static(buf, "dicts-dynamic/data.dic"); kb->dict.data = e_kbd_dict_new(buf); kb->dict.data_monitor = ecore_file_monitor_add(buf, _e_kbd_buf_cb_data_dict_change, kb); @@ -313,17 +309,15 @@ EAPI void e_kbd_buf_dict_set(E_Kbd_Buf *kb, const char *dict) { char buf[PATH_MAX]; - const char *homedir; - + e_kbd_buf_clear(kb); - + if (kb->dict.sys) e_kbd_dict_free(kb->dict.sys); - - homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/dicts", homedir); + + e_user_dir_concat_static(buf, "dicts"); if (!ecore_file_exists(buf)) ecore_file_mkpath(buf); - - snprintf(buf, sizeof(buf), "%s/.e/e/dicts/%s", homedir, dict); + + e_user_dir_snprintf(buf, sizeof(buf), "dicts/%s", dict); kb->dict.sys = e_kbd_dict_new(buf); if (!kb->dict.sys) { diff --git a/src/modules/illume/e_kbd_int.c b/src/modules/illume/e_kbd_int.c index c9703f96b..5930ff1f3 100644 --- a/src/modules/illume/e_kbd_int.c +++ b/src/modules/illume/e_kbd_int.c @@ -1067,48 +1067,61 @@ _e_kbd_int_layouts_list_update(E_Kbd_Int *ki) Eina_List *files; Eina_List *l; char buf[PATH_MAX], *p, *file; - const char *homedir, *fl; + const char *fl; char *path; Eina_List *kbs = NULL, *layouts = NULL; int ok; - - homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/keyboards", homedir); + size_t len; + + len = e_user_dir_concat_static(buf, "keyboards"); + if (len + 2 >= sizeof(buf)) return; + files = ecore_file_ls(buf); + + buf[len] = '/'; + len++; + EINA_LIST_FREE(files, file) + { + p = strrchr(file, '.'); + if ((p) && (!strcmp(p, ".kbd"))) { - p = strrchr(file, '.'); - if ((p) && (!strcmp(p, ".kbd"))) - { - snprintf(buf, sizeof(buf), "%s/.e/e/keyboards/%s", homedir, file); - kbs = eina_list_append(kbs, evas_stringshare_add(buf)); - } + if (ecore_strlcpy(buf + len, file, sizeof(buf) - len) >= sizeof(buf) - len) + continue; + kbs = eina_list_append(kbs, evas_stringshare_add(buf)); + } free(file); } - snprintf(buf, sizeof(buf), "%s/keyboards", ki->syskbds); + len = snprintf(buf, sizeof(buf), "%s/keyboards", ki->syskbds); + if (len + 2 >= sizeof(buf)) return; + files = ecore_file_ls(buf); + + buf[len] = '/'; + len++; + EINA_LIST_FREE(files, file) + { + p = strrchr(file, '.'); + if ((p) && (!strcmp(p, ".kbd"))) { - p = strrchr(file, '.'); - if ((p) && (!strcmp(p, ".kbd"))) + ok = 1; + EINA_LIST_FOREACH(kbs, l, fl) { - ok = 1; - for (l = kbs; l; l = l->next) + if (!strcmp(file, fl)) { - fl = ecore_file_file_get(l->data); - if (!strcmp(file, fl)) - { - ok = 0; - break; - } - } - if (ok) - { - snprintf(buf, sizeof(buf), "%s/keyboards/%s", ki->syskbds, file); - kbs = eina_list_append(kbs, evas_stringshare_add(buf)); + ok = 0; + break; } } + if (ok) + { + if (ecore_strlcpy(buf + len, file, sizeof(buf) - len) >= sizeof(buf) - len) + continue; + kbs = eina_list_append(kbs, evas_stringshare_add(buf)); + } + } free(file); } /* Previous loop could break before destroying all items. */ @@ -1356,7 +1369,7 @@ _e_kbd_int_dictlist_up(E_Kbd_Int *ki) Eina_List *files; Eina_List *l; char buf[PATH_MAX], *p, *file, *pp; - const char *homedir, *str; + const char *str; int used; if (ki->dictlist.popup) return; @@ -1372,8 +1385,7 @@ _e_kbd_int_dictlist_up(E_Kbd_Int *ki) e_widget_ilist_freeze(o); ki->dictlist.ilist_obj = o; - homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/dicts", homedir); + e_user_dir_concat_static(buf, "dicts"); files = ecore_file_ls(buf); EINA_LIST_FREE(files, file) diff --git a/src/modules/illume/e_mod_win.c b/src/modules/illume/e_mod_win.c index 16760e83f..ec873ec77 100644 --- a/src/modules/illume/e_mod_win.c +++ b/src/modules/illume/e_mod_win.c @@ -943,12 +943,13 @@ _cb_slipshelf_home2(const void *data, E_Slipshelf *ess, E_Border *pbd) static void _apps_unpopulate(void) { - char buf[PATH_MAX], *homedir; + char buf[PATH_MAX]; Efreet_Desktop *desktop; Evas_Object *obj; Eina_List *files; char *file; - + size_t len; + EINA_LIST_FREE(sels, obj) evas_object_del(obj); @@ -964,13 +965,19 @@ _apps_unpopulate(void) if (sf) evas_object_del(sf); sf = NULL; - homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/appshadow", homedir); + len = e_user_dir_concat_static(buf, "appshadow"); + if (len + 2 >= sizeof(buf)) return; + files = ecore_file_ls(buf); + + buf[len] = '/'; + len++; + EINA_LIST_FREE(files, file) - { - snprintf(buf, sizeof(buf), "%s/.e/e/appshadow/%s", homedir, file); - ecore_file_unlink(buf); + { + if (ecore_strlcpy(buf + len, file, sizeof(buf) - len) >= sizeof(buf) - len) + continue; + ecore_file_unlink(buf); free(file); } } @@ -1006,7 +1013,6 @@ _apps_populate(void) Evas_Coord mw, mh, sfw, sfh; Evas_Object *o = NULL; char buf[PATH_MAX]; - char *homedir = NULL; int num = 0; sf = e_scrollframe_add(evas); @@ -1027,8 +1033,7 @@ _apps_populate(void) } else { - homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/appshadow", homedir); + e_user_dir_concat_static(buf, "appshadow"); ecore_file_mkpath(buf); fm = e_fm2_add(evas); _apps_fm_config(fm); @@ -1126,7 +1131,7 @@ _apps_populate(void) { if (desktop) { - snprintf(buf, sizeof(buf), "%s/.e/e/appshadow/%04x.desktop", homedir, num); + e_user_dir_snprintf(buf, sizeof(buf), "appshadow/%04x.desktop", num); ecore_file_symlink(desktop->orig_path, buf); } num++; @@ -1173,8 +1178,7 @@ _apps_populate(void) // _e_illume_pan_get, // _e_illume_pan_max_get, // _e_illume_pan_child_size_get); - homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/appshadow", homedir); + e_user_dir_concat_static(buf, "appshadow"); e_fm2_path_set(fm, NULL, buf); evas_object_show(fm); evas_object_smart_callback_add(fm, "selected", diff --git a/src/modules/wizard/page_010.c b/src/modules/wizard/page_010.c index f93c03cd8..114c9386c 100644 --- a/src/modules/wizard/page_010.c +++ b/src/modules/wizard/page_010.c @@ -149,11 +149,9 @@ wizard_page_show(E_Wizard_Page *pg) E_Intl_Pair *pair; Evas_Object *ic; char buf[PATH_MAX]; - const char *dir; - + pair = l->data; - dir = e_prefix_data_get(); - snprintf(buf, sizeof(buf), "%s/data/images/%s", dir, pair->locale_icon); + e_prefix_data_snprintf(buf, sizeof(buf), "data/images/%s", pair->locale_icon); ic = e_util_icon_add(buf, pg->evas); e_widget_ilist_append(ob, ic, _(pair->locale_translation), NULL, NULL, pair->locale_key); diff --git a/src/modules/wizard/page_020.c b/src/modules/wizard/page_020.c index 45c1b48e4..fb159025b 100644 --- a/src/modules/wizard/page_020.c +++ b/src/modules/wizard/page_020.c @@ -13,9 +13,8 @@ _profile_change(void *data, Evas_Object *obj) char buf[PATH_MAX]; const char *dir; Efreet_Desktop *desk = NULL; - - dir = e_prefix_data_get(); - snprintf(buf, sizeof(buf), "%s/data/config/%s", dir, profile); + + e_prefix_data_snprintf(buf, sizeof(buf), "data/config/%s", profile); dir = strdup(buf); if (!dir) { @@ -80,8 +79,7 @@ wizard_page_show(E_Wizard_Page *pg) continue; } } - dir = e_prefix_data_get(); - snprintf(buf, sizeof(buf), "%s/data/config/%s", dir, prof); + e_prefix_data_snprintf(buf, sizeof(buf), "data/config/%s", prof); // if it's not a system profile - don't offer it if (!ecore_file_is_dir(buf)) { @@ -102,7 +100,7 @@ wizard_page_show(E_Wizard_Page *pg) if ((desk) && (desk->icon)) snprintf(buf, sizeof(buf), "%s/%s", dir, desk->icon); else - snprintf(buf, sizeof(buf), "%s/data/images/enlightenment.png", e_prefix_data_get()); + e_prefix_data_concat_static(buf, "data/images/enlightenment.png"); ic = e_util_icon_add(buf, pg->evas); e_widget_ilist_append(ob, ic, label, NULL, NULL, prof); free(prof); @@ -141,10 +139,8 @@ wizard_page_hide(E_Wizard_Page *pg) if (e_config_profile_get()) { char buf[PATH_MAX]; - const char *homedir; - homedir = e_user_homedir_get(); - - snprintf(buf, sizeof(buf), "%s/.e/e/config/%s", homedir, e_config_profile_get()); + if (e_user_dir_snprintf(buf, sizeof(buf), "config/%s", e_config_profile_get()) >= sizeof(buf)) + return 1; ecore_file_recursive_rm(buf); } if (!profile) profile = "standard"; diff --git a/src/modules/wizard/page_080.c b/src/modules/wizard/page_080.c index fe8abf69e..b0ddc725b 100644 --- a/src/modules/wizard/page_080.c +++ b/src/modules/wizard/page_080.c @@ -112,12 +112,10 @@ wizard_page_apply(E_Wizard_Page *pg) int i; FILE *f; char buf[PATH_MAX]; - const char *homedir; - - homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/applications/bar/default", homedir); + + e_user_dir_concat_static(buf, "applications/bar/default"); ecore_file_mkpath(buf); - snprintf(buf, sizeof(buf), "%s/.e/e/applications/bar/default/.order", homedir); + e_user_dir_concat_static(buf, "applications/bar/default/.order"); f = fopen(buf, "w"); if (f) { diff --git a/src/modules/wizard/page_200.c b/src/modules/wizard/page_200.c index cb076c70f..74e458c9d 100644 --- a/src/modules/wizard/page_200.c +++ b/src/modules/wizard/page_200.c @@ -18,13 +18,11 @@ EAPI int wizard_page_show(E_Wizard_Page *pg) { char buf[PATH_MAX]; - const char *homedir; - + if ((e_config_profile_get()) && (strlen(e_config_profile_get()) > 0)) { - // delete profile - homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/config/%s", homedir, e_config_profile_get()); + if (e_user_dir_snprintf(buf, sizeof(buf), "config/%s", e_config_profile_get()) >= sizeof(buf)) + return 0; if (ecore_file_is_dir(buf)) ecore_file_recursive_rm(buf); } // load profile as e_config @@ -41,30 +39,26 @@ EAPI int wizard_page_apply(E_Wizard_Page *pg) { char buf[PATH_MAX]; - const char *homedir; - // setup ~/Desktop and ~/.e/e/fileman/favorites and // ~/.e/e/applications/bar/default, maybe ~/.e/e/applications/startup/.order - homedir = e_user_homedir_get(); - // FIXME: should become a wizard page on its own // setup fileman favorites snprintf(buf, sizeof(buf), "gzip -d -c < %s/data/other/efm_favorites.tar.gz | " "(cd %s/.e/e/ ; tar -xkf -)", - e_prefix_data_get(), homedir); + e_prefix_data_get(), e_user_homedir_get()); system(buf); // FIXME: efm favorites linked to desktop should be an option in another // wizard page // ~/Desktop - snprintf(buf, sizeof(buf), "%s/Desktop", homedir); + e_user_homedir_concat_static(buf, "Desktop"); ecore_file_mkpath(buf); - snprintf(buf, sizeof(buf), "%s/Desktop/home.desktop", homedir); + e_user_homedir_concat_static(buf, "Desktop/home.desktop"); ecore_file_symlink("../.e/e/fileman/favorites/home.desktop", buf); - snprintf(buf, sizeof(buf), "%s/Desktop/root.desktop", homedir); + e_user_homedir_concat_static(buf, "Desktop/root.desktop"); ecore_file_symlink("../.e/e/fileman/favorites/root.desktop", buf); - snprintf(buf, sizeof(buf), "%s/Desktop/tmp.desktop", homedir); + e_user_homedir_concat_static(buf, "Desktop/tmp.desktop"); ecore_file_symlink("../.e/e/fileman/favorites/tmp.desktop", buf); // save the config now everyone has modified it