summaryrefslogtreecommitdiff
path: root/firmware/common/filefuncs.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2010-08-01 16:15:27 +0000
committerThomas Martitz <kugel@rockbox.org>2010-08-01 16:15:27 +0000
commit9c0b2479f7025a84444adf08e3be8ced60dad013 (patch)
treef3d328dd73f46d599f0432cc43ae206798cbe4f6 /firmware/common/filefuncs.c
parent2e7d92fef707a2cd30820fd0053c539c3ac8e2b3 (diff)
downloadrockbox-9c0b2479f7025a84444adf08e3be8ced60dad013.tar.gz
rockbox-9c0b2479f7025a84444adf08e3be8ced60dad013.zip
Rockbox as an application: add get_user_file_path().
For RaaA it evaluates user paths at runtime. For everything but codecs/plugins it will give the path under $HOME/.config/rockbox.org if write access is needed or if the file/folder in question exists there (otherwise it gives /usr/local/share/rockbox). This allows for installing themes under $HOME as well as having config.cfg and other important files there while installing the application (and default themes) under /usr/local. On the DAPs it's a no-op, returing /.rockbox directly. Not converted to use get_user_file_path() are plugins themselves, because RaaA doesn't build plugins yet. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27656 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/common/filefuncs.c')
-rw-r--r--firmware/common/filefuncs.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/firmware/common/filefuncs.c b/firmware/common/filefuncs.c
index ca9113250a..c058267094 100644
--- a/firmware/common/filefuncs.c
+++ b/firmware/common/filefuncs.c
@@ -22,6 +22,7 @@
22#include "dir.h" 22#include "dir.h"
23#include "stdlib.h" 23#include "stdlib.h"
24#include "string.h" 24#include "string.h"
25#include "debug.h"
25 26
26#ifdef HAVE_MULTIVOLUME 27#ifdef HAVE_MULTIVOLUME
27/* returns on which volume this is, and copies the reduced name 28/* returns on which volume this is, and copies the reduced name
@@ -50,3 +51,39 @@ int strip_volume(const char* name, char* namecopy)
50 return volume; 51 return volume;
51} 52}
52#endif /* #ifdef HAVE_MULTIVOLUME */ 53#endif /* #ifdef HAVE_MULTIVOLUME */
54
55#ifndef __PCTOOL__
56/* Test file existence, using dircache of possible */
57bool file_exists(const char *file)
58{
59 int fd;
60
61#ifdef DEBUG
62 if (!file || strlen(file) <= 0)
63 {
64 DEBUGF("%s(): Invalid parameter!\n");
65 return false;
66 }
67#endif
68
69#ifdef HAVE_DIRCACHE
70 if (dircache_is_enabled())
71 return (dircache_get_entry_ptr(file) != NULL);
72#endif
73
74 fd = open(file, O_RDONLY);
75 if (fd < 0)
76 return false;
77 close(fd);
78 return true;
79}
80
81bool dir_exists(const char *path)
82{
83 DIR* d = opendir(path);
84 if (!d)
85 return false;
86 closedir(d);
87 return true;
88}
89#endif /* __PCTOOL__ */