From bc366ae145683ca7ec1695c69cd2b4ed8f5bc589 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 3 Sep 2009 13:43:12 -0600 Subject: [PATCH] euidaccess: prefer POSIX over non-standard implementation * m4/euidaccess.m4 (gl_PREREQ_EUIDACCESS): Check for faccessat. * lib/euidaccess.c (euidaccess): Use it if available. Signed-off-by: Eric Blake --- ChangeLog | 4 ++++ lib/euidaccess.c | 8 +++++--- m4/euidaccess.m4 | 5 ++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 288440ec7b..4358759baa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2009-09-03 Eric Blake + euidaccess: prefer POSIX over non-standard implementation + * m4/euidaccess.m4 (gl_PREREQ_EUIDACCESS): Check for faccessat. + * lib/euidaccess.c (euidaccess): Use it if available. + openat: make template easier to use * lib/at-func.c (CALL_FUNC): Allow AT_FUNC_USE_F1_COND and AT_FUNC_F2 to be undefined. diff --git a/lib/euidaccess.c b/lib/euidaccess.c index 17eb724972..5ba59b0ef6 100644 --- a/lib/euidaccess.c +++ b/lib/euidaccess.c @@ -1,7 +1,7 @@ /* euidaccess -- check if effective user id can access file - Copyright (C) 1990, 1991, 1995, 1998, 2000, 2003, 2004, 2005, 2006, 2008 - Free Software Foundation, Inc. + Copyright (C) 1990, 1991, 1995, 1998, 2000, 2003, 2004, 2005, 2006, + 2008, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -77,7 +77,9 @@ int euidaccess (const char *file, int mode) { -#if defined EFF_ONLY_OK +#if HAVE_FACCESSAT + return faccessat (AT_FDCWD, file, mode, AT_EACCESS); +#elif defined EFF_ONLY_OK return access (file, mode | EFF_ONLY_OK); #elif defined ACC_SELF return accessx (file, mode, ACC_SELF); diff --git a/m4/euidaccess.m4 b/m4/euidaccess.m4 index 5882f5817c..f1a175cdca 100644 --- a/m4/euidaccess.m4 +++ b/m4/euidaccess.m4 @@ -1,4 +1,4 @@ -# euidaccess.m4 serial 10 +# euidaccess.m4 serial 11 dnl Copyright (C) 2002-2009 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -31,6 +31,9 @@ AC_DEFUN([gl_FUNC_EUIDACCESS], # Prerequisites of lib/euidaccess.c. AC_DEFUN([gl_PREREQ_EUIDACCESS], [ + dnl Prefer POSIX faccessat over non-standard euidaccess. + AC_CHECK_FUNCS_ONCE([faccessat]) + dnl Try various other non-standard fallbacks. AC_CHECK_HEADERS_ONCE([libgen.h]) AC_CHECK_DECLS_ONCE([setregid]) AC_REQUIRE([AC_FUNC_GETGROUPS]) -- 2.30.2