summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2020-06-01 14:16:23 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2020-07-06 15:15:20 +1000
commitd075c3e6971a10fd7e0bd44bbf5a5c9d610159d7 (patch)
tree613f29b8e470f59214b35c3b6dc0622ebfaf3e65 /src
parent43b9d0924889e326c6c738f2fac1296bf0b56a31 (diff)
downloadxorg-lib-libxkbcommon-d075c3e6971a10fd7e0bd44bbf5a5c9d610159d7.tar.gz
Factor the access check for paths out
Easier to re-use without having to duplicate ifdefs. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'src')
-rw-r--r--src/context.c7
-rw-r--r--src/utils.h23
2 files changed, 24 insertions, 6 deletions
diff --git a/src/context.c b/src/context.c
index fbb48dc..fe24516 100644
--- a/src/context.c
+++ b/src/context.c
@@ -63,13 +63,8 @@ xkb_context_include_path_append(struct xkb_context *ctx, const char *path)
if (!S_ISDIR(stat_buf.st_mode))
goto err;
-#if defined(HAVE_EACCESS)
- if (eaccess(path, R_OK | X_OK) != 0)
+ if (!check_eaccess(path, R_OK | X_OK))
goto err;
-#elif defined(HAVE_EUIDACCESS)
- if (euidaccess(path, R_OK | X_OK) != 0)
- goto err;
-#endif
darray_append(ctx->includes, tmp);
return 1;
diff --git a/src/utils.h b/src/utils.h
index 303b93c..2c35a87 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -29,6 +29,15 @@
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
+#if defined(HAVE_EACCESS) || defined(HAVE_EUIDACCESS)
+#include <unistd.h>
+#else
+/* Required on Windows where unistd.h doesn't exist */
+#define R_OK 4 /* Test for read permission. */
+#define W_OK 2 /* Test for write permission. */
+#define X_OK 1 /* Test for execute permission. */
+#define F_OK 0 /* Test for existence. */
+#endif
#include "darray.h"
@@ -202,6 +211,20 @@ map_file(FILE *file, char **string_out, size_t *size_out);
void
unmap_file(char *string, size_t size);
+static inline bool
+check_eaccess(const char *path, int mode)
+{
+#if defined(HAVE_EACCESS)
+ if (eaccess(path, mode) != 0)
+ return false;
+#elif defined(HAVE_EUIDACCESS)
+ if (euidaccess(path, mode) != 0)
+ return false;
+#endif
+
+ return true;
+}
+
#if defined(HAVE_SECURE_GETENV)
# define secure_getenv secure_getenv
#elif defined(HAVE___SECURE_GETENV)