char const *old_user, char const *old_group,
char const *user, char const *group)
{
- char const *fmt;
- char *old_spec;
- char *spec;
-
if (changed == CH_NOT_APPLIED)
{
printf (_("neither symbolic link %s nor referent has been changed\n"),
return;
}
- spec = user_group_str (user, group);
- old_spec = user_group_str (user ? old_user : NULL,
- group ? old_group : NULL);
+ char *spec = user_group_str (user, group);
+ char *old_spec = user_group_str (user ? old_user : NULL,
+ group ? old_group : NULL);
+ char const *fmt;
switch (changed)
{
case CH_SUCCEEDED:
uid_t uid, gid_t gid,
uid_t required_uid, gid_t required_gid)
{
- enum RCH_status status = RC_ok;
- struct stat st;
- int open_flags = O_NONBLOCK | O_NOCTTY;
- int fd;
-
if (required_uid == (uid_t) -1 && required_gid == (gid_t) -1)
return RC_do_ordinary_chown;
+ int open_flags = O_NONBLOCK | O_NOCTTY;
if (! S_ISREG (orig_st->st_mode))
{
if (S_ISDIR (orig_st->st_mode))
return RC_do_ordinary_chown;
}
- fd = openat (cwd_fd, file, O_RDONLY | open_flags);
+ int fd = openat (cwd_fd, file, O_RDONLY | open_flags);
if (! (0 <= fd
|| (errno == EACCES && S_ISREG (orig_st->st_mode)
&& 0 <= (fd = openat (cwd_fd, file, O_WRONLY | open_flags)))))
return (errno == EACCES ? RC_do_ordinary_chown : RC_error);
+ enum RCH_status status = RC_ok;
+ struct stat st;
if (fstat (fd, &st) != 0)
status = RC_error;
else if (! psame_inode (orig_st, &st))
{
char const *file_full_name = ent->fts_path;
char const *file = ent->fts_accpath;
- struct stat const *file_stats;
- struct stat stat_buf;
bool ok = true;
- bool do_chown;
- bool symlink_changed = true;
switch (ent->fts_info)
{
break;
}
+ bool do_chown;
+ struct stat stat_buf;
+ struct stat const *file_stats;
if (!ok)
{
do_chown = false;
return false;
}
+ bool symlink_changed = true;
if (do_chown)
{
if ( ! chopt->affect_symlink_referent)
while (true)
{
- FTSENT *ent;
+ FTSENT *ent = fts_read (fts);
- ent = fts_read (fts);
if (ent == NULL)
{
if (errno != 0)
{
bool preserve_root = false;
- uid_t uid = -1; /* Specified uid; -1 if not to be changed. */
- gid_t gid = -1; /* Specified gid; -1 if not to be changed. */
-
/* Change the owner (group) of a file only if it has this uid (gid).
-1 means there's no restriction. */
uid_t required_uid = -1;
int dereference = -1;
struct Chown_option chopt;
- bool ok;
- int optc;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
chopt_init (&chopt);
+ int optc;
while ((optc = getopt_long (argc, argv, "HLPRcfhv", long_options, NULL))
!= -1)
{
usage (EXIT_FAILURE);
}
+ uid_t uid = -1; /* Specified uid; -1 if not to be changed. */
+ gid_t gid = -1; /* Specified gid; -1 if not to be changed. */
+
if (reference_file)
{
struct stat ref_stats;
}
bit_flags |= FTS_DEFER_STAT;
- ok = chown_files (argv + optind, bit_flags,
- uid, gid,
- required_uid, required_gid, &chopt);
+ bool ok = chown_files (argv + optind, bit_flags,
+ uid, gid,
+ required_uid, required_gid, &chopt);
main_exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
}