Hi Paul, > similarly for lchmod on non-symlinks.
When I see a new autoconf test that activates an override, in order to guarantee a certain documented behaviour, I like to add a unit test - because in the past we several times had an override that would not have passed the autoconf test either. So I added a unit test for 'lchown', and found that on HP-UX 11.31 the function could not be used because it is not declared. Which leads to these patches: 2020-02-08 Bruno Haible <br...@clisp.org> lchmod: Add tests. * tests/test-lchmod.c: New file. * modules/lchmod-tests: New file. 2020-02-08 Bruno Haible <br...@clisp.org> lchmod: Ensure declaration on HP-UX. * lib/sys_stat.in.h (lchown): Declare also on HP-UX. * doc/glibc-functions/lchmod.texi: Mention the HP-UX problem.
>From d863fc54623c497e0ed51fb0d7011415dc943434 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sat, 8 Feb 2020 21:22:15 +0100 Subject: [PATCH 1/2] lchmod: Ensure declaration on HP-UX. * lib/sys_stat.in.h (lchown): Declare also on HP-UX. * doc/glibc-functions/lchmod.texi: Mention the HP-UX problem. --- ChangeLog | 6 ++++++ doc/glibc-functions/lchmod.texi | 3 +++ lib/sys_stat.in.h | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index fc07914..ffb2096 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2020-02-08 Bruno Haible <br...@clisp.org> + lchmod: Ensure declaration on HP-UX. + * lib/sys_stat.in.h (lchown): Declare also on HP-UX. + * doc/glibc-functions/lchmod.texi: Mention the HP-UX problem. + +2020-02-08 Bruno Haible <br...@clisp.org> + fchmodat: Strengthen tests. * tests/test-fchmodat.c (BASE): New macro. (main): Use it, to avoid conflicts with other unit tests. Verify that diff --git a/doc/glibc-functions/lchmod.texi b/doc/glibc-functions/lchmod.texi index 6cc48b4..7a2e9d0 100644 --- a/doc/glibc-functions/lchmod.texi +++ b/doc/glibc-functions/lchmod.texi @@ -10,6 +10,9 @@ Portability problems fixed by Gnulib: This function is missing on some platforms: OpenBSD 3.8, Minix 3.1.8, AIX 5.1, IRIX 6.5, Solaris 11.4, Cygwin, mingw, MSVC 14, Android 9.0. @item +This function is not declared on some platforms: +HP-UX 11.31. +@item This function always fails with @code{errno} set to @code{ENOSYS}, even when the file is not a symbolic link: GNU/Linux with glibc 2.31. diff --git a/lib/sys_stat.in.h b/lib/sys_stat.in.h index 4f9eb59..65661f4 100644 --- a/lib/sys_stat.in.h +++ b/lib/sys_stat.in.h @@ -525,7 +525,7 @@ _GL_FUNCDECL_RPL (lchmod, int, _GL_CXXALIAS_RPL (lchmod, int, (char const *filename, mode_t mode)); # else -# if !@HAVE_LCHMOD@ +# if !@HAVE_LCHMOD@ || defined __hpux _GL_FUNCDECL_SYS (lchmod, int, (const char *filename, mode_t mode) _GL_ARG_NONNULL ((1))); # endif -- 2.7.4
>From 8cc34c349afc79e2728093e109a09f9f0aaa4b50 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sat, 8 Feb 2020 21:24:35 +0100 Subject: [PATCH 2/2] lchmod: Add tests. * tests/test-lchmod.c: New file. * modules/lchmod-tests: New file. --- ChangeLog | 6 +++++ modules/lchmod-tests | 13 ++++++++++ tests/test-lchmod.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 modules/lchmod-tests create mode 100644 tests/test-lchmod.c diff --git a/ChangeLog b/ChangeLog index ffb2096..a4ee3dd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2020-02-08 Bruno Haible <br...@clisp.org> + lchmod: Add tests. + * tests/test-lchmod.c: New file. + * modules/lchmod-tests: New file. + +2020-02-08 Bruno Haible <br...@clisp.org> + lchmod: Ensure declaration on HP-UX. * lib/sys_stat.in.h (lchown): Declare also on HP-UX. * doc/glibc-functions/lchmod.texi: Mention the HP-UX problem. diff --git a/modules/lchmod-tests b/modules/lchmod-tests new file mode 100644 index 0000000..cbb2537 --- /dev/null +++ b/modules/lchmod-tests @@ -0,0 +1,13 @@ +Files: +tests/test-lchmod.c +tests/signature.h +tests/macros.h + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-lchmod +check_PROGRAMS += test-lchmod +test_lchmod_LDADD = $(LDADD) @LIBINTL@ diff --git a/tests/test-lchmod.c b/tests/test-lchmod.c new file mode 100644 index 0000000..783e608 --- /dev/null +++ b/tests/test-lchmod.c @@ -0,0 +1,67 @@ +/* Test changing the protections of a file. + Copyright (C) 2020 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> + +#include <sys/stat.h> + +#include "signature.h" +SIGNATURE_CHECK (lchmod, int, (const char *, mode_t)); + +#include <errno.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <unistd.h> + +#include "macros.h" + +#define BASE "test-lchmod." + +int +main (void) +{ + /* Test that lchmod works on non-symlinks. */ + { + struct stat statbuf; + unlink (BASE "file"); + ASSERT (close (creat (BASE "file", 0600)) == 0); + ASSERT (lchmod (BASE "file", 0400) == 0); + ASSERT (stat (BASE "file", &statbuf) >= 0); + ASSERT ((statbuf.st_mode & 0700) == 0400); + /* Clean up. */ + ASSERT (chmod (BASE "file", 0600) == 0); + ASSERT (unlink (BASE "file") == 0); + } + + /* Test that lchmod on symlinks does not modify the symlink target. */ + { + unlink (BASE "file"); + unlink (BASE "link"); + if (symlink (BASE "file", BASE "link") == 0) + { + struct stat statbuf; + ASSERT (close (creat (BASE "file", 0600)) == 0); + lchmod (BASE "link", 0400); + ASSERT (stat (BASE "file", &statbuf) >= 0); + ASSERT ((statbuf.st_mode & 0700) == 0600); + } + /* Clean up. */ + unlink (BASE "file"); + unlink (BASE "link"); + } + + return 0; +} -- 2.7.4