summaryrefslogtreecommitdiff
path: root/src/chmod.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1993-10-17 22:43:10 +0000
committerJim Meyering <jim@meyering.net>1993-10-17 22:43:10 +0000
commit214c19a8b32d2ed5dd3b0b57eea84c709720c753 (patch)
tree9ed7bb495b774417c7f9738e208e532a7969004d /src/chmod.c
parent1958250cc66bf2ec89193bff8b27b73ce5765fc7 (diff)
downloadcoreutils-214c19a8b32d2ed5dd3b0b57eea84c709720c753.tar.xz
merge with 3.8.4g
Diffstat (limited to 'src/chmod.c')
-rw-r--r--src/chmod.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/chmod.c b/src/chmod.c
index f1e4738ff..5236cb140 100644
--- a/src/chmod.c
+++ b/src/chmod.c
@@ -176,18 +176,21 @@ main (argc, argv)
error (1, 0, "virtual memory exhausted");
for (; optind < argc; ++optind)
- errors |= change_file_mode (argv[optind], changes);
+ errors |= change_file_mode (argv[optind], changes, 1);
exit (errors);
}
/* Change the mode of FILE according to the list of operations CHANGES.
- Return 0 if successful, 1 if errors occurred. */
+ If DEREF_SYMLINK is non-zero and FILE is a symbolic link, change the
+ mode of the referenced file. If DEREF_SYMLINK is zero, ignore symbolic
+ links. Return 0 if successful, 1 if errors occurred. */
static int
-change_file_mode (file, changes)
+change_file_mode (file, changes, deref_symlink)
char *file;
struct mode_change *changes;
+ int deref_symlink;
{
struct stat file_stats;
unsigned short newmode;
@@ -201,7 +204,15 @@ change_file_mode (file, changes)
}
#ifdef S_ISLNK
if (S_ISLNK (file_stats.st_mode))
- return 0;
+ if (! deref_symlink)
+ return 0;
+ else
+ if (stat (file, &file_stats))
+ {
+ if (force_silent == 0)
+ error (0, errno, "%s", file);
+ return 1;
+ }
#endif
newmode = mode_adjust (file_stats.st_mode, changes);
@@ -273,7 +284,7 @@ change_dir_mode (dir, changes, statp)
path = xrealloc (path, pathlength);
}
strcpy (path + dirlength, namep);
- errors |= change_file_mode (path, changes);
+ errors |= change_file_mode (path, changes, 0);
}
free (path);
free (name_space);