glibc and the BSD systems declare lchmod() in <sys/stat.h>. Therefore gnulib should do the same. Here's a proposed patch to that effect.
2008-10-18 Bruno Haible <[EMAIL PROTECTED]> * lib/dirchownmod.c: Don't include lchmod.h. * lib/lchmod.h: Remove file. * lib/sys_stat.in.h: Add placeholder for GL_LINK_WARNING. (lchmod): New declaration, moved here from lib/lchown.h. * m4/lchmod.m4 (gl_FUNC_LCHMOD): Require gl_SYS_STAT_H_DEFAULTS and AC_USE_SYSTEM_EXTENSIONS. Set HAVE_LCHMOD. * m4/sys_stat_h.m4 (gl_SYS_STAT_H_DEFAULTS): Initialize GNULIB_LCHMOD and HAVE_LCHMOD. * modules/lchmod (Files): Remove lib/lchmod.h. (Depends-on): Add sys_stat, extensions. (configure.ac): Invoke gl_SYS_STAT_MODULE_INDICATOR. (Include): Specify <sys/stat.h> instead of lchmod.h. * modules/sys_stat (Depends-on): Add link-warning. (Makefile.am): Substitute GNULIB_LCHMOD, HAVE_LCHMOD, and the definition of GL_LINK_WARNING. * NEWS: Mention the change. --- lib/lchmod.h.orig 2008-10-19 04:11:13.000000000 +0200 +++ lib/lchmod.h 2003-09-23 19:59:22.000000000 +0200 @@ -1,34 +0,0 @@ -/* Provide a replacement for lchmod on hosts that lack it. - - Copyright (C) 2005 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 <http://www.gnu.org/licenses/>. */ - -/* Written by Paul Eggert. */ - -#include <sys/types.h> -#include <sys/stat.h> - -#ifndef HAVE_LCHMOD - -/* The lchmod replacement follows symbolic links. Callers should take - this into account; lchmod should be applied only to arguments that - are known to not be symbolic links. On hosts that lack lchmod, - this can lead to race conditions between the check and the - invocation of lchmod, but we know of no workarounds that are - reliable in general. You might try requesting support for lchmod - from your operating system supplier. */ - -# define lchmod chmod -#endif --- lib/sys_stat.in.h.orig 2008-10-19 04:11:13.000000000 +0200 +++ lib/sys_stat.in.h 2008-10-19 04:10:38.000000000 +0200 @@ -1,5 +1,5 @@ /* Provide a more complete sys/stat header file. - Copyright (C) 2006-2008 Free Software Foundation, Inc. + Copyright (C) 2005-2008 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 @@ -33,6 +33,8 @@ #ifndef _GL_SYS_STAT_H #define _GL_SYS_STAT_H +/* The definition of GL_LINK_WARNING is copied here. */ + /* Before doing "#define mkdir rpl_mkdir" below, we need to include all headers that may declare mkdir(). */ #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ @@ -291,5 +293,32 @@ # endif #endif + +/* Declare BSD extensions. */ + +#if @GNULIB_LCHMOD@ +/* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME + denotes a symbolic link. */ +# if [EMAIL PROTECTED]@ +/* The lchmod replacement follows symbolic links. Callers should take + this into account; lchmod should be applied only to arguments that + are known to not be symbolic links. On hosts that lack lchmod, + this can lead to race conditions between the check and the + invocation of lchmod, but we know of no workarounds that are + reliable in general. You might try requesting support for lchmod + from your operating system supplier. */ +# define lchmod chmod +# endif +# if 0 /* assume already declared */ +extern int lchmod (const char *filename, mode_t mode); +# endif +#elif defined GNULIB_POSIXCHECK +# undef lchmod +# define lchmod(f,m) \ + (GL_LINK_WARNING ("lchmod is unportable - " \ + "use gnulib module lchmod for portability"), \ + lchmod (f, m)) +#endif + #endif /* _GL_SYS_STAT_H */ #endif /* _GL_SYS_STAT_H */ --- m4/lchmod.m4.orig 2008-10-19 04:11:13.000000000 +0200 +++ m4/lchmod.m4 2008-10-19 04:04:44.000000000 +0200 @@ -1,6 +1,6 @@ -#serial 2 +#serial 3 -dnl Copyright (C) 2005, 2006 Free Software Foundation, Inc. +dnl Copyright (C) 2005, 2006, 2008 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. @@ -10,5 +10,13 @@ AC_DEFUN([gl_FUNC_LCHMOD], [ + AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS]) + + dnl Persuade glibc <sys/stat.h> to declare lchmod(). + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + AC_CHECK_FUNCS_ONCE([lchmod]) + if test $ac_cv_func_lchmod = no; then + HAVE_LCHMOD=0 + fi ]) --- m4/sys_stat_h.m4.orig 2008-10-19 04:11:13.000000000 +0200 +++ m4/sys_stat_h.m4 2008-10-19 04:05:26.000000000 +0200 @@ -1,4 +1,4 @@ -# sys_stat_h.m4 serial 8 -*- Autoconf -*- +# sys_stat_h.m4 serial 9 -*- Autoconf -*- dnl Copyright (C) 2006-2008 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -50,6 +50,8 @@ AC_DEFUN([gl_SYS_STAT_H_DEFAULTS], [ + GNULIB_LCHMOD=0; AC_SUBST([GNULIB_LCHMOD]) dnl Assume proper GNU behavior unless another module says otherwise. + HAVE_LCHMOD=1; AC_SUBST([HAVE_LCHMOD]) REPLACE_MKDIR=0; AC_SUBST([REPLACE_MKDIR]) ]) --- modules/lchmod.orig 2008-10-19 04:11:13.000000000 +0200 +++ modules/lchmod 2008-10-19 04:04:50.000000000 +0200 @@ -2,18 +2,20 @@ lchmod that is actually chmod (!) on hosts lacking lchmod Files: -lib/lchmod.h m4/lchmod.m4 Depends-on: +sys_stat +extensions configure.ac: gl_FUNC_LCHMOD +gl_SYS_STAT_MODULE_INDICATOR([lchmod]) Makefile.am: Include: -"lchmod.h" +<sys/stat.h> License: GPL --- modules/sys_stat.orig 2008-10-19 04:11:14.000000000 +0200 +++ modules/sys_stat 2008-10-19 03:59:50.000000000 +0200 @@ -7,6 +7,7 @@ Depends-on: include_next +link-warning configure.ac: gl_HEADER_SYS_STAT_H @@ -24,8 +25,11 @@ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ -e 's|@''NEXT_SYS_STAT_H''@|$(NEXT_SYS_STAT_H)|g' \ + -e 's|@''GNULIB_LCHMOD''@|$(GNULIB_LCHMOD)|g' \ + -e 's|@''HAVE_LCHMOD''@|$(HAVE_LCHMOD)|g' \ -e 's|@''HAVE_LSTAT''@|$(HAVE_LSTAT)|g' \ -e 's|@''REPLACE_MKDIR''@|$(REPLACE_MKDIR)|g' \ + -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ < $(srcdir)/sys_stat.in.h; \ } > [EMAIL PROTECTED] mv [EMAIL PROTECTED] $@ --- NEWS.orig 2008-10-19 04:11:13.000000000 +0200 +++ NEWS 2008-10-19 03:58:48.000000000 +0200 @@ -6,6 +6,9 @@ Date Modules Changes +2008-10-18 lchmod The include file is changed from "lchmod.h" to + <sys/stat.h>. + 2008-09-28 sockets When using this module, you now need to link with $(LIBSOCKET). --- lib/dirchownmod.c.orig 2008-10-19 04:11:13.000000000 +0200 +++ lib/dirchownmod.c 2008-10-19 04:06:26.000000000 +0200 @@ -1,6 +1,6 @@ /* Change the ownership and mode bits of a directory. - Copyright (C) 2006, 2007 Free Software Foundation, Inc. + Copyright (C) 2006, 2007, 2008 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 @@ -26,7 +26,6 @@ #include <sys/stat.h> #include <unistd.h> -#include "lchmod.h" #include "stat-macros.h" #ifndef HAVE_FCHMOD