forked from len0rd/rockbox
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
This commit is contained in:
parent
a2ad8537af
commit
d87b037efe
10 changed files with 50 additions and 65 deletions
32
apps/misc.c
32
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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue