diff options
Diffstat (limited to 'apps/misc.c')
-rw-r--r-- | apps/misc.c | 32 |
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 */ | ||
1096 | bool 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 | |||
1115 | bool 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 | } | ||