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.tar.gz
rockbox-d87b037efe7d001902c0cde992e1633ff9f70061.zip
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 4af97afb5e..a8710c312f 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -1092,3 +1092,35 @@ char* strrsplt(char* str, int c)
1092 return s; 1092 return s;
1093} 1093}
1094 1094
1095/* Test file existence, using dircache of possible */
1096bool file_exists(const char *file)
1097{
1098 int fd;
1099
1100 if (!file || strlen(file) <= 0)
1101 return false;
1102
1103#ifdef HAVE_DIRCACHE
1104 if (dircache_is_enabled())
1105 return (dircache_get_entry_ptr(file) != NULL);
1106#endif
1107
1108 fd = open(file, O_RDONLY);
1109 if (fd < 0)
1110 return false;
1111 close(fd);
1112 return true;
1113}
1114
1115bool dir_exists(const char *path)
1116{
1117 DIR* d = opendir(path);
1118 bool retval;
1119 if (d != NULL) {
1120 closedir(d);
1121 retval = true;
1122 } else {
1123 retval = false;
1124 }
1125 return retval;
1126}