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>master
parent
43b9d09248
commit
d075c3e697
|
@ -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;
|
||||
|
|
23
src/utils.h
23
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)
|
||||
|
|
Loading…
Reference in New Issue