bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

various minor fixes in porting to Solaris 8


From: Paul Eggert
Subject: various minor fixes in porting to Solaris 8
Date: Sun, 03 Jul 2005 02:40:46 -0700
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

I had problem with lstat on Solaris 8 (link failures), so I installed
the latest gnulib lstat module, which fixed it.

There is still a problem that that configure thinks the Sun C compiler
supports __typeof__, but the support is only partial.  I'll try to
come up with a test case for that tomorrow.

2005-07-03  Paul Eggert  <address@hidden>

        * lib/fts.c [! _LIBC]: Include "lstat.h" rather than rolling our own.
        * lib/lstat.c: Sync from gnulib.
        * lib/lstat.h: New file, from gnulib.
        * lib/stat.c: Remove.

        * m4/fts.m4 (gl_FUNC_FTS_CORE): Don't require
        AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK; that's now the lstat
        module's job.
        * m4/jm-macros.m4 (gl_MACROS): Likewise.
        * m4/prereq.m4 (gl_PREREQ): Add gl_FUNC_LSTAT.

        * src/copy.h: Include "lstat.h" rather than rolling our own.
        * src/ls.c: Likewise.
        * src/remove.c: Likewise.


Index: lib/fts.c
===================================================================
RCS file: /fetish/cu/lib/fts.c,v
retrieving revision 1.35
diff -p -u -r1.35 fts.c
--- lib/fts.c   3 Jul 2005 07:14:05 -0000       1.35
+++ lib/fts.c   3 Jul 2005 09:22:16 -0000
@@ -71,6 +71,10 @@ static char sccsid[] = "@(#)fts.c    8.6 (B
 #include <string.h>
 #include <unistd.h>
 
+#if ! _LIBC
+# include "lstat.h"
+#endif
+
 #if defined _LIBC
 # include <dirent.h>
 # define NAMLEN(dirent) _D_EXACT_NAMLEN (dirent)
@@ -111,15 +115,6 @@ static char sccsid[] = "@(#)fts.c  8.6 (B
 # define internal_function /* empty */
 #endif
 
-/* Arrange to make lstat calls go through the wrapper function
-   on systems with an lstat function that does not dereference symlinks
-   that are specified with a trailing slash.  */
-#if ! _LIBC && ! LSTAT_FOLLOWS_SLASHED_SYMLINK
-int rpl_lstat (const char *, struct stat *);
-# undef lstat
-# define lstat(Name, Stat_buf) rpl_lstat(Name, Stat_buf)
-#endif
-
 #ifndef __set_errno
 # define __set_errno(Val) errno = (Val)
 #endif
