This changes _alpm_access* to use faccessat,

which allows behavior flags to be passed.

Signed-off-by: Ryan Gonzalez <rym...@gmail.com>
---
 lib/libalpm/util.c | 18 ++++++++++++------
 lib/libalpm/util.h |  2 ++
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index a4d62c7c..8d653b16 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -1333,16 +1333,22 @@ alpm_time_t _alpm_parsedate(const char *line)
        return (alpm_time_t)result;
 }
 
-/** Wrapper around access() which takes a dir and file argument
+int _alpm_access(alpm_handle_t *handle, const char *dir, const char *file, int 
amode) {
+       return _alpm_access_flags(handle, dir, file, amode, 0);
+}
+
+/** Wrapper around faccessat() which takes a dir and file argument
  * separately and generates an appropriate error message.
  * If dir is NULL file will be treated as the whole path.
  * @param handle an alpm handle
  * @param dir directory path ending with and slash
  * @param file filename
- * @param amode access mode as described in access()
- * @return int value returned by access()
+ * @param amode access mode as described in faccessat()
+ * @param flags flags to pass as described in faccessat()
+ * @return int value returned by faccessat()
  */
-int _alpm_access(alpm_handle_t *handle, const char *dir, const char *file, int 
amode)
+int _alpm_access_flags(alpm_handle_t *handle, const char *dir, const char 
*file, int amode,
+               int flags)
 {
        size_t len = 0;
        int ret = 0;
@@ -1354,11 +1360,11 @@ int _alpm_access(alpm_handle_t *handle, const char 
*dir, const char *file, int a
                CALLOC(check_path, len, sizeof(char), RET_ERR(handle, 
ALPM_ERR_MEMORY, -1));
                snprintf(check_path, len, "%s%s", dir, file);
 
-               ret = access(check_path, amode);
+               ret = faccessat(AT_FDCWD, check_path, amode, flags);
                free(check_path);
        } else {
                dir = "";
-               ret = access(file, amode);
+               ret = faccessat(AT_FDCWD, file, amode, flags);
        }
 
        if(ret != 0) {
diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h
index 71dadc2c..1af79571 100644
--- a/lib/libalpm/util.h
+++ b/lib/libalpm/util.h
@@ -143,6 +143,8 @@ alpm_time_t _alpm_parsedate(const char *line);
 int _alpm_raw_cmp(const char *first, const char *second);
 int _alpm_raw_ncmp(const char *first, const char *second, size_t max);
 int _alpm_access(alpm_handle_t *handle, const char *dir, const char *file, int 
amode);
+int _alpm_access_flags(alpm_handle_t *handle, const char *dir, const char 
*file, int amode,
+               int flags);
 int _alpm_fnmatch_patterns(alpm_list_t *patterns, const char *string);
 int _alpm_fnmatch(const void *pattern, const void *string);
 void *_alpm_realloc(void **data, size_t *current, const size_t required);
-- 
2.23.0

Reply via email to