]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(xstat): New global.
authorJim Meyering <jim@meyering.net>
Sun, 7 Nov 1999 20:18:11 +0000 (20:18 +0000)
committerJim Meyering <jim@meyering.net>
Sun, 7 Nov 1999 20:18:11 +0000 (20:18 +0000)
(main): Define it.
(change_file_group): Use it.  Before this change, when running chgrp
on a symlink without --dereference (-h) and when the requested group
is the same as the group for the *symlink*, chgrp would do nothing.
Now it changes the group of the file referenced through the symlink.
Reported by Martin Mitchell.

src/chgrp.c

index 82f3ad0e46c8a5295de23f8b5ab1604138c192c1..52bb78ed01a9115311582d6292ffde81e1b2b4ca 100644 (file)
@@ -81,6 +81,10 @@ char *program_name;
    of symbolic links rather than any files they point to.  */
 static int change_symlinks = 1;
 
+/* When change_symlinks is set, this should be set to `lstat', otherwise,
+   it should be `stat'.  */
+static int (*xstat) ();
+
 /* If nonzero, change the ownership of directories recursively. */
 static int recurse;
 
@@ -196,7 +200,7 @@ change_file_group (int cmdline_arg, const char *file, gid_t group)
   struct stat file_stats;
   int errors = 0;
 
-  if (lstat (file, &file_stats))
+  if ((*xstat) (file, &file_stats))
     {
       if (force_silent == 0)
        error (0, errno, "%s", file);
@@ -409,6 +413,11 @@ main (int argc, char **argv)
       usage (1);
     }
 
+  if (change_symlinks)
+    xstat = lstat;
+  else
+    xstat = stat;
+
   if (reference_file)
     {
       struct stat ref_stats;