summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2010-12-06 22:26:31 +0000
committerThomas Martitz <kugel@rockbox.org>2010-12-06 22:26:31 +0000
commit2c2416094f426972c9e2e96d25058311bbe82f97 (patch)
tree449b4e12e01c3c5c4afa2ae6a8cd396df82b5a38
parentc35b43b0f54bd607d38908544446caaa02f148a3 (diff)
downloadrockbox-2c2416094f426972c9e2e96d25058311bbe82f97.tar.gz
rockbox-2c2416094f426972c9e2e96d25058311bbe82f97.zip
Get rid of get_user_file_path and do the path handling in wrappers for open() and friends.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28752 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/filetypes.c8
-rw-r--r--apps/gui/icon.c7
-rw-r--r--apps/gui/skin_engine/skin_backdrops.c14
-rw-r--r--apps/gui/skin_engine/skin_engine.c6
-rw-r--r--apps/gui/skin_engine/skin_fonts.c4
-rw-r--r--apps/gui/skin_engine/skin_parser.c3
-rw-r--r--apps/main.c4
-rw-r--r--apps/menus/theme_menu.c4
-rw-r--r--apps/playlist.c10
-rw-r--r--apps/playlist_catalog.c8
-rw-r--r--apps/plugin.c6
-rw-r--r--apps/settings.c36
-rw-r--r--apps/tagcache.c145
-rw-r--r--apps/tree.c3
-rw-r--r--firmware/common/dircache.c11
-rw-r--r--firmware/common/rbpaths.c166
-rw-r--r--firmware/export/rbpaths.h35
-rw-r--r--firmware/font.c10
-rw-r--r--firmware/include/dir.h7
-rw-r--r--firmware/include/dir_uncached.h33
-rw-r--r--firmware/include/file.h46
-rw-r--r--firmware/load_code.c6
-rw-r--r--firmware/target/hosted/android/dir-target.h21
-rw-r--r--firmware/target/hosted/android/fs-android.c1
-rw-r--r--uisimulator/common/io.c1
25 files changed, 309 insertions, 286 deletions
diff --git a/apps/filetypes.c b/apps/filetypes.c
index f23026ea69..481c0df6de 100644
--- a/apps/filetypes.c
+++ b/apps/filetypes.c
@@ -219,15 +219,14 @@ static void read_config(const char* config_file);
219 * load a colors file from a theme with: 219 * load a colors file from a theme with:
220 * filetype colours: filename.colours */ 220 * filetype colours: filename.colours */
221void read_color_theme_file(void) { 221void read_color_theme_file(void) {
222 char buffer[MAX_PATH], dir[MAX_PATH]; 222 char buffer[MAX_PATH];
223 int fd; 223 int fd;
224 char *ext, *color; 224 char *ext, *color;
225 int i; 225 int i;
226 for (i = 0; i < MAX_FILETYPES+1; i++) { 226 for (i = 0; i < MAX_FILETYPES+1; i++) {
227 custom_colors[i] = -1; 227 custom_colors[i] = -1;
228 } 228 }
229 snprintf(buffer, MAX_PATH, "%s/%s.colours", 229 snprintf(buffer, MAX_PATH, THEME_DIR "/%s.colours",
230 get_user_file_path(THEME_DIR, 0, dir, sizeof(dir)),
231 global_settings.colors_file); 230 global_settings.colors_file);
232 fd = open(buffer, O_RDONLY); 231 fd = open(buffer, O_RDONLY);
233 if (fd < 0) 232 if (fd < 0)
@@ -300,7 +299,6 @@ void read_viewer_theme_file(void)
300 299
301void filetype_init(void) 300void filetype_init(void)
302{ 301{
303 char path[MAX_PATH];
304 /* set the directory item first */ 302 /* set the directory item first */
305 filetypes[0].extension = NULL; 303 filetypes[0].extension = NULL;
306 filetypes[0].plugin = NULL; 304 filetypes[0].plugin = NULL;
@@ -310,7 +308,7 @@ void filetype_init(void)
310 viewer_count = 0; 308 viewer_count = 0;
311 filetype_count = 1; 309 filetype_count = 1;
312 read_builtin_types(); 310 read_builtin_types();
313 read_config(get_user_file_path(VIEWERS_CONFIG, IS_FILE, path, sizeof(path))); 311 read_config(VIEWERS_CONFIG);
314#ifdef HAVE_LCD_BITMAP 312#ifdef HAVE_LCD_BITMAP
315 read_viewer_theme_file(); 313 read_viewer_theme_file();
316#endif 314#endif
diff --git a/apps/gui/icon.c b/apps/gui/icon.c
index c4581e031f..628196a98f 100644
--- a/apps/gui/icon.c
+++ b/apps/gui/icon.c
@@ -228,12 +228,9 @@ static void load_icons(const char* filename, enum Iconset iconset)
228 if (filename[0] && filename[0] != '-') 228 if (filename[0] && filename[0] != '-')
229 { 229 {
230 char path[MAX_PATH]; 230 char path[MAX_PATH];
231 char temp[MAX_PATH];
232 const char * fname;
233 231
234 snprintf(path, sizeof(path), "%s/%s.bmp", ICON_DIR, filename); 232 snprintf(path, sizeof(path), ICON_DIR "/%s.bmp", filename);
235 fname = get_user_file_path(path, IS_FILE, temp, sizeof(temp)); 233 size_read = read_bmp_file(path, bmp, IMG_BUFSIZE, bmpformat, NULL);
236 size_read = read_bmp_file(fname, bmp, IMG_BUFSIZE, bmpformat, NULL);
237 if (size_read > 0) 234 if (size_read > 0)
238 { 235 {
239 *loaded_ok = true; 236 *loaded_ok = true;
diff --git a/apps/gui/skin_engine/skin_backdrops.c b/apps/gui/skin_engine/skin_backdrops.c
index e337774994..3e04beaae0 100644
--- a/apps/gui/skin_engine/skin_backdrops.c
+++ b/apps/gui/skin_engine/skin_backdrops.c
@@ -54,7 +54,6 @@ void skin_backdrop_init(void)
54int skin_backdrop_assign(char* backdrop, char *bmpdir, 54int skin_backdrop_assign(char* backdrop, char *bmpdir,
55 enum screen_type screen) 55 enum screen_type screen)
56{ 56{
57 char dir[MAX_PATH];
58 char filename[MAX_PATH]; 57 char filename[MAX_PATH];
59 int i, free = -1; 58 int i, free = -1;
60 if (!backdrop) 59 if (!backdrop)
@@ -68,8 +67,7 @@ int skin_backdrop_assign(char* backdrop, char *bmpdir,
68 } 67 }
69 else 68 else
70 { 69 {
71 const char *bd_dir = get_user_file_path(bmpdir, 0, dir, sizeof(dir)); 70 get_image_filename(backdrop, bmpdir, filename, sizeof(filename));
72 get_image_filename(backdrop, bd_dir, filename, sizeof(filename));
73 } 71 }
74 for (i=0; i<NB_BDROPS; i++) 72 for (i=0; i<NB_BDROPS; i++)
75 { 73 {
@@ -115,12 +113,9 @@ bool skin_backdrops_preload(void)
115 if (screen == SCREEN_MAIN && global_settings.backdrop_file[0] && 113 if (screen == SCREEN_MAIN && global_settings.backdrop_file[0] &&
116 global_settings.backdrop_file[0] != '-' && filename[0] == '-') 114 global_settings.backdrop_file[0] != '-' && filename[0] == '-')
117 { 115 {
118 char dir[MAX_PATH];
119 char* temp = filename+2; /* slightly hacky to get a buffer */ 116 char* temp = filename+2; /* slightly hacky to get a buffer */
120 size_t size = sizeof(backdrops[i].name) - 2; 117 size_t size = sizeof(backdrops[i].name) - 2;
121 snprintf(temp, size, "%s/%s.bmp", 118 snprintf(temp, size, BACKDROP_DIR "/%s.bmp", global_settings.backdrop_file);
122 get_user_file_path(BACKDROP_DIR, 0, dir, sizeof(dir)),
123 global_settings.backdrop_file);
124 filename = temp; 119 filename = temp;
125 } 120 }
126 if (*filename && *filename != '-') 121 if (*filename && *filename != '-')
@@ -161,7 +156,7 @@ void skin_backdrop_unload(int backdrop_id)
161void skin_backdrop_load_setting(void) 156void skin_backdrop_load_setting(void)
162{ 157{
163 int i; 158 int i;
164 char filename[MAX_PATH], dir[MAX_PATH]; 159 char filename[MAX_PATH];
165 for(i=0;i<SKINNABLE_SCREENS_COUNT*NB_SCREENS;i++) 160 for(i=0;i<SKINNABLE_SCREENS_COUNT*NB_SCREENS;i++)
166 { 161 {
167 if (backdrops[i].name[0] == '-' && backdrops[i].screen == SCREEN_MAIN) 162 if (backdrops[i].name[0] == '-' && backdrops[i].screen == SCREEN_MAIN)
@@ -171,8 +166,7 @@ void skin_backdrop_load_setting(void)
171 { 166 {
172 if (!backdrops[i].buffer) 167 if (!backdrops[i].buffer)
173 backdrops[i].buffer = (char*)skin_buffer_alloc(LCD_BACKDROP_BYTES); 168 backdrops[i].buffer = (char*)skin_buffer_alloc(LCD_BACKDROP_BYTES);
174 snprintf(filename, sizeof filename, "%s/%s.bmp", 169 snprintf(filename, sizeof filename, BACKDROP_DIR "/%s.bmp",
175 get_user_file_path(BACKDROP_DIR, 0, dir, sizeof(dir)),
176 global_settings.backdrop_file); 170 global_settings.backdrop_file);
177 bool loaded = backdrops[i].buffer && 171 bool loaded = backdrops[i].buffer &&
178 screens[SCREEN_MAIN].backdrop_load(filename, 172 screens[SCREEN_MAIN].backdrop_load(filename,
diff --git a/apps/gui/skin_engine/skin_engine.c b/apps/gui/skin_engine/skin_engine.c
index 25baeb2c3c..fbedbb96fd 100644
--- a/apps/gui/skin_engine/skin_engine.c
+++ b/apps/gui/skin_engine/skin_engine.c
@@ -155,7 +155,7 @@ struct gui_wps *skin_get_gwps(enum skinnable_screens skin, enum screen_type scre
155{ 155{
156 if (!loading_a_sbs && skins[skin][screen].data.wps_loaded == false) 156 if (!loading_a_sbs && skins[skin][screen].data.wps_loaded == false)
157 { 157 {
158 char buf[MAX_PATH*2], path[MAX_PATH]; 158 char buf[MAX_PATH*2];
159 char *setting = NULL, *ext = NULL; 159 char *setting = NULL, *ext = NULL;
160 switch (skin) 160 switch (skin)
161 { 161 {
@@ -226,9 +226,7 @@ struct gui_wps *skin_get_gwps(enum skinnable_screens skin, enum screen_type scre
226 buf[0] = '\0'; /* force it to reload the default */ 226 buf[0] = '\0'; /* force it to reload the default */
227 if (strcmp(setting, "rockbox_failsafe")) 227 if (strcmp(setting, "rockbox_failsafe"))
228 { 228 {
229 snprintf(buf, sizeof buf, "%s/%s.%s", 229 snprintf(buf, sizeof buf, WPS_DIR "/%s.%s", setting, ext);
230 get_user_file_path(WPS_DIR, false, path, sizeof(path)),
231 setting, ext);
232 } 230 }
233 cpu_boost(true); 231 cpu_boost(true);
234 skin_load(skin, screen, buf, true); 232 skin_load(skin, screen, buf, true);
diff --git a/apps/gui/skin_engine/skin_fonts.c b/apps/gui/skin_engine/skin_fonts.c
index e5081e8cd9..23255aa8cc 100644
--- a/apps/gui/skin_engine/skin_fonts.c
+++ b/apps/gui/skin_engine/skin_fonts.c
@@ -64,7 +64,6 @@ int skin_font_load(char* font_name, int glyphs)
64 struct font *pf; 64 struct font *pf;
65 struct skin_font_info *font = NULL; 65 struct skin_font_info *font = NULL;
66 char filename[MAX_PATH]; 66 char filename[MAX_PATH];
67 char tmp[MAX_PATH];
68 67
69 if (!strcmp(font_name, global_settings.font_file)) 68 if (!strcmp(font_name, global_settings.font_file))
70 return FONT_UI; 69 return FONT_UI;
@@ -72,8 +71,7 @@ int skin_font_load(char* font_name, int glyphs)
72 if (!strcmp(font_name, global_settings.remote_font_file)) 71 if (!strcmp(font_name, global_settings.remote_font_file))
73 return FONT_UI_REMOTE; 72 return FONT_UI_REMOTE;
74#endif 73#endif
75 snprintf(tmp, MAX_PATH, FONT_DIR "/%s.fnt", font_name); 74 snprintf(filename, MAX_PATH, FONT_DIR "/%s.fnt", font_name);
76 get_user_file_path(tmp, FORCE_BUFFER_COPY, filename, sizeof(filename));
77 75
78 for(i=0;i<MAXUSERFONTS;i++) 76 for(i=0;i<MAXUSERFONTS;i++)
79 { 77 {
diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c
index 4da13842e4..f292ff3946 100644
--- a/apps/gui/skin_engine/skin_parser.c
+++ b/apps/gui/skin_engine/skin_parser.c
@@ -1646,8 +1646,7 @@ bool skin_data_load(enum screen_type screen, struct wps_data *wps_data,
1646 strlcpy(bmpdir, buf, dot - buf + 1); 1646 strlcpy(bmpdir, buf, dot - buf + 1);
1647 } 1647 }
1648 else 1648 else
1649 { /* fall back to backdrop dir for built-in themes */ 1649 {
1650 /* no get_user_file_path(), assuming we ship bmps for built-in themes */
1651 snprintf(bmpdir, MAX_PATH, "%s", BACKDROP_DIR); 1650 snprintf(bmpdir, MAX_PATH, "%s", BACKDROP_DIR);
1652 } 1651 }
1653 /* load the bitmaps that were found by the parsing */ 1652 /* load the bitmaps that were found by the parsing */
diff --git a/apps/main.c b/apps/main.c
index 950168d8ed..7af4cca37e 100644
--- a/apps/main.c
+++ b/apps/main.c
@@ -172,13 +172,13 @@ int main(void)
172#ifdef AUTOROCK 172#ifdef AUTOROCK
173 { 173 {
174 char filename[MAX_PATH]; 174 char filename[MAX_PATH];
175 const char *file = get_user_file_path( 175 const char *file =
176#ifdef APPLICATION 176#ifdef APPLICATION
177 ROCKBOX_DIR 177 ROCKBOX_DIR
178#else 178#else
179 PLUGIN_APPS_DIR 179 PLUGIN_APPS_DIR
180#endif 180#endif
181 "/autostart.rock", NEED_WRITE|IS_FILE, filename, sizeof(filename)); 181 "/autostart.rock";
182 if(file_exists(file)) /* no complaint if it doesn't exist */ 182 if(file_exists(file)) /* no complaint if it doesn't exist */
183 { 183 {
184 plugin_load(file, NULL); /* start if it does */ 184 plugin_load(file, NULL); /* start if it does */
diff --git a/apps/menus/theme_menu.c b/apps/menus/theme_menu.c
index 66274e2e18..983eca9445 100644
--- a/apps/menus/theme_menu.c
+++ b/apps/menus/theme_menu.c
@@ -246,11 +246,9 @@ static struct browse_folder_info themes = {THEME_DIR, SHOW_CFG};
246 246
247int browse_folder(void *param) 247int browse_folder(void *param)
248{ 248{
249 char path[MAX_PATH];
250 const struct browse_folder_info *info = 249 const struct browse_folder_info *info =
251 (const struct browse_folder_info*)param; 250 (const struct browse_folder_info*)param;
252 return rockbox_browse(get_user_file_path(info->dir, 0, path, sizeof(path)), 251 return rockbox_browse(info->dir, info->show_options);
253 info->show_options);
254} 252}
255 253
256#ifdef HAVE_LCD_BITMAP 254#ifdef HAVE_LCD_BITMAP
diff --git a/apps/playlist.c b/apps/playlist.c
index f56603749a..41d6ae5ed7 100644
--- a/apps/playlist.c
+++ b/apps/playlist.c
@@ -1439,12 +1439,7 @@ static int get_next_dir(char *dir, bool is_forward, bool recursion)
1439 /* process random folder advance */ 1439 /* process random folder advance */
1440 if (global_settings.next_folder == FOLDER_ADVANCE_RANDOM) 1440 if (global_settings.next_folder == FOLDER_ADVANCE_RANDOM)
1441 { 1441 {
1442 char folder_advance_list[MAX_PATH]; 1442 int fd = open(ROCKBOX_DIR "/folder_advance_list.dat", O_RDONLY);
1443 get_user_file_path(ROCKBOX_DIR, FORCE_BUFFER_COPY,
1444 folder_advance_list, sizeof(folder_advance_list));
1445 strlcat(folder_advance_list, "/folder_advance_list.dat",
1446 sizeof(folder_advance_list));
1447 int fd = open(folder_advance_list, O_RDONLY);
1448 if (fd >= 0) 1443 if (fd >= 0)
1449 { 1444 {
1450 char buffer[MAX_PATH]; 1445 char buffer[MAX_PATH];
@@ -1914,8 +1909,7 @@ void playlist_init(void)
1914 struct playlist_info* playlist = &current_playlist; 1909 struct playlist_info* playlist = &current_playlist;
1915 1910
1916 playlist->current = true; 1911 playlist->current = true;
1917 get_user_file_path(PLAYLIST_CONTROL_FILE, IS_FILE|NEED_WRITE|FORCE_BUFFER_COPY, 1912 strlcpy(playlist->control_filename, PLAYLIST_CONTROL_FILE,
1918 playlist->control_filename,
1919 sizeof(playlist->control_filename)); 1913 sizeof(playlist->control_filename));
1920 playlist->fd = -1; 1914 playlist->fd = -1;
1921 playlist->control_fd = -1; 1915 playlist->control_fd = -1;
diff --git a/apps/playlist_catalog.c b/apps/playlist_catalog.c
index 5f9f46728a..ff69b28263 100644
--- a/apps/playlist_catalog.c
+++ b/apps/playlist_catalog.c
@@ -81,11 +81,9 @@ static int initialize_catalog(void)
81 /* fall back to default directory if no or invalid config */ 81 /* fall back to default directory if no or invalid config */
82 if (default_dir) 82 if (default_dir)
83 { 83 {
84 const char *dir = get_user_file_path(PLAYLIST_CATALOG_DEFAULT_DIR, 84 strcpy(playlist_dir, PLAYLIST_CATALOG_DEFAULT_DIR);
85 FORCE_BUFFER_COPY|NEED_WRITE, 85 if (!dir_exists(playlist_dir))
86 playlist_dir, sizeof(playlist_dir)); 86 mkdir(playlist_dir);
87 if (!dir_exists(dir))
88 mkdir(dir);
89 } 87 }
90 88
91 playlist_dir_length = strlen(playlist_dir); 89 playlist_dir_length = strlen(playlist_dir);
diff --git a/apps/plugin.c b/apps/plugin.c
index 316c7c6b5d..f28593ec4e 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -314,11 +314,11 @@ static const struct plugin_api rockbox_api = {
314#ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE 314#ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE
315 (creat_func)creat_wrapper, 315 (creat_func)creat_wrapper,
316#else 316#else
317 (creat_func)PREFIX(creat), 317 (creat_func)creat,
318#endif 318#endif
319 (write_func)PREFIX(write), 319 (write_func)PREFIX(write),
320 PREFIX(remove), 320 remove,
321 PREFIX(rename), 321 rename,
322 PREFIX(ftruncate), 322 PREFIX(ftruncate),
323 PREFIX(filesize), 323 PREFIX(filesize),
324 fdprintf, 324 fdprintf,
diff --git a/apps/settings.c b/apps/settings.c
index 85b0489c09..848c7c14f2 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -118,9 +118,7 @@ static bool read_nvram_data(char* buf, int max_len)
118 unsigned crc32 = 0xffffffff; 118 unsigned crc32 = 0xffffffff;
119 int var_count = 0, i = 0, buf_pos = 0; 119 int var_count = 0, i = 0, buf_pos = 0;
120#ifndef HAVE_RTC_RAM 120#ifndef HAVE_RTC_RAM
121 char path[MAX_PATH]; 121 int fd = open(NVRAM_FILE, O_RDONLY);
122 int fd = open(get_user_file_path(NVRAM_FILE, IS_FILE|NEED_WRITE,
123 path, sizeof(path)), O_RDONLY);
124 int bytes; 122 int bytes;
125 if (fd < 0) 123 if (fd < 0)
126 return false; 124 return false;
@@ -174,7 +172,6 @@ static bool write_nvram_data(char* buf, int max_len)
174 char var_count = 0; 172 char var_count = 0;
175#ifndef HAVE_RTC_RAM 173#ifndef HAVE_RTC_RAM
176 int fd; 174 int fd;
177 char path[MAX_PATH];
178#endif 175#endif
179 memset(buf,0,max_len); 176 memset(buf,0,max_len);
180 /* magic, version */ 177 /* magic, version */
@@ -198,8 +195,7 @@ static bool write_nvram_data(char* buf, int max_len)
198 max_len-NVRAM_DATA_START-1,0xffffffff); 195 max_len-NVRAM_DATA_START-1,0xffffffff);
199 memcpy(&buf[4],&crc32,4); 196 memcpy(&buf[4],&crc32,4);
200#ifndef HAVE_RTC_RAM 197#ifndef HAVE_RTC_RAM
201 fd = open(get_user_file_path(NVRAM_FILE, IS_FILE|NEED_WRITE, 198 fd = open(NVRAM_FILE,O_CREAT|O_TRUNC|O_WRONLY, 0666);
202 path, sizeof(path)),O_CREAT|O_TRUNC|O_WRONLY, 0666);
203 if (fd >= 0) 199 if (fd >= 0)
204 { 200 {
205 int len = write(fd,buf,max_len); 201 int len = write(fd,buf,max_len);
@@ -230,12 +226,8 @@ void settings_load(int which)
230 read_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE); 226 read_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE);
231 if (which&SETTINGS_HD) 227 if (which&SETTINGS_HD)
232 { 228 {
233 const char *file; 229 settings_load_config(CONFIGFILE, false);
234 char path[MAX_PATH]; 230 settings_load_config(FIXEDSETTINGSFILE, false);
235 file = get_user_file_path(CONFIGFILE, IS_FILE|NEED_WRITE, path, sizeof(path));
236 settings_load_config(file, false);
237 file = get_user_file_path(FIXEDSETTINGSFILE, IS_FILE, path, sizeof(path));
238 settings_load_config(file, false);
239 } 231 }
240} 232}
241 233
@@ -596,11 +588,8 @@ static void flush_global_status_callback(void *data)
596static void flush_config_block_callback(void *data) 588static void flush_config_block_callback(void *data)
597{ 589{
598 (void)data; 590 (void)data;
599 char path[MAX_PATH];
600 write_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE); 591 write_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE);
601 settings_write_config( 592 settings_write_config(CONFIGFILE, SETTINGS_SAVE_CHANGED);
602 get_user_file_path(CONFIGFILE, IS_FILE|NEED_WRITE, path, sizeof(path)),
603 SETTINGS_SAVE_CHANGED);
604} 593}
605 594
606/* 595/*
@@ -644,7 +633,7 @@ int settings_save(void)
644 633
645bool settings_save_config(int options) 634bool settings_save_config(int options)
646{ 635{
647 char filename[MAX_PATH], path[MAX_PATH]; 636 char filename[MAX_PATH];
648 const char *folder, *namebase; 637 const char *folder, *namebase;
649 switch (options) 638 switch (options)
650 { 639 {
@@ -673,8 +662,6 @@ bool settings_save_config(int options)
673 namebase = "config"; 662 namebase = "config";
674 break; 663 break;
675 } 664 }
676
677 folder = get_user_file_path(folder, NEED_WRITE, path, sizeof(path));
678 create_numbered_filename(filename, folder, namebase, ".cfg", 2 665 create_numbered_filename(filename, folder, namebase, ".cfg", 2
679 IF_CNFN_NUM_(, NULL)); 666 IF_CNFN_NUM_(, NULL));
680 667
@@ -884,13 +871,11 @@ void settings_apply(bool read_disk)
884 { 871 {
885 char buf[MAX_PATH]; 872 char buf[MAX_PATH];
886#ifdef HAVE_LCD_BITMAP 873#ifdef HAVE_LCD_BITMAP
887 char dir[MAX_PATH];
888 const char *font_path = get_user_file_path(FONT_DIR, 0, dir, sizeof(dir));
889 /* fonts need to be loaded before the WPS */ 874 /* fonts need to be loaded before the WPS */
890 if (global_settings.font_file[0] 875 if (global_settings.font_file[0]
891 && global_settings.font_file[0] != '-') { 876 && global_settings.font_file[0] != '-') {
892 877
893 snprintf(buf, sizeof buf, "%s/%s.fnt", font_path, 878 snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt",
894 global_settings.font_file); 879 global_settings.font_file);
895 CHART2(">font_load ", global_settings.font_file); 880 CHART2(">font_load ", global_settings.font_file);
896 rc = font_load(NULL, buf); 881 rc = font_load(NULL, buf);
@@ -903,7 +888,7 @@ void settings_apply(bool read_disk)
903#ifdef HAVE_REMOTE_LCD 888#ifdef HAVE_REMOTE_LCD
904 if ( global_settings.remote_font_file[0] 889 if ( global_settings.remote_font_file[0]
905 && global_settings.remote_font_file[0] != '-') { 890 && global_settings.remote_font_file[0] != '-') {
906 snprintf(buf, sizeof buf, "%s/%s.fnt", font_path, 891 snprintf(buf, sizeof buf, FONT_DIR "%s.fnt",
907 global_settings.remote_font_file); 892 global_settings.remote_font_file);
908 CHART2(">font_load_remoteui ", global_settings.remote_font_file); 893 CHART2(">font_load_remoteui ", global_settings.remote_font_file);
909 rc = font_load_remoteui(buf); 894 rc = font_load_remoteui(buf);
@@ -915,8 +900,7 @@ void settings_apply(bool read_disk)
915 font_load_remoteui(NULL); 900 font_load_remoteui(NULL);
916#endif 901#endif
917 if ( global_settings.kbd_file[0]) { 902 if ( global_settings.kbd_file[0]) {
918 snprintf(buf, sizeof buf, "%s/%s.kbd", 903 snprintf(buf, sizeof buf, ROCKBOX_DIR "/%s.kbd",
919 get_user_file_path(ROCKBOX_DIR, 0, dir, sizeof(dir)),
920 global_settings.kbd_file); 904 global_settings.kbd_file);
921 CHART(">load_kbd"); 905 CHART(">load_kbd");
922 load_kbd(buf); 906 load_kbd(buf);
@@ -925,8 +909,6 @@ void settings_apply(bool read_disk)
925 else 909 else
926 load_kbd(NULL); 910 load_kbd(NULL);
927#endif /* HAVE_LCD_BITMAP */ 911#endif /* HAVE_LCD_BITMAP */
928 /* no get_user_file_path() here because we don't really support
929 * langs that don't come with rockbox */
930 if ( global_settings.lang_file[0]) { 912 if ( global_settings.lang_file[0]) {
931 snprintf(buf, sizeof buf, LANG_DIR "/%s.lng", 913 snprintf(buf, sizeof buf, LANG_DIR "/%s.lng",
932 global_settings.lang_file); 914 global_settings.lang_file);
diff --git a/apps/tagcache.c b/apps/tagcache.c
index 679d7cbe79..5b175c4b20 100644
--- a/apps/tagcache.c
+++ b/apps/tagcache.c
@@ -73,9 +73,9 @@
73#include "buffer.h" 73#include "buffer.h"
74#include "crc32.h" 74#include "crc32.h"
75#include "misc.h" 75#include "misc.h"
76#include "filefuncs.h"
77#include "settings.h" 76#include "settings.h"
78#include "dir.h" 77#include "dir.h"
78#include "filefuncs.h"
79#include "structec.h" 79#include "structec.h"
80 80
81#ifndef __PCTOOL__ 81#ifndef __PCTOOL__
@@ -293,17 +293,15 @@ static bool is_dircache_intact(void)
293static int open_tag_fd(struct tagcache_header *hdr, int tag, bool write) 293static int open_tag_fd(struct tagcache_header *hdr, int tag, bool write)
294{ 294{
295 int fd; 295 int fd;
296 char buf[MAX_PATH], path[MAX_PATH]; 296 char buf[MAX_PATH];
297 const char * file;
298 int rc; 297 int rc;
299 298
300 if (TAGCACHE_IS_NUMERIC(tag) || tag < 0 || tag >= TAG_COUNT) 299 if (TAGCACHE_IS_NUMERIC(tag) || tag < 0 || tag >= TAG_COUNT)
301 return -1; 300 return -1;
302 301
303 snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, tag); 302 snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, tag);
304 file = get_user_file_path(buf, IS_FILE | NEED_WRITE, path, sizeof(path));
305 303
306 fd = open(file, write ? O_RDWR : O_RDONLY); 304 fd = open(buf, write ? O_RDWR : O_RDONLY);
307 if (fd < 0) 305 if (fd < 0)
308 { 306 {
309 logf("tag file open failed: tag=%d write=%d file=%s", tag, write, buf); 307 logf("tag file open failed: tag=%d write=%d file=%s", tag, write, buf);
@@ -328,12 +326,8 @@ static int open_master_fd(struct master_header *hdr, bool write)
328{ 326{
329 int fd; 327 int fd;
330 int rc; 328 int rc;
331 char path[MAX_PATH];
332 329
333 fd = open(get_user_file_path(TAGCACHE_FILE_MASTER, 330 fd = open(TAGCACHE_FILE_MASTER, write ? O_RDWR : O_RDONLY);
334 IS_FILE|NEED_WRITE,
335 path, sizeof(path)),
336 write ? O_RDWR : O_RDONLY);
337 if (fd < 0) 331 if (fd < 0)
338 { 332 {
339 logf("master file open failed for R/W"); 333 logf("master file open failed for R/W");
@@ -675,12 +669,10 @@ static bool open_files(struct tagcache_search *tcs, int tag)
675{ 669{
676 if (tcs->idxfd[tag] < 0) 670 if (tcs->idxfd[tag] < 0)
677 { 671 {
678 char fn[MAX_PATH], path[MAX_PATH]; 672 char fn[MAX_PATH];
679 const char *file;
680 673
681 snprintf(fn, sizeof fn, TAGCACHE_FILE_INDEX, tag); 674 snprintf(fn, sizeof fn, TAGCACHE_FILE_INDEX, tag);
682 file = get_user_file_path(fn, IS_FILE | NEED_WRITE, path, sizeof(path)); 675 tcs->idxfd[tag] = open(fn, O_RDONLY);
683 tcs->idxfd[tag] = open(file, O_RDONLY);
684 } 676 }
685 677
686 if (tcs->idxfd[tag] < 0) 678 if (tcs->idxfd[tag] < 0)
@@ -1218,17 +1210,14 @@ static void remove_files(void)
1218 tc_stat.ready = false; 1210 tc_stat.ready = false;
1219 tc_stat.ramcache = false; 1211 tc_stat.ramcache = false;
1220 tc_stat.econ = false; 1212 tc_stat.econ = false;
1221 remove(get_user_file_path(TAGCACHE_FILE_MASTER, NEED_WRITE|IS_FILE, 1213 remove(TAGCACHE_FILE_MASTER);
1222 buf, sizeof(buf)));
1223 for (i = 0; i < TAG_COUNT; i++) 1214 for (i = 0; i < TAG_COUNT; i++)
1224 { 1215 {
1225 char buf2[MAX_PATH];
1226 if (TAGCACHE_IS_NUMERIC(i)) 1216 if (TAGCACHE_IS_NUMERIC(i))
1227 continue; 1217 continue;
1228 1218
1229 /* database_%d.tcd -> database_0.tcd */
1230 snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, i); 1219 snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, i);
1231 remove(get_user_file_path(buf, NEED_WRITE | IS_FILE, buf2, sizeof(buf2))); 1220 remove(buf);
1232 } 1221 }
1233} 1222}
1234 1223
@@ -1379,11 +1368,10 @@ bool tagcache_search_add_clause(struct tagcache_search *tcs,
1379 1368
1380 if (!TAGCACHE_IS_NUMERIC(clause->tag) && tcs->idxfd[clause->tag] < 0) 1369 if (!TAGCACHE_IS_NUMERIC(clause->tag) && tcs->idxfd[clause->tag] < 0)
1381 { 1370 {
1382 char buf[MAX_PATH], path[MAX_PATH]; 1371 char buf[MAX_PATH];
1383 const char *file; 1372
1384 snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, clause->tag); 1373 snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, clause->tag);
1385 file = get_user_file_path(buf, IS_FILE | NEED_WRITE, path, sizeof(path)); 1374 tcs->idxfd[clause->tag] = open(buf, O_RDONLY);
1386 tcs->idxfd[clause->tag] = open(file, O_RDONLY);
1387 } 1375 }
1388 1376
1389 tcs->clause[tcs->clause_count] = clause; 1377 tcs->clause[tcs->clause_count] = clause;
@@ -2407,8 +2395,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd)
2407 struct master_header tcmh; 2395 struct master_header tcmh;
2408 struct index_entry idxbuf[IDX_BUF_DEPTH]; 2396 struct index_entry idxbuf[IDX_BUF_DEPTH];
2409 int idxbuf_pos; 2397 int idxbuf_pos;
2410 char buf[TAG_MAXLEN+32], path[MAX_PATH]; 2398 char buf[TAG_MAXLEN+32];
2411 const char *file;
2412 int fd = -1, masterfd; 2399 int fd = -1, masterfd;
2413 bool error = false; 2400 bool error = false;
2414 int init; 2401 int init;
@@ -2556,8 +2543,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd)
2556 * anything whether the index type is sorted or not. 2543 * anything whether the index type is sorted or not.
2557 */ 2544 */
2558 snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, index_type); 2545 snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, index_type);
2559 file = get_user_file_path(buf, IS_FILE | NEED_WRITE, path, sizeof(path)); 2546 fd = open(buf, O_WRONLY | O_CREAT | O_TRUNC, 0666);
2560 fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
2561 if (fd < 0) 2547 if (fd < 0)
2562 { 2548 {
2563 logf("%s open fail", buf); 2549 logf("%s open fail", buf);
@@ -2577,21 +2563,18 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd)
2577 } 2563 }
2578 } 2564 }
2579 2565
2580 file = get_user_file_path(TAGCACHE_FILE_MASTER,
2581 IS_FILE|NEED_WRITE,
2582 buf, sizeof(buf));
2583 /* Loading the tag lookup file as "master file". */ 2566 /* Loading the tag lookup file as "master file". */
2584 logf("Loading index file"); 2567 logf("Loading index file");
2585 masterfd = open(file, O_RDWR); 2568 masterfd = open(TAGCACHE_FILE_MASTER, O_RDWR);
2586 2569
2587 if (masterfd < 0) 2570 if (masterfd < 0)
2588 { 2571 {
2589 logf("Creating new DB"); 2572 logf("Creating new DB");
2590 masterfd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); 2573 masterfd = open(TAGCACHE_FILE_MASTER, O_WRONLY | O_CREAT | O_TRUNC, 0666);
2591 2574
2592 if (masterfd < 0) 2575 if (masterfd < 0)
2593 { 2576 {
2594 logf("Failure to create index file (%s)", file); 2577 logf("Failure to create index file (%s)", TAGCACHE_FILE_MASTER);
2595 close(fd); 2578 close(fd);
2596 return -2; 2579 return -2;
2597 } 2580 }
@@ -2899,8 +2882,6 @@ static bool commit(void)
2899{ 2882{
2900 struct tagcache_header tch; 2883 struct tagcache_header tch;
2901 struct master_header tcmh; 2884 struct master_header tcmh;
2902 char path[MAX_PATH];
2903 const char *file;
2904 int i, len, rc; 2885 int i, len, rc;
2905 int tmpfd; 2886 int tmpfd;
2906 int masterfd; 2887 int masterfd;
@@ -2914,10 +2895,7 @@ static bool commit(void)
2914 while (write_lock) 2895 while (write_lock)
2915 sleep(1); 2896 sleep(1);
2916 2897
2917 file = get_user_file_path(TAGCACHE_FILE_TEMP, 2898 tmpfd = open(TAGCACHE_FILE_TEMP, O_RDONLY);
2918 IS_FILE|NEED_WRITE, path, sizeof(path));
2919
2920 tmpfd = open(file, O_RDONLY);
2921 if (tmpfd < 0) 2899 if (tmpfd < 0)
2922 { 2900 {
2923 logf("nothing to commit"); 2901 logf("nothing to commit");
@@ -2933,7 +2911,7 @@ static bool commit(void)
2933 { 2911 {
2934 logf("incorrect tmpheader"); 2912 logf("incorrect tmpheader");
2935 close(tmpfd); 2913 close(tmpfd);
2936 remove(file); 2914 remove(TAGCACHE_FILE_TEMP);
2937 return false; 2915 return false;
2938 } 2916 }
2939 2917
@@ -2941,7 +2919,7 @@ static bool commit(void)
2941 { 2919 {
2942 logf("nothing to commit"); 2920 logf("nothing to commit");
2943 close(tmpfd); 2921 close(tmpfd);
2944 remove(file); 2922 remove(TAGCACHE_FILE_TEMP);
2945 return true; 2923 return true;
2946 } 2924 }
2947 2925
@@ -2949,8 +2927,7 @@ static bool commit(void)
2949 tc_stat.ready = check_all_headers(); 2927 tc_stat.ready = check_all_headers();
2950 2928
2951#ifdef HAVE_EEPROM_SETTINGS 2929#ifdef HAVE_EEPROM_SETTINGS
2952 remove(get_user_file_path(TAGCACHE_STATEFILE, IS_FILE | NEED_WRITE, 2930 remove(TAGCACHE_STATEFILE);
2953 path, sizeof(path)));
2954#endif 2931#endif
2955 2932
2956 /* At first be sure to unload the ramcache! */ 2933 /* At first be sure to unload the ramcache! */
@@ -3040,7 +3017,7 @@ static bool commit(void)
3040 } 3017 }
3041 3018
3042 close(tmpfd); 3019 close(tmpfd);
3043 remove(file); 3020 remove(TAGCACHE_FILE_TEMP);
3044 3021
3045 tc_stat.commit_step = 0; 3022 tc_stat.commit_step = 0;
3046 3023
@@ -3458,18 +3435,15 @@ bool tagcache_import_changelog(void)
3458 struct tagcache_header tch; 3435 struct tagcache_header tch;
3459 int clfd; 3436 int clfd;
3460 long masterfd; 3437 long masterfd;
3461 char buf[MAX(MAX_PATH, 2048)]; 3438 char buf[2048];
3462 const char *file;
3463 3439
3464 if (!tc_stat.ready) 3440 if (!tc_stat.ready)
3465 return false; 3441 return false;
3466 3442
3467 while (read_lock) 3443 while (read_lock)
3468 sleep(1); 3444 sleep(1);
3469 3445
3470 file = get_user_file_path(TAGCACHE_FILE_CHANGELOG, 3446 clfd = open(TAGCACHE_FILE_CHANGELOG, O_RDONLY);
3471 IS_FILE|NEED_WRITE, buf, sizeof(buf));
3472 clfd = open(file, O_RDONLY);
3473 if (clfd < 0) 3447 if (clfd < 0)
3474 { 3448 {
3475 logf("failure to open changelog"); 3449 logf("failure to open changelog");
@@ -3511,8 +3485,7 @@ bool tagcache_create_changelog(struct tagcache_search *tcs)
3511{ 3485{
3512 struct master_header myhdr; 3486 struct master_header myhdr;
3513 struct index_entry idx; 3487 struct index_entry idx;
3514 const char *file; 3488 char buf[TAG_MAXLEN+32];
3515 char buf[MAX(TAG_MAXLEN+32, MAX_PATH)];
3516 char temp[32]; 3489 char temp[32];
3517 int clfd; 3490 int clfd;
3518 int i, j; 3491 int i, j;
@@ -3524,9 +3497,7 @@ bool tagcache_create_changelog(struct tagcache_search *tcs)
3524 return false; 3497 return false;
3525 3498
3526 /* Initialize the changelog */ 3499 /* Initialize the changelog */
3527 file = get_user_file_path(TAGCACHE_FILE_CHANGELOG, IS_FILE | NEED_WRITE, 3500 clfd = open(TAGCACHE_FILE_CHANGELOG, O_WRONLY | O_CREAT | O_TRUNC, 0666);
3528 buf, sizeof(buf));
3529 clfd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
3530 if (clfd < 0) 3501 if (clfd < 0)
3531 { 3502 {
3532 logf("failure to open changelog"); 3503 logf("failure to open changelog");
@@ -3844,15 +3815,11 @@ static bool allocate_tagcache(void)
3844static bool tagcache_dumpload(void) 3815static bool tagcache_dumpload(void)
3845{ 3816{
3846 struct statefile_header shdr; 3817 struct statefile_header shdr;
3847 char path[MAX_PATH];
3848 const char *file;
3849 int fd, rc; 3818 int fd, rc;
3850 long offpos; 3819 long offpos;
3851 int i; 3820 int i;
3852 3821
3853 file = get_user_file_path(TAGCACHE_STATEFILE, IS_FILE | NEED_WRITE, 3822 fd = open(TAGCACHE_STATEFILE, O_RDONLY);
3854 path, sizeof(path));
3855 fd = open(file, O_RDONLY);
3856 if (fd < 0) 3823 if (fd < 0)
3857 { 3824 {
3858 logf("no tagcache statedump"); 3825 logf("no tagcache statedump");
@@ -3898,16 +3865,12 @@ static bool tagcache_dumpload(void)
3898static bool tagcache_dumpsave(void) 3865static bool tagcache_dumpsave(void)
3899{ 3866{
3900 struct statefile_header shdr; 3867 struct statefile_header shdr;
3901 char path[MAX_PATH];
3902 const char *file;
3903 int fd; 3868 int fd;
3904 3869
3905 if (!tc_stat.ramcache) 3870 if (!tc_stat.ramcache)
3906 return false; 3871 return false;
3907 3872
3908 file = get_user_file_path(TAGCACHE_STATEFILE, IS_FILE | NEED_WRITE, 3873 fd = open(TAGCACHE_STATEFILE, O_WRONLY | O_CREAT | O_TRUNC, 0666);
3909 path, sizeof(path));
3910 fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
3911 if (fd < 0) 3874 if (fd < 0)
3912 { 3875 {
3913 logf("failed to create a statedump"); 3876 logf("failed to create a statedump");
@@ -3933,8 +3896,7 @@ static bool load_tagcache(void)
3933 long bytesleft = tc_stat.ramcache_allocated; 3896 long bytesleft = tc_stat.ramcache_allocated;
3934 struct index_entry *idx; 3897 struct index_entry *idx;
3935 int rc, fd; 3898 int rc, fd;
3936 char *p, path[MAX_PATH]; 3899 char *p;
3937 const char *file;
3938 int i, tag; 3900 int i, tag;
3939 3901
3940# ifdef HAVE_DIRCACHE 3902# ifdef HAVE_DIRCACHE
@@ -3945,11 +3907,8 @@ static bool load_tagcache(void)
3945# endif 3907# endif
3946 3908
3947 logf("loading tagcache to ram..."); 3909 logf("loading tagcache to ram...");
3948 3910
3949 file = get_user_file_path(TAGCACHE_FILE_MASTER, 3911 fd = open(TAGCACHE_FILE_MASTER, O_RDONLY);
3950 IS_FILE|NEED_WRITE,
3951 path, sizeof(path));
3952 fd = open(file, O_RDONLY);
3953 if (fd < 0) 3912 if (fd < 0)
3954 { 3913 {
3955 logf("tagcache open failed"); 3914 logf("tagcache open failed");
@@ -4159,14 +4118,12 @@ static bool load_tagcache(void)
4159static bool check_deleted_files(void) 4118static bool check_deleted_files(void)
4160{ 4119{
4161 int fd; 4120 int fd;
4162 char buf[TAG_MAXLEN+32], path[MAX_PATH]; 4121 char buf[TAG_MAXLEN+32];
4163 const char *file;
4164 struct tagfile_entry tfe; 4122 struct tagfile_entry tfe;
4165 4123
4166 logf("reverse scan..."); 4124 logf("reverse scan...");
4167 snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, tag_filename); 4125 snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, tag_filename);
4168 file = get_user_file_path(buf, IS_FILE | NEED_WRITE, path, sizeof(path)); 4126 fd = open(buf, O_RDONLY);
4169 fd = open(file, O_RDONLY);
4170 4127
4171 if (fd < 0) 4128 if (fd < 0)
4172 { 4129 {
@@ -4326,8 +4283,6 @@ void tagcache_build(const char *path)
4326{ 4283{
4327 struct tagcache_header header; 4284 struct tagcache_header header;
4328 bool ret; 4285 bool ret;
4329 char buf[MAX_PATH];
4330 const char *file;
4331 4286
4332 curpath[0] = '\0'; 4287 curpath[0] = '\0';
4333 data_size = 0; 4288 data_size = 0;
@@ -4340,21 +4295,19 @@ void tagcache_build(const char *path)
4340#endif 4295#endif
4341 4296
4342 logf("updating tagcache"); 4297 logf("updating tagcache");
4343
4344 file = get_user_file_path(TAGCACHE_FILE_TEMP,
4345 IS_FILE|NEED_WRITE, buf, sizeof(buf));
4346 4298
4347 4299 cachefd = open(TAGCACHE_FILE_TEMP, O_RDONLY);
4348 if (file_exists(file)) 4300 if (cachefd >= 0)
4349 { 4301 {
4350 logf("skipping, cache already waiting for commit"); 4302 logf("skipping, cache already waiting for commit");
4303 close(cachefd);
4351 return ; 4304 return ;
4352 } 4305 }
4353 4306
4354 cachefd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0666); 4307 cachefd = open(TAGCACHE_FILE_TEMP, O_RDWR | O_CREAT | O_TRUNC, 0666);
4355 if (cachefd < 0) 4308 if (cachefd < 0)
4356 { 4309 {
4357 logf("master file open failed: %s", file); 4310 logf("master file open failed: %s", TAGCACHE_FILE_TEMP);
4358 return ; 4311 return ;
4359 } 4312 }
4360 4313
@@ -4398,7 +4351,7 @@ void tagcache_build(const char *path)
4398#endif 4351#endif
4399 if (commit()) 4352 if (commit())
4400 { 4353 {
4401 remove(file); 4354 remove(TAGCACHE_FILE_TEMP);
4402 logf("tagcache built!"); 4355 logf("tagcache built!");
4403 } 4356 }
4404#ifdef __PCTOOL__ 4357#ifdef __PCTOOL__
@@ -4443,12 +4396,7 @@ void tagcache_unload_ramcache(void)
4443{ 4396{
4444 tc_stat.ramcache = false; 4397 tc_stat.ramcache = false;
4445 /* Just to make sure there is no statefile present. */ 4398 /* Just to make sure there is no statefile present. */
4446 4399 // remove(TAGCACHE_STATEFILE);
4447#if 0
4448 char path[MAX_PATH];
4449 remove(get_user_file_path(TAGCACHE_STATEFILE, IS_FILE | NEED_WRITE,
4450 path, sizeof(path)));
4451#endif
4452} 4400}
4453#endif 4401#endif
4454 4402
@@ -4457,7 +4405,6 @@ static void tagcache_thread(void)
4457{ 4405{
4458 struct queue_event ev; 4406 struct queue_event ev;
4459 bool check_done = false; 4407 bool check_done = false;
4460 char path[MAX_PATH];
4461 4408
4462 /* If the previous cache build/update was interrupted, commit 4409 /* If the previous cache build/update was interrupted, commit
4463 * the changes first in foreground. */ 4410 * the changes first in foreground. */
@@ -4474,8 +4421,7 @@ static void tagcache_thread(void)
4474 check_done = tagcache_dumpload(); 4421 check_done = tagcache_dumpload();
4475 } 4422 }
4476 4423
4477 remove(get_user_file_path(TAGCACHE_STATEFILE, IS_FILE | NEED_WRITE, 4424 remove(TAGCACHE_STATEFILE);
4478 path, sizeof(path)));
4479# endif 4425# endif
4480 4426
4481 /* Allocate space for the tagcache if found on disk. */ 4427 /* Allocate space for the tagcache if found on disk. */
@@ -4508,8 +4454,7 @@ static void tagcache_thread(void)
4508 4454
4509 case Q_REBUILD: 4455 case Q_REBUILD:
4510 remove_files(); 4456 remove_files();
4511 remove(get_user_file_path(TAGCACHE_FILE_TEMP, 4457 remove(TAGCACHE_FILE_TEMP);
4512 IS_FILE|NEED_WRITE, path, sizeof(path)));
4513 tagcache_build("/"); 4458 tagcache_build("/");
4514 break; 4459 break;
4515 4460
diff --git a/apps/tree.c b/apps/tree.c
index 86238c50d9..98880f001a 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -261,8 +261,7 @@ static int tree_voice_cb(int selected_item, void * data)
261 261
262bool check_rockboxdir(void) 262bool check_rockboxdir(void)
263{ 263{
264 char path[MAX_PATH]; 264 if(!dir_exists(ROCKBOX_DIR))
265 if(!dir_exists(get_user_file_path(ROCKBOX_DIR, 0, path, sizeof(path))))
266 { /* No need to localise this message. 265 { /* No need to localise this message.
267 If .rockbox is missing, it wouldn't work anyway */ 266 If .rockbox is missing, it wouldn't work anyway */
268 int i; 267 int i;
diff --git a/firmware/common/dircache.c b/firmware/common/dircache.c
index 509743bdbb..e8a5e7cbb1 100644
--- a/firmware/common/dircache.c
+++ b/firmware/common/dircache.c
@@ -89,13 +89,10 @@ static int fdbind_idx = 0;
89 */ 89 */
90static int open_dircache_file(unsigned flags, int permissions) 90static int open_dircache_file(unsigned flags, int permissions)
91{ 91{
92 char path[MAX_PATH];
93 const char *file = get_user_file_path(DIRCACHE_FILE, IS_FILE|NEED_WRITE,
94 path, sizeof(path));
95 if (permissions != 0) 92 if (permissions != 0)
96 return open(file, flags, permissions); 93 return open(DIRCACHE_FILE, flags, permissions);
97 94
98 return open(file, flags); 95 return open(DIRCACHE_FILE, flags);
99} 96}
100 97
101/** 98/**
@@ -103,9 +100,7 @@ static int open_dircache_file(unsigned flags, int permissions)
103 */ 100 */
104static int remove_dircache_file(void) 101static int remove_dircache_file(void)
105{ 102{
106 char path[MAX_PATH]; 103 return remove(DIRCACHE_FILE);
107 return remove(get_user_file_path(DIRCACHE_FILE, IS_FILE|NEED_WRITE,
108 path, sizeof(path)));
109} 104}
110#endif 105#endif
111/** 106/**
diff --git a/firmware/common/rbpaths.c b/firmware/common/rbpaths.c
index b63586c9f4..50d6ccf6ec 100644
--- a/firmware/common/rbpaths.c
+++ b/firmware/common/rbpaths.c
@@ -22,13 +22,47 @@
22 22
23#include <stdio.h> /* snprintf */ 23#include <stdio.h> /* snprintf */
24#include <stdlib.h> 24#include <stdlib.h>
25#include <stdarg.h>
25#include "rbpaths.h" 26#include "rbpaths.h"
26#include "file.h" /* MAX_PATH */ 27#include "file.h" /* MAX_PATH */
27#include "dir.h"
28#include "gcc_extensions.h" 28#include "gcc_extensions.h"
29#include "string-extra.h" 29#include "string-extra.h"
30#include "filefuncs.h" 30#include "filefuncs.h"
31 31
32#undef open
33#undef creat
34#undef remove
35#undef rename
36#undef opendir
37#undef mkdir
38#undef rmdir
39
40#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
41#include "dir-target.h"
42#define opendir opendir_android
43#define mkdir mkdir_android
44#define rmdir rmdir_android
45#elif (CONFIG_PLATFORM & PLATFORM_SDL)
46#define open sim_open
47#define remove sim_remove
48#define rename sim_rename
49#define opendir sim_opendir
50#define mkdir sim_mkdir
51#define rmdir sim_rmdir
52extern int sim_open(const char* name, int o, ...);
53extern int sim_remove(const char* name);
54extern int sim_rename(const char* old, const char* new);
55extern DIR* sim_opendir(const char* name);
56extern int sim_mkdir(const char* name);
57extern int sim_rmdir(const char* name);
58#endif
59
60/* flags for get_user_file_path() */
61/* whether you need write access to that file/dir, especially true
62 * for runtime generated files (config.cfg) */
63#define NEED_WRITE (1<<0)
64/* file or directory? */
65#define IS_FILE (1<<1)
32 66
33void paths_init(void) 67void paths_init(void)
34{ 68{
@@ -42,14 +76,28 @@ void paths_init(void)
42#endif 76#endif
43} 77}
44 78
45const char* get_user_file_path(const char *path, 79static bool try_path(const char* filename, unsigned flags)
46 unsigned flags, 80{
47 char* buf, 81 if (flags & IS_FILE)
48 const size_t bufsize) 82 {
83 if (file_exists(filename))
84 return true;
85 }
86 else
87 {
88 if (dir_exists(filename))
89 return true;
90 }
91 return false;
92}
93
94static const char* _get_user_file_path(const char *path,
95 unsigned flags,
96 char* buf,
97 const size_t bufsize)
49{ 98{
50 const char *ret = path; 99 const char *ret = path;
51 const char *pos = path; 100 const char *pos = path;
52 printf("%s(): looking for %s\n", __func__, path);
53 /* replace ROCKBOX_DIR in path with $HOME/.config/rockbox.org */ 101 /* replace ROCKBOX_DIR in path with $HOME/.config/rockbox.org */
54 pos += ROCKBOX_DIR_LEN; 102 pos += ROCKBOX_DIR_LEN;
55 if (*pos == '/') pos += 1; 103 if (*pos == '/') pos += 1;
@@ -66,27 +114,99 @@ const char* get_user_file_path(const char *path,
66 * write access is needed */ 114 * write access is needed */
67 if (flags & NEED_WRITE) 115 if (flags & NEED_WRITE)
68 ret = buf; 116 ret = buf;
69 else 117 else if (try_path(buf, flags))
118 ret = buf;
119
120 if (ret != buf) /* not found in $HOME, try ROCKBOX_BASE_DIR, !NEED_WRITE only */
70 { 121 {
71 if (flags & IS_FILE) 122 if (snprintf(buf, bufsize, ROCKBOX_SHARE_PATH "/%s", pos) >= (int)bufsize)
72 { 123 return NULL;
73 if (file_exists(buf)) 124
74 ret = buf; 125 if (try_path(buf, flags))
75 } 126 ret = buf;
76 else
77 {
78 if (dir_exists(buf))
79 ret = buf;
80 }
81 } 127 }
82 128
83 /* make a copy if we're about to return the path*/ 129 return ret;
84 if (UNLIKELY((flags & FORCE_BUFFER_COPY) && (ret != buf))) 130}
131
132int app_open(const char *name, int o, ...)
133{
134 char realpath[MAX_PATH];
135 va_list ap;
136 int fd;
137
138 if (!strncmp(ROCKBOX_DIR, name, ROCKBOX_DIR_LEN))
85 { 139 {
86 strlcpy(buf, ret, bufsize); 140 int flags = IS_FILE;
87 ret = buf; 141 if (o & (O_CREAT|O_RDWR|O_TRUNC|O_WRONLY))
142 flags |= NEED_WRITE;
143 name = _get_user_file_path(name, flags, realpath, sizeof(realpath));
88 } 144 }
145 va_start(ap, o);
146 fd = open(name, o, ap);
147 va_end(ap);
148
149 return fd;
150
151}
89 152
90 printf("%s(): %s\n", __func__, ret); 153int app_creat(const char* name, mode_t mode)
91 return ret; 154{
155 return app_open(name, O_CREAT|O_WRONLY|O_TRUNC, mode);
92} 156}
157
158int app_remove(const char *name)
159{
160 char realpath[MAX_PATH];
161 const char *fname = name;
162 if (!strncmp(ROCKBOX_DIR, name, ROCKBOX_DIR_LEN))
163 {
164 fname = _get_user_file_path(name, 0, realpath, sizeof(realpath));
165 }
166 return remove(fname);
167}
168
169int app_rename(const char *old, const char *new)
170{
171 char realpath[MAX_PATH];
172 const char *fname = old;
173 if (!strncmp(ROCKBOX_DIR, old, ROCKBOX_DIR_LEN))
174 {
175 fname = _get_user_file_path(old, 0, realpath, sizeof(realpath));
176 }
177 return rename(fname, new);
178}
179
180DIR *app_opendir(const char *name)
181{
182 char realpath[MAX_PATH];
183 const char *fname = name;
184 if (!strncmp(ROCKBOX_DIR, name, ROCKBOX_DIR_LEN))
185 {
186 fname = _get_user_file_path(name, 0, realpath, sizeof(realpath));
187 }
188 return opendir(fname);
189}
190
191int app_mkdir(const char* name)
192{
193 char realpath[MAX_PATH];
194 const char *fname = name;
195 if (!strncmp(ROCKBOX_DIR, name, ROCKBOX_DIR_LEN))
196 {
197 fname = _get_user_file_path(name, 0, realpath, sizeof(realpath));
198 }
199 return mkdir(fname);
200}
201
202int app_rmdir(const char* name)
203{
204 char realpath[MAX_PATH];
205 const char *fname = name;
206 if (!strncmp(ROCKBOX_DIR, name, ROCKBOX_DIR_LEN))
207 {
208 fname = _get_user_file_path(name, 0, realpath, sizeof(realpath));
209 }
210 return rmdir(fname);
211}
212
diff --git a/firmware/export/rbpaths.h b/firmware/export/rbpaths.h
index cd87888cef..6c5d769ed8 100644
--- a/firmware/export/rbpaths.h
+++ b/firmware/export/rbpaths.h
@@ -26,17 +26,6 @@
26#include "autoconf.h" 26#include "autoconf.h"
27#include "string-extra.h" 27#include "string-extra.h"
28 28
29/* flags for get_user_file_path() */
30/* whether you need write access to that file/dir, especially true
31 * for runtime generated files (config.cfg) */
32#define NEED_WRITE (1<<0)
33/* file or directory? */
34#define IS_FILE (1<<1)
35/* make sure the path is copied into the passed buffer (it may return
36 * the passed path directly otherwise, e.g. always on target builds) */
37#define FORCE_BUFFER_COPY (1<<2)
38
39
40 29
41/* name of directory where configuration, fonts and other data 30/* name of directory where configuration, fonts and other data
42 * files are stored */ 31 * files are stored */
@@ -67,35 +56,17 @@
67#define REC_BASE_DIR "/" 56#define REC_BASE_DIR "/"
68#define PLAYLIST_CATALOG_DEFAULT_DIR "/Playlists" 57#define PLAYLIST_CATALOG_DEFAULT_DIR "/Playlists"
69 58
70#ifndef PLUGIN
71static inline __attribute__((always_inline)) const char* get_user_file_path(const char *path,
72 unsigned flags,
73 char* buf,
74 const size_t bufsize)
75{
76 if (flags & FORCE_BUFFER_COPY)
77 {
78 strlcpy(buf, path, bufsize);
79 return buf;
80 }
81 return path;
82}
83#endif
84
85#define paths_init() 59#define paths_init()
86#else /* application */ 60#else /* application */
87 61
88#define PLUGIN_DIR ROCKBOX_LIBRARY_PATH "/rockbox/rocks" 62#define PLUGIN_DIR ROCKBOX_LIBRARY_PATH "/rocks"
89#define CODECS_DIR ROCKBOX_LIBRARY_PATH "/rockbox/codecs" 63#define CODECS_DIR ROCKBOX_LIBRARY_PATH "/codecs"
90 64
91#define REC_BASE_DIR ROCKBOX_DIR "/" 65#define REC_BASE_DIR ROCKBOX_DIR "/"
92#define PLAYLIST_CATALOG_DEFAULT_DIR ROCKBOX_DIR "/Playlists" 66#define PLAYLIST_CATALOG_DEFAULT_DIR ROCKBOX_DIR "/Playlists"
93 67
94extern void paths_init(void); 68extern void paths_init(void);
95extern const char* get_user_file_path(const char *path, 69
96 unsigned flags,
97 char* buf,
98 const size_t bufsize);
99#endif /* APPLICATION */ 70#endif /* APPLICATION */
100 71
101#define LANG_DIR ROCKBOX_DIR "/langs" 72#define LANG_DIR ROCKBOX_DIR "/langs"
diff --git a/firmware/font.c b/firmware/font.c
index e973108bca..cd74459b1e 100644
--- a/firmware/font.c
+++ b/firmware/font.c
@@ -613,11 +613,7 @@ void glyph_cache_save(struct font* pf)
613 pf = &font_ui; 613 pf = &font_ui;
614 if (pf->fd >= 0 && pf == &font_ui) 614 if (pf->fd >= 0 && pf == &font_ui)
615 { 615 {
616 char path[MAX_PATH]; 616 cache_fd = open(GLYPH_CACHE_FILE, O_WRONLY|O_CREAT|O_TRUNC, 0666);
617 const char *file = get_user_file_path(GLYPH_CACHE_FILE, IS_FILE|NEED_WRITE,
618 path, sizeof(path));
619
620 cache_fd = open(file, O_WRONLY|O_CREAT|O_TRUNC, 0666);
621 if (cache_fd < 0) 617 if (cache_fd < 0)
622 return; 618 return;
623 619
@@ -678,7 +674,6 @@ static void glyph_cache_load(struct font* pf)
678 int i, size; 674 int i, size;
679 unsigned char tmp[2]; 675 unsigned char tmp[2];
680 unsigned short ch; 676 unsigned short ch;
681 char path[MAX_PATH];
682 unsigned short glyphs[MAX_SORT]; 677 unsigned short glyphs[MAX_SORT];
683 unsigned short glyphs_lru_order[MAX_SORT]; 678 unsigned short glyphs_lru_order[MAX_SORT];
684 int glyph_file_skip=0, glyph_file_size=0; 679 int glyph_file_skip=0, glyph_file_size=0;
@@ -687,8 +682,7 @@ static void glyph_cache_load(struct font* pf)
687 if ( sort_size > MAX_SORT ) 682 if ( sort_size > MAX_SORT )
688 sort_size = MAX_SORT; 683 sort_size = MAX_SORT;
689 684
690 fd = open(get_user_file_path(GLYPH_CACHE_FILE, IS_FILE|NEED_WRITE, 685 fd = open(GLYPH_CACHE_FILE, O_RDONLY|O_BINARY);
691 path, sizeof(path)), O_RDONLY|O_BINARY);
692 if (fd >= 0) { 686 if (fd >= 0) {
693 687
694 /* only read what fits */ 688 /* only read what fits */
diff --git a/firmware/include/dir.h b/firmware/include/dir.h
index 29dcb65961..3a582c3865 100644
--- a/firmware/include/dir.h
+++ b/firmware/include/dir.h
@@ -49,7 +49,6 @@
49#define ATTR_ARCHIVE 0x20 49#define ATTR_ARCHIVE 0x20
50#define ATTR_VOLUME 0x40 /* this is a volume, not a real directory */ 50#define ATTR_VOLUME 0x40 /* this is a volume, not a real directory */
51 51
52#if (CONFIG_PLATFORM & (PLATFORM_NATIVE|PLATFORM_SDL))
53#ifdef HAVE_DIRCACHE 52#ifdef HAVE_DIRCACHE
54# include "dircache.h" 53# include "dircache.h"
55# define DIR DIR_CACHED 54# define DIR DIR_CACHED
@@ -61,7 +60,7 @@
61# define mkdir mkdir_cached 60# define mkdir mkdir_cached
62# define rmdir rmdir_cached 61# define rmdir rmdir_cached
63#else 62#else
64#include "dir_uncached.h" 63# include "dir_uncached.h"
65# define DIR DIR_UNCACHED 64# define DIR DIR_UNCACHED
66# define dirent dirent_uncached 65# define dirent dirent_uncached
67# define opendir opendir_uncached 66# define opendir opendir_uncached
@@ -71,9 +70,5 @@
71# define mkdir mkdir_uncached 70# define mkdir mkdir_uncached
72# define rmdir rmdir_uncached 71# define rmdir rmdir_uncached
73#endif 72#endif
74#else
75#include "dir-target.h"
76#include "dir_uncached.h"
77#endif
78 73
79#endif 74#endif
diff --git a/firmware/include/dir_uncached.h b/firmware/include/dir_uncached.h
index 29512c7a69..3bae07177b 100644
--- a/firmware/include/dir_uncached.h
+++ b/firmware/include/dir_uncached.h
@@ -34,13 +34,13 @@ struct dirinfo {
34#include "file.h" 34#include "file.h"
35 35
36#if (CONFIG_PLATFORM & PLATFORM_SDL) 36#if (CONFIG_PLATFORM & PLATFORM_SDL)
37#define dirent_uncached sim_dirent 37# define dirent_uncached sim_dirent
38#define DIR_UNCACHED SIM_DIR 38# define DIR_UNCACHED SIM_DIR
39#define opendir_uncached sim_opendir 39# define opendir_uncached sim_opendir
40#define readdir_uncached sim_readdir 40# define readdir_uncached sim_readdir
41#define closedir_uncached sim_closedir 41# define closedir_uncached sim_closedir
42#define mkdir_uncached sim_mkdir 42# define mkdir_uncached sim_mkdir
43#define rmdir_uncached sim_rmdir 43# define rmdir_uncached sim_rmdir
44#endif 44#endif
45 45
46#ifndef DIRENT_DEFINED 46#ifndef DIRENT_DEFINED
@@ -54,6 +54,7 @@ struct dirent_uncached {
54 54
55#include "fat.h" 55#include "fat.h"
56 56
57#ifndef DIR_DEFINED
57typedef struct { 58typedef struct {
58#if (CONFIG_PLATFORM & PLATFORM_NATIVE) 59#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
59 bool busy; 60 bool busy;
@@ -69,6 +70,24 @@ typedef struct {
69 char *name; 70 char *name;
70#endif 71#endif
71} DIR_UNCACHED; 72} DIR_UNCACHED;
73#endif
74
75
76#if defined(APPLICATION)
77#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
78#include "dir-target.h"
79#endif
80# undef opendir_uncached
81# define opendir_uncached app_opendir
82# undef mkdir_uncached
83# define mkdir_uncached app_mkdir
84# undef rmdir_uncached
85# define rmdir_uncached app_rmdir
86/* defined in rbpaths.c */
87extern DIR_UNCACHED* app_opendir(const char* name);
88extern int app_rmdir(const char* name);
89extern int app_mkdir(const char* name);
90#endif
72 91
73#ifdef HAVE_HOTSWAP 92#ifdef HAVE_HOTSWAP
74char *get_volume_name(int volume); 93char *get_volume_name(int volume);
diff --git a/firmware/include/file.h b/firmware/include/file.h
index 8711124391..ee52c3f2b7 100644
--- a/firmware/include/file.h
+++ b/firmware/include/file.h
@@ -37,20 +37,38 @@
37#define MAX_OPEN_FILES 11 37#define MAX_OPEN_FILES 11
38 38
39#if !defined(PLUGIN) && !defined(CODEC) 39#if !defined(PLUGIN) && !defined(CODEC)
40#if (CONFIG_PLATFORM & PLATFORM_SDL) 40#if defined(APPLICATION)
41#define open(x, ...) sim_open(x, __VA_ARGS__) 41# define open(x, ...) app_open(x, __VA_ARGS__)
42#define creat(x,m) sim_creat(x,m) 42# define creat(x,m) app_creat(x, m)
43#define remove(x) sim_remove(x) 43# define remove(x) app_remove(x)
44#define rename(x,y) sim_rename(x,y) 44# define rename(x,y) app_rename(x,y)
45#define filesize(x) sim_filesize(x) 45extern int app_open(const char *name, int o, ...);
46#define fsync(x) sim_fsync(x) 46extern int app_creat(const char *name, mode_t mode);
47#define ftruncate(x,y) sim_ftruncate(x,y) 47extern int app_remove(const char* pathname);
48#define lseek(x,y,z) sim_lseek(x,y,z) 48extern int app_rename(const char* path, const char* newname);
49#define read(x,y,z) sim_read(x,y,z) 49# if (CONFIG_PLATFORM & PLATFORM_SDL)
50#define write(x,y,z) sim_write(x,y,z) 50# define filesize(x) sim_filesize(x)
51#define close(x) sim_close(x) 51# define fsync(x) sim_fsync(x)
52extern int sim_creat(const char *pathname, mode_t mode); 52# define ftruncate(x,y) sim_ftruncate(x,y)
53extern int sim_open(const char *pathname, int flags, ...); 53# define lseek(x,y,z) sim_lseek(x,y,z)
54# define read(x,y,z) sim_read(x,y,z)
55# define write(x,y,z) sim_write(x,y,z)
56# define close(x) sim_close(x)
57# endif
58#elif defined(SIMULATOR)
59# define open(x, ...) sim_open(x, __VA_ARGS__)
60# define creat(x,m) sim_creat(x,m)
61# define remove(x) sim_remove(x)
62# define rename(x,y) sim_rename(x,y)
63# define filesize(x) sim_filesize(x)
64# define fsync(x) sim_fsync(x)
65# define ftruncate(x,y) sim_ftruncate(x,y)
66# define lseek(x,y,z) sim_lseek(x,y,z)
67# define read(x,y,z) sim_read(x,y,z)
68# define write(x,y,z) sim_write(x,y,z)
69# define close(x) sim_close(x)
70extern int sim_open(const char *name, int o, ...);
71extern int sim_creat(const char *name, mode_t mode);
54#endif 72#endif
55 73
56typedef int (*open_func)(const char* pathname, int flags, ...); 74typedef int (*open_func)(const char* pathname, int flags, ...);
diff --git a/firmware/load_code.c b/firmware/load_code.c
index 5b5307e622..2337ee5cad 100644
--- a/firmware/load_code.c
+++ b/firmware/load_code.c
@@ -144,17 +144,15 @@ void *lc_open_from_mem(void *addr, size_t blob_size)
144 for (i = 0; i < 10; i++) 144 for (i = 0; i < 10; i++)
145 { 145 {
146#if (CONFIG_PLATFORM & PLATFORM_ANDROID) 146#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
147 /* we need that path fixed, since get_user_file_path() 147 /* we need that path fixed, since _get_user_file_path()
148 * gives us the folder on the sdcard where we cannot load libraries 148 * gives us the folder on the sdcard where we cannot load libraries
149 * from (no exec permissions) 149 * from (no exec permissions)
150 */ 150 */
151 snprintf(temp_filename, sizeof(temp_filename), 151 snprintf(temp_filename, sizeof(temp_filename),
152 "/data/data/org.rockbox/app_rockbox/libtemp_binary_%d.so", i); 152 "/data/data/org.rockbox/app_rockbox/libtemp_binary_%d.so", i);
153#else 153#else
154 char name[MAX_PATH];
155 const char *_name = get_user_file_path(ROCKBOX_DIR, NEED_WRITE, name, sizeof(name));
156 snprintf(temp_filename, sizeof(temp_filename), 154 snprintf(temp_filename, sizeof(temp_filename),
157 "%s/libtemp_binary_%d.dll", _name, i); 155 ROCKBOX_DIR "/libtemp_binary_%d.dll", i);
158#endif 156#endif
159 fd = open(temp_filename, O_WRONLY|O_CREAT|O_TRUNC, 0700); 157 fd = open(temp_filename, O_WRONLY|O_CREAT|O_TRUNC, 0700);
160 if (fd >= 0) 158 if (fd >= 0)
diff --git a/firmware/target/hosted/android/dir-target.h b/firmware/target/hosted/android/dir-target.h
index c93d92caad..c6c6b4b2b0 100644
--- a/firmware/target/hosted/android/dir-target.h
+++ b/firmware/target/hosted/android/dir-target.h
@@ -24,10 +24,21 @@
24 24
25#include <dirent.h> 25#include <dirent.h>
26 26
27#define opendir _opendir 27#define dirent_uncached dirent
28#define mkdir _mkdir 28#define DIR_UNCACHED DIR
29#define closedir _closedir 29#define opendir_uncached _opendir
30#define readdir _readdir 30#define readdir_uncached _readdir
31#define closedir_uncached _closedir
32#define mkdir_uncached _mkdir
33#define rmdir_uncached rmdir
34
35#define dirent_android dirent
36#define DIR_android DIR
37#define opendir_android _opendir
38#define readdir_android _readdir
39#define closedir_android _closedir
40#define mkdir_android _mkdir
41#define rmdir_android rmdir
31 42
32extern DIR* _opendir(const char* name); 43extern DIR* _opendir(const char* name);
33extern int _mkdir(const char* name); 44extern int _mkdir(const char* name);
@@ -36,5 +47,7 @@ extern struct dirent *_readdir(DIR* dir);
36extern void fat_size(unsigned long *size, unsigned long *free); 47extern void fat_size(unsigned long *size, unsigned long *free);
37 48
38#define DIRFUNCTIONS_DEFINED 49#define DIRFUNCTIONS_DEFINED
50#define DIRENT_DEFINED
51#define DIR_DEFINED
39 52
40#endif /* __DIR_TARGET_H__ */ 53#endif /* __DIR_TARGET_H__ */
diff --git a/firmware/target/hosted/android/fs-android.c b/firmware/target/hosted/android/fs-android.c
index 5209458e54..1967198d3d 100644
--- a/firmware/target/hosted/android/fs-android.c
+++ b/firmware/target/hosted/android/fs-android.c
@@ -29,6 +29,7 @@
29#include "dir-target.h" 29#include "dir-target.h"
30#include "file.h" 30#include "file.h"
31#include "dir.h" 31#include "dir.h"
32#include "rbpaths.h"
32 33
33 34
34long filesize(int fd) 35long filesize(int fd)
diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c
index 3591905e32..fe7bad438f 100644
--- a/uisimulator/common/io.c
+++ b/uisimulator/common/io.c
@@ -293,7 +293,6 @@ static const char *get_sim_pathname(const char *name)
293MYDIR *sim_opendir(const char *name) 293MYDIR *sim_opendir(const char *name)
294{ 294{
295 DIR_T *dir; 295 DIR_T *dir;
296
297 dir = (DIR_T *) OPENDIR(get_sim_pathname(name)); 296 dir = (DIR_T *) OPENDIR(get_sim_pathname(name));
298 297
299 if (dir) 298 if (dir)