>From 265886a27c8bc637b1e1f3e85e68d594bbe5fa2c Mon Sep 17 00:00:00 2001
From: Bruno Haible
Date: Sun, 15 Sep 2019 18:56:46 +0200
Subject: [PATCH 1/3] 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.
---
ChangeLog | 14 ++++++++++++++
doc/posix-functions/access.texi | 5 ++++-
lib/access.c | 31 +++++++++++++++++++++++++++++++
lib/unistd.in.h | 22 ++++++++++++++++++++--
m4/access.m4 | 16 ++++++++++++++++
m4/unistd_h.m4 | 10 ++++++----
modules/access | 28 ++++++++++++++++++++++++++++
modules/unistd | 4 +++-
tests/test-unistd-c++.cc | 4 ++++
9 files changed, 126 insertions(+), 8 deletions(-)
create mode 100644 lib/access.c
create mode 100644 m4/access.m4
create mode 100644 modules/access
diff --git a/ChangeLog b/ChangeLog
index 84d9508..b85c3dd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
2019-09-15 Bruno Haible
+ 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
+
fcntl-h: Fix compilation error of creat.c on MSVC.
* lib/fcntl.in.h: Include also when __need_system_fcntl_h is
defined.
diff --git a/doc/posix-functions/access.texi b/doc/posix-functions/access.texi
index fe66ae0..d9c5006 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 0000000..210f7f4
--- /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 . */
+
+#include
+
+/* Specification. */
+#include
+
+#include
+#include
+
+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 032cc93..eaf734d 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 0000000..a718f81
--- /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 a3b3905..18b7140 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
# 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 0000000..7434e02
--- /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:
+
+
+License:
+LGPLv2+
+
+Maintainer:
+all
diff --git a/modules/unistd b/modules/unistd
index e29c1ad..b68029d 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 e6a6952..8ba7a04 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
--
2.7.4