Paul Eggert wrote: >Derek Price <[EMAIL PROTECTED]> writes: > > > >>What does this mean for Bruno's recent patch for stat & lstat which >>removed the SunOS 4.1.4 support in addition to some other fixes? >> >> > >His patch made sense to me, but as far as I know nobody has taken the >time to integrate the comments on it and try it out. Here's what I >see so far: > >
I've attached a revised patch. In addition to integrating the suggestions Bruno's patch received, it also includes changes to modules/lstat, config/srclist.txt, and MODULES.html.sh. In addition to this patch, lib/stat.c, m4/stat.m4, and modules/stat need to be removed. It appears to work installed in CVS on Linux, but that only tests the modules file and macro, not the C source or header files. Cheers, Derek
Index: MODULES.html.sh =================================================================== RCS file: /cvsroot/gnulib/gnulib/MODULES.html.sh,v retrieving revision 1.88 diff -u -p -r1.88 MODULES.html.sh --- MODULES.html.sh 2 Jun 2005 20:41:04 -0000 1.88 +++ MODULES.html.sh 7 Jun 2005 14:46:02 -0000 @@ -1063,7 +1063,6 @@ srand srand48 srandom sscanf -stat statvfs stdin strcasecmp @@ -1756,7 +1755,6 @@ func_all_modules () func_module mkdtemp func_module poll func_module readlink - func_module stat func_module lstat func_module time_r func_module timespec Index: config/srclist.txt =================================================================== RCS file: /cvsroot/gnulib/gnulib/config/srclist.txt,v retrieving revision 1.63 diff -u -p -r1.63 srclist.txt --- config/srclist.txt 29 May 2005 16:56:02 -0000 1.63 +++ config/srclist.txt 7 Jun 2005 14:46:02 -0000 @@ -143,7 +143,6 @@ $LIBCSRC/sysdeps/generic/memmem.c lib gp # # These implementations are quite different. #$LIBCSRC/io/lstat.c lib gpl -#$LIBCSRC/io/stat.c lib gpl #$LIBCSRC/libio/__fpending.c lib gpl #$LIBCSRC/malloc/malloc.c lib gpl #$LIBCSRC/misc/dirname.c lib gpl Index: lib/lstat.c =================================================================== RCS file: /cvsroot/gnulib/gnulib/lib/lstat.c,v retrieving revision 1.7 diff -u -p -r1.7 lstat.c --- lib/lstat.c 14 May 2005 06:03:58 -0000 1.7 +++ lib/lstat.c 7 Jun 2005 14:46:02 -0000 @@ -1,8 +1,6 @@ -/* Work around the bug in some systems whereby lstat succeeds when - given the zero-length file name argument. The lstat from SunOS 4.1.4 - has this bug. +/* Work around a bug of lstat on some systems - Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free + Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify @@ -19,5 +17,59 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#define LSTAT -#include "stat.c" +/* written by Jim Meyering */ + +#include <config.h> + +/* The specification of these functions is in sys_stat.h. But we cannot + include this include file here, because on some systems, a + "#define lstat lstat64" is being used, and sys_stat.h deletes this + definition. */ + +#include <sys/types.h> +#include <sys/stat.h> +#include <stdlib.h> +#include <string.h> + +#include "stat-macros.h" +#include "xalloc.h" + +/* lstat works differently on Linux and Solaris systems. POSIX (see + `pathname resolution' in the glossary) requires that programs like `ls' + take into consideration the fact that FILE has a trailing slash when + FILE is a symbolic link. On Linux systems, the lstat function already + has the desired semantics (in treating `lstat("symlink/",sbuf)' just like + `lstat("symlink/.",sbuf)', but on Solaris it does not. + + If FILE has a trailing slash and specifies a symbolic link, + then append a `.' to FILE and call lstat a second time. */ + +int +rpl_lstat (const char *file, struct stat *sbuf) +{ + size_t len; + char *new_file; + + int lstat_result = lstat (file, sbuf); + + if (lstat_result != 0 || !S_ISLNK (sbuf->st_mode)) + return lstat_result; + + len = strlen (file); + if (len == 0 || file[len - 1] != '/') + return lstat_result; + + /* FILE refers to a symbolic link and the name ends with a slash. + Append a `.' to FILE and repeat the lstat call. */ + + /* Add one for the `.' we'll append, and one more for the trailing NUL. */ + new_file = xmalloc (len + 1 + 1); + memcpy (new_file, file, len); + new_file[len] = '.'; + new_file[len + 1] = 0; + + lstat_result = lstat (new_file, sbuf); + free (new_file); + + return lstat_result; +} Index: lib/lstat.h =================================================================== RCS file: lib/lstat.h diff -N lib/lstat.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/lstat.h 7 Jun 2005 14:46:02 -0000 @@ -0,0 +1,24 @@ +/* Retrieving information about files. + 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 2, 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, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include <sys/stat.h> + +#if !LSTAT_FOLLOWS_SLASHED_SYMLINK +extern int rpl_lstat (const char *name, struct stat *buf); +# undef lstat +# define lstat rpl_lstat +#endif Index: m4/lstat.m4 =================================================================== RCS file: /cvsroot/gnulib/gnulib/m4/lstat.m4,v retrieving revision 1.20 diff -u -p -r1.20 lstat.m4 --- m4/lstat.m4 2 May 2005 07:00:50 -0000 1.20 +++ m4/lstat.m4 7 Jun 2005 14:46:02 -0000 @@ -18,7 +18,7 @@ dnl AC_DEFUN([gl_FUNC_LSTAT], [ - AC_REQUIRE([AC_FUNC_LSTAT]) - dnl Note: AC_FUNC_LSTAT does AC_LIBOBJ(lstat). + AC_REQUIRE([AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK]) + dnl Note: AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK does AC_LIBOBJ(lstat). : ]) Index: modules/lstat =================================================================== RCS file: /cvsroot/gnulib/gnulib/modules/lstat,v retrieving revision 1.6 diff -u -p -r1.6 lstat --- modules/lstat 2 May 2005 07:00:50 -0000 1.6 +++ modules/lstat 7 Jun 2005 14:46:02 -0000 @@ -1,12 +1,14 @@ Description: -stat() function: return information about a file or symbolic link. +lstat() function: return information about a file or symbolic link. Files: lib/lstat.c +lib/lstat.h m4/lstat.m4 Depends-on: -stat +xalloc +stat-macros configure.ac: gl_FUNC_LSTAT @@ -14,7 +16,7 @@ gl_FUNC_LSTAT Makefile.am: Include: -<sys/stat.h> +"lstat.h" License: GPL
_______________________________________________ bug-gnulib mailing list bug-gnulib@gnu.org http://lists.gnu.org/mailman/listinfo/bug-gnulib