summaryrefslogtreecommitdiff
path: root/apps/misc.c
diff options
context:
space:
mode:
authorRobert Kukla <roolku@rockbox.org>2007-11-21 21:28:27 +0000
committerRobert Kukla <roolku@rockbox.org>2007-11-21 21:28:27 +0000
commitd87b037efe7d001902c0cde992e1633ff9f70061 (patch)
treeddea298e51d73443aad0d31fca7d59311444efab /apps/misc.c
parenta2ad8537af659972b2e859c99c0ff75e374b73f9 (diff)
downloadrockbox-d87b037efe7d001902c0cde992e1633ff9f70061.zip
rockbox-d87b037efe7d001902c0cde992e1633ff9f70061.tar.gz
rockbox-d87b037efe7d001902c0cde992e1633ff9f70061.tar.bz2
rockbox-d87b037efe7d001902c0cde992e1633ff9f70061.tar.xz
consolidate the 3 file_exists() functions into one; use the version that explicitly uses dircache; give dir_exists() the same treatment for consistency
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15742 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/misc.c')
-rw-r--r--apps/misc.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/apps/misc.c b/apps/misc.c
index 4af97af..a8710c3 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -1092,3 +1092,35 @@ char* strrsplt(char* str, int c)
return s;
}
+/* Test file existence, using dircache of possible */
+bool file_exists(const char *file)
+{
+ int fd;
+
+ if (!file || strlen(file) <= 0)
+ return false;
+
+#ifdef HAVE_DIRCACHE
+ if (dircache_is_enabled())
+ return (dircache_get_entry_ptr(file) != NULL);
+#endif
+
+ fd = open(file, O_RDONLY);
+ if (fd < 0)
+ return false;
+ close(fd);
+ return true;
+}
+
+bool dir_exists(const char *path)
+{
+ DIR* d = opendir(path);
+ bool retval;
+ if (d != NULL) {
+ closedir(d);
+ retval = true;
+ } else {
+ retval = false;
+ }
+ return retval;
+}