summaryrefslogtreecommitdiff
path: root/main/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'main/utils.c')
-rw-r--r--main/utils.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/main/utils.c b/main/utils.c
index ffef3ac97..3eeafed4f 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -2932,3 +2932,20 @@ int ast_eid_cmp(const struct ast_eid *eid1, const struct ast_eid *eid2)
{
return memcmp(eid1, eid2, sizeof(*eid1));
}
+
+int ast_file_is_readable(const char *filename)
+{
+#if defined(HAVE_EACCESS) || defined(HAVE_EUIDACCESS)
+#if defined(HAVE_EUIDACCESS) && !defined(HAVE_EACCESS)
+#define eaccess euidaccess
+#endif
+ return eaccess(filename, R_OK) == 0;
+#else
+ int fd = open(filename, O_RDONLY | O_NONBLOCK);
+ if (fd < 0) {
+ return 0;
+ }
+ close(fd);
+ return 1;
+#endif
+}