summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2019-09-15 18:56:46 +0200
committerBruno Haible <bruno@clisp.org>2019-09-15 18:56:46 +0200
commit265886a27c8bc637b1e1f3e85e68d594bbe5fa2c (patch)
treefe630991a74cdf68b24ca8754546b66178502930
parent7ed78c9f539e6981b7ba48ef2962d4364cbd37fc (diff)
downloadgnulib-265886a27c8bc637b1e1f3e85e68d594bbe5fa2c.tar.gz
access: New module.
* lib/unistd.in.h (access): New declaration. * lib/access.c: New file. * m4/access.m4: New file. * m4/unistd_h.m4 (gl_UNISTD_H): Test whether access is declared. (gl_UNISTD_H_DEFAULTS): Initialize GNULIB_ACCESS, REPLACE_ACCESS. * modules/unistd (Makefile.am): Substitute GNULIB_ACCESS, REPLACE_ACCESS. * modules/access: New file. * tests/test-unistd-c++.cc (access): Check signature. * doc/posix-functions/access.texi: Mention the new module.
-rw-r--r--ChangeLog14
-rw-r--r--doc/posix-functions/access.texi5
-rw-r--r--lib/access.c31
-rw-r--r--lib/unistd.in.h22
-rw-r--r--m4/access.m416
-rw-r--r--m4/unistd_h.m410
-rw-r--r--modules/access28
-rw-r--r--modules/unistd4
-rw-r--r--tests/test-unistd-c++.cc4
9 files changed, 126 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 84d9508c1c..b85c3ddea6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
2019-09-15 Bruno Haible <bruno@clisp.org>
+ access: New module.
+ * lib/unistd.in.h (access): New declaration.
+ * lib/access.c: New file.
+ * m4/access.m4: New file.
+ * m4/unistd_h.m4 (gl_UNISTD_H): Test whether access is declared.
+ (gl_UNISTD_H_DEFAULTS): Initialize GNULIB_ACCESS, REPLACE_ACCESS.
+ * modules/unistd (Makefile.am): Substitute GNULIB_ACCESS,
+ REPLACE_ACCESS.
+ * modules/access: New file.
+ * tests/test-unistd-c++.cc (access): Check signature.
+ * doc/posix-functions/access.texi: Mention the new module.
+
+2019-09-15 Bruno Haible <bruno@clisp.org>
+
fcntl-h: Fix compilation error of creat.c on MSVC.
* lib/fcntl.in.h: Include <io.h> also when __need_system_fcntl_h is
defined.
diff --git a/doc/posix-functions/access.texi b/doc/posix-functions/access.texi
index fe66ae01fc..d9c5006339 100644
--- a/doc/posix-functions/access.texi
+++ b/doc/posix-functions/access.texi
@@ -4,10 +4,13 @@
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/access.html}
-Gnulib module: ---
+Gnulib module: access
Portability problems fixed by Gnulib:
@itemize
+@item
+This function does not support the @code{X_OK} mode on some platforms:
+MSVC 14.
@end itemize
Portability problems not fixed by Gnulib:
diff --git a/lib/access.c b/lib/access.c
new file mode 100644
index 0000000000..210f7f4072
--- /dev/null
+++ b/lib/access.c
@@ -0,0 +1,31 @@
+/* Test the access rights of a file.
+ Copyright (C) 2019 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <unistd.h>
+
+#include <fcntl.h>
+#include <io.h>
+
+int
+access (const char *file, int mode)
+{
+ if ((mode & X_OK) != 0)
+ mode = (mode & ~X_OK) | R_OK;
+ return _access (file, mode);
+}
diff --git a/lib/unistd.in.h b/lib/unistd.in.h
index 032cc933d1..eaf734d9a6 100644
--- a/lib/unistd.in.h
+++ b/lib/unistd.in.h
@@ -253,10 +253,28 @@ _GL_INLINE_HEADER_BEGIN
/* Declare overridden functions. */
-#if defined GNULIB_POSIXCHECK
+#if @GNULIB_ACCESS@
+# if @REPLACE_ACCESS@
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef access
+# define access rpl_access
+# endif
+_GL_FUNCDECL_RPL (access, int, (const char *file, int mode)
+ _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (access, int, (const char *file, int mode));
+# else
+_GL_CXXALIAS_SYS (access, int, (const char *file, int mode));
+# endif
+_GL_CXXALIASWARN (access);
+#elif defined GNULIB_POSIXCHECK
+# undef access
+# if HAVE_RAW_DECL_ACCESS
/* The access() function is a security risk. */
-_GL_WARN_ON_USE (access, "the access function is a security risk - "
+_GL_WARN_ON_USE (access, "access does not always support X_OK - "
+ "use gnulib module access for portability; "
+ "also, this function is a security risk - "
"use the gnulib module faccessat instead");
+# endif
#endif
diff --git a/m4/access.m4 b/m4/access.m4
new file mode 100644
index 0000000000..a718f81c9c
--- /dev/null
+++ b/m4/access.m4
@@ -0,0 +1,16 @@
+# access.m4 serial 1
+dnl Copyright (C) 2019 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_ACCESS],
+[
+ AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+ AC_REQUIRE([AC_CANONICAL_HOST])
+ dnl On native Windows, access (= _access) does not support the X_OK mode.
+ dnl It works by chance on some versions of mingw.
+ case "$host_os" in
+ mingw*) REPLACE_ACCESS=1 ;;
+ esac
+])
diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4
index a3b3905f84..18b7140e59 100644
--- a/m4/unistd_h.m4
+++ b/m4/unistd_h.m4
@@ -1,4 +1,4 @@
-# unistd_h.m4 serial 75
+# unistd_h.m4 serial 76
dnl Copyright (C) 2006-2019 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -41,9 +41,9 @@ AC_DEFUN([gl_UNISTD_H],
# include <io.h>
# endif
#endif
- ]], [chdir chown dup dup2 dup3 environ euidaccess faccessat fchdir fchownat
- fdatasync fsync ftruncate getcwd getdomainname getdtablesize getgroups
- gethostname getlogin getlogin_r getpagesize getpass
+ ]], [access chdir chown dup dup2 dup3 environ euidaccess faccessat fchdir
+ fchownat fdatasync fsync ftruncate getcwd getdomainname getdtablesize
+ getgroups gethostname getlogin getlogin_r getpagesize getpass
getusershell setusershell endusershell
group_member isatty lchown link linkat lseek pipe pipe2 pread pwrite
readlink readlinkat rmdir sethostname sleep symlink symlinkat
@@ -61,6 +61,7 @@ AC_DEFUN([gl_UNISTD_MODULE_INDICATOR],
AC_DEFUN([gl_UNISTD_H_DEFAULTS],
[
+ GNULIB_ACCESS=0; AC_SUBST([GNULIB_ACCESS])
GNULIB_CHDIR=0; AC_SUBST([GNULIB_CHDIR])
GNULIB_CHOWN=0; AC_SUBST([GNULIB_CHOWN])
GNULIB_CLOSE=0; AC_SUBST([GNULIB_CLOSE])
@@ -159,6 +160,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
HAVE_DECL_TTYNAME_R=1; AC_SUBST([HAVE_DECL_TTYNAME_R])
HAVE_OS_H=0; AC_SUBST([HAVE_OS_H])
HAVE_SYS_PARAM_H=0; AC_SUBST([HAVE_SYS_PARAM_H])
+ REPLACE_ACCESS=0; AC_SUBST([REPLACE_ACCESS])
REPLACE_CHOWN=0; AC_SUBST([REPLACE_CHOWN])
REPLACE_CLOSE=0; AC_SUBST([REPLACE_CLOSE])
REPLACE_DUP=0; AC_SUBST([REPLACE_DUP])
diff --git a/modules/access b/modules/access
new file mode 100644
index 0000000000..7434e021ef
--- /dev/null
+++ b/modules/access
@@ -0,0 +1,28 @@
+Description:
+access() function: test the access rights of a file.
+
+Files:
+lib/access.c
+m4/access.m4
+
+Depends-on:
+unistd
+fcntl
+
+configure.ac:
+gl_FUNC_ACCESS
+if test $REPLACE_ACCESS = 1; then
+ AC_LIBOBJ([access])
+fi
+gl_UNISTD_MODULE_INDICATOR([access])
+
+Makefile.am:
+
+Include:
+<unistd.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all
diff --git a/modules/unistd b/modules/unistd
index e29c1ad942..b68029d185 100644
--- a/modules/unistd
+++ b/modules/unistd
@@ -36,6 +36,7 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
-e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
-e 's|@''NEXT_UNISTD_H''@|$(NEXT_UNISTD_H)|g' \
-e 's|@''WINDOWS_64_BIT_OFF_T''@|$(WINDOWS_64_BIT_OFF_T)|g' \
+ -e 's/@''GNULIB_ACCESS''@/$(GNULIB_ACCESS)/g' \
-e 's/@''GNULIB_CHDIR''@/$(GNULIB_CHDIR)/g' \
-e 's/@''GNULIB_CHOWN''@/$(GNULIB_CHOWN)/g' \
-e 's/@''GNULIB_CLOSE''@/$(GNULIB_CLOSE)/g' \
@@ -135,7 +136,8 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
-e 's|@''HAVE_OS_H''@|$(HAVE_OS_H)|g' \
-e 's|@''HAVE_SYS_PARAM_H''@|$(HAVE_SYS_PARAM_H)|g' \
| \
- sed -e 's|@''REPLACE_CHOWN''@|$(REPLACE_CHOWN)|g' \
+ sed -e 's|@''REPLACE_ACCESS''@|$(REPLACE_ACCESS)|g' \
+ -e 's|@''REPLACE_CHOWN''@|$(REPLACE_CHOWN)|g' \
-e 's|@''REPLACE_CLOSE''@|$(REPLACE_CLOSE)|g' \
-e 's|@''REPLACE_DUP''@|$(REPLACE_DUP)|g' \
-e 's|@''REPLACE_DUP2''@|$(REPLACE_DUP2)|g' \
diff --git a/tests/test-unistd-c++.cc b/tests/test-unistd-c++.cc
index e6a6952a5a..8ba7a044a7 100644
--- a/tests/test-unistd-c++.cc
+++ b/tests/test-unistd-c++.cc
@@ -24,6 +24,10 @@
#include "signature.h"
+#if GNULIB_TEST_ACCESS
+SIGNATURE_CHECK (GNULIB_NAMESPACE::access, int, (const char *, int));
+#endif
+
#if GNULIB_TEST_CHDIR
SIGNATURE_CHECK (GNULIB_NAMESPACE::chdir, int, (const char *));
#endif