summaryrefslogtreecommitdiff
path: root/firmware/common/filefuncs.c
diff options
context:
space:
mode:
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__ */