* import-gnulib.config (modules): Add faccessat. * find/pred.c (struct access_check_args): Delete. (access_callback): Delete. (can_access): Delete. (pred_executable): Use faccessat. (pred_readable): Likewise. (pred_writable): Likewise.
Signed-off-by: James Youngman <[email protected]> --- ChangeLog | 9 +++++++++ find/pred.c | 38 ++++++-------------------------------- import-gnulib.config | 2 +- 3 files changed, 16 insertions(+), 33 deletions(-) diff --git a/ChangeLog b/ChangeLog index d00cebe..fc5b655 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2010-04-08 James Youngman <[email protected]> + Adopt the use of the gnulib module faccessat. + * import-gnulib.config (modules): Add faccessat. + * find/pred.c (struct access_check_args): Delete. + (access_callback): Delete. + (can_access): Delete. + (pred_executable): Use faccessat. + (pred_readable): Likewise. + (pred_writable): Likewise. + Adopt (explicitly) the use of the gnulib module dirent-safer. * import-gnulib.config (modules): Add dirent-safer; we were previously transitively importing this module, but we are now diff --git a/find/pred.c b/find/pred.c index 1e0e891..9c7b372 100644 --- a/find/pred.c +++ b/find/pred.c @@ -1570,35 +1570,6 @@ pred_perm (const char *pathname, struct stat *stat_buf, struct predicate *pred_p } -struct access_check_args -{ - const char *filename; - int access_type; - int cb_errno; -}; - - -static int -access_callback (void *context) -{ - int rv; - struct access_check_args *args = context; - if ((rv = access (args->filename, args->access_type)) < 0) - args->cb_errno = errno; - return rv; -} - -static int -can_access (int access_type) -{ - struct access_check_args args; - args.filename = state.rel_pathname; - args.access_type = access_type; - args.cb_errno = 0; - return 0 == run_in_dir (state.cwd_dir_fd, access_callback, &args); -} - - bool pred_executable (const char *pathname, struct stat *stat_buf, struct predicate *pred_ptr) { @@ -1606,7 +1577,8 @@ pred_executable (const char *pathname, struct stat *stat_buf, struct predicate * (void) stat_buf; (void) pred_ptr; - return can_access (X_OK); + /* As for access, the check is performed with the real user id. */ + return 0 == faccessat (state.cwd_dir_fd, state.rel_pathname, X_OK, 0); } bool @@ -1616,7 +1588,8 @@ pred_readable (const char *pathname, struct stat *stat_buf, struct predicate *pr (void) stat_buf; (void) pred_ptr; - return can_access (R_OK); + /* As for access, the check is performed with the real user id. */ + return 0 == faccessat (state.cwd_dir_fd, state.rel_pathname, R_OK, 0); } bool @@ -1626,7 +1599,8 @@ pred_writable (const char *pathname, struct stat *stat_buf, struct predicate *pr (void) stat_buf; (void) pred_ptr; - return can_access (W_OK); + /* As for access, the check is performed with the real user id. */ + return 0 == faccessat (state.cwd_dir_fd, state.rel_pathname, W_OK, 0); } bool diff --git a/import-gnulib.config b/import-gnulib.config index 5abe74a..6186b7c 100644 --- a/import-gnulib.config +++ b/import-gnulib.config @@ -25,7 +25,6 @@ update-copyright ' # consider using do-release-commit-and-tag -# consider using faccessat # consider using gendocs # consider using getdelim # consider using gethrxtime @@ -75,6 +74,7 @@ dirent-safer dirname errno error +faccessat fchdir fcntl fdl -- 1.7.0