Index: lib/lstat.c
===================================================================
RCS file: /fetish/cu/lib/lstat.c,v
retrieving revision 1.8
diff -p -u -r1.8 lstat.c
--- lib/lstat.c 14 May 2005 07:58:06 -0000      1.8
+++ lib/lstat.c 3 Jul 2005 09:22:16 -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: m4/fts.m4
===================================================================
RCS file: /fetish/cu/m4/fts.m4,v
retrieving revision 1.7
diff -p -u -r1.7 fts.m4
--- m4/fts.m4   28 May 2005 00:01:00 -0000      1.7
+++ m4/fts.m4   3 Jul 2005 09:22:16 -0000
@@ -31,7 +31,4 @@ AC_DEFUN([gl_FUNC_FTS_CORE],
   # Checks for header files.
   AC_REQUIRE([AC_HEADER_DIRENT])
   AC_CHECK_HEADERS_ONCE([sys/param.h])
-
-  # Checks for library functions.
-  AC_REQUIRE([AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
 ])
Index: m4/jm-macros.m4
===================================================================
RCS file: /fetish/cu/m4/jm-macros.m4,v
retrieving revision 1.223
diff -p -u -r1.223 jm-macros.m4
--- m4/jm-macros.m4     1 Jul 2005 21:06:08 -0000       1.223
+++ m4/jm-macros.m4     3 Jul 2005 09:22:16 -0000
@@ -55,7 +55,6 @@ AC_DEFUN([gl_MACROS],
   AC_REQUIRE([gl_FUNC_RMDIR_NOTEMPTY])
   AC_REQUIRE([gl_FUNC_CHOWN])
   AC_REQUIRE([AC_FUNC_LSTAT])
-  AC_REQUIRE([AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
   AC_REQUIRE([AC_FUNC_STRERROR_R])
   AC_REQUIRE([gl_FUNC_GROUP_MEMBER])
   AC_REQUIRE([gl_AFS])
Index: m4/prereq.m4
===================================================================
RCS file: /fetish/cu/m4/prereq.m4,v
retrieving revision 1.115
diff -p -u -r1.115 prereq.m4
--- m4/prereq.m4        3 Jul 2005 07:15:58 -0000       1.115
+++ m4/prereq.m4        3 Jul 2005 09:22:16 -0000
@@ -61,6 +61,7 @@ AC_DEFUN([gl_PREREQ],
   AC_REQUIRE([AC_FUNC_GETLOADAVG])
   AC_REQUIRE([gl_FUNC_GETPASS])
   AC_REQUIRE([gl_FUNC_GETUSERSHELL])
+  AC_REQUIRE([gl_FUNC_LSTAT])
   AC_REQUIRE([gl_FUNC_MEMCHR])
   AC_REQUIRE([gl_FUNC_MEMCPY])
   AC_REQUIRE([gl_FUNC_MEMMOVE])
Index: src/copy.h
===================================================================
RCS file: /fetish/cu/src/copy.h,v
retrieving revision 1.33
diff -p -u -r1.33 copy.h
--- src/copy.h  2 Jun 2005 05:17:24 -0000       1.33
+++ src/copy.h  3 Jul 2005 09:22:16 -0000
@@ -22,6 +22,7 @@
 
 # include <stdbool.h>
 # include "hash.h"
+# include "lstat.h"
 
 /* Control creation of sparse files (files with holes).  */
 enum Sparse_type
@@ -197,15 +198,6 @@ struct cp_options
    ? lstat (Src_name, Src_sb) \
    : stat (Src_name, Src_sb))
 
-/* Arrange to make lstat calls go through the wrapper function
-   on systems with an lstat function that does not dereference symlinks
-   that are specified with a trailing slash.  */
-# if ! LSTAT_FOLLOWS_SLASHED_SYMLINK
-int rpl_lstat (const char *, struct stat *);
-#  undef lstat
-#  define lstat rpl_lstat
-# endif
-
 /* Arrange to make rename calls go through the wrapper function
    on systems with a rename function that fails for a source file name
    specified with a trailing slash.  */
Index: src/ls.c
===================================================================
RCS file: /fetish/cu/src/ls.c,v
retrieving revision 1.391
diff -p -u -r1.391 ls.c
--- src/ls.c    30 Jun 2005 16:47:58 -0000      1.391
+++ src/ls.c    3 Jul 2005 09:22:17 -0000
@@ -115,6 +115,7 @@ int wcwidth ();
 #include "filemode.h"
 #include "inttostr.h"
 #include "ls.h"
+#include "lstat.h"
 #include "mbswidth.h"
 #include "obstack.h"
 #include "quote.h"
@@ -138,15 +139,6 @@ int wcwidth ();
    Subtracting doesn't always work, due to overflow.  */
 #define longdiff(a, b) ((a) < (b) ? -1 : (a) > (b))
 
-/* Arrange to make lstat calls go through the wrapper function
-   on systems with an lstat function that does not dereference symlinks
-   that are specified with a trailing slash.  */
-#if ! LSTAT_FOLLOWS_SLASHED_SYMLINK
-int rpl_lstat (const char *, struct stat *);
-# undef lstat
-# define lstat(Name, Stat_buf) rpl_lstat(Name, Stat_buf)
-#endif
-
 #if HAVE_STRUCT_DIRENT_D_TYPE && defined DTTOIF
 # define DT_INIT(Val) = Val
 #else
Index: src/remove.c
===================================================================
RCS file: /fetish/cu/src/remove.c,v
retrieving revision 1.128
diff -p -u -r1.128 remove.c
--- src/remove.c        2 Jun 2005 05:17:24 -0000       1.128
+++ src/remove.c        3 Jul 2005 09:22:17 -0000
@@ -32,6 +32,7 @@
 #include "file-type.h"
 #include "hash.h"
 #include "hash-pjw.h"
+#include "lstat.h"
 #include "obstack.h"
 #include "quote.h"
 #include "remove.h"
@@ -78,13 +79,6 @@ enum Prompt_action
     PA_REMOVE_DIR
   };
 
-/* On systems with an lstat function that accepts the empty string,
-   arrange to make lstat calls go through the wrapper function.  */
-#if HAVE_LSTAT_EMPTY_STRING_BUG
-int rpl_lstat (const char *, struct stat *);
-# define lstat(Name, Stat_buf) rpl_lstat(Name, Stat_buf)
-#endif
-
 /* Initial capacity of per-directory hash table of entries that have
    been processed but not been deleted.  */
 #define HT_UNREMOVABLE_INITIAL_CAPACITY 13




reply via email to

[Prev in Thread] Current Thread [Next in Thread]