/* modechange.c -- file mode manipulation
- Copyright (C) 1989, 1990, 1997, 1998, 1999 Free Software Foundation, Inc.
+
+ Copyright (C) 1989, 1990, 1997, 1998, 1999, 2001, 2003, 2004 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
#include "modechange.h"
#include <sys/stat.h>
#include "xstrtol.h"
-
-#if STDC_HEADERS
-# include <stdlib.h>
-#else
-char *malloc ();
-#endif
-
-#ifndef NULL
-# define NULL 0
-#endif
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdlib.h>
#if STAT_MACROS_BROKEN
# undef S_ISDIR
&& S_IRGRP == RGRP && S_IWGRP == WGRP && S_IXGRP == XGRP
&& S_IROTH == ROTH && S_IWOTH == WOTH && S_IXOTH == XOTH)
? octal_value
- : ((octal_value & SUID ? S_ISUID : 0)
- | (octal_value & SGID ? S_ISGID : 0)
- | (octal_value & SVTX ? S_ISVTX : 0)
- | (octal_value & RUSR ? S_IRUSR : 0)
- | (octal_value & WUSR ? S_IWUSR : 0)
- | (octal_value & XUSR ? S_IXUSR : 0)
- | (octal_value & RGRP ? S_IRGRP : 0)
- | (octal_value & WGRP ? S_IWGRP : 0)
- | (octal_value & XGRP ? S_IXGRP : 0)
- | (octal_value & ROTH ? S_IROTH : 0)
- | (octal_value & WOTH ? S_IWOTH : 0)
- | (octal_value & XOTH ? S_IXOTH : 0)));
+ : (mode_t) ((octal_value & SUID ? S_ISUID : 0)
+ | (octal_value & SGID ? S_ISGID : 0)
+ | (octal_value & SVTX ? S_ISVTX : 0)
+ | (octal_value & RUSR ? S_IRUSR : 0)
+ | (octal_value & WUSR ? S_IWUSR : 0)
+ | (octal_value & XUSR ? S_IXUSR : 0)
+ | (octal_value & RGRP ? S_IRGRP : 0)
+ | (octal_value & WGRP ? S_IWGRP : 0)
+ | (octal_value & XGRP ? S_IXGRP : 0)
+ | (octal_value & ROTH ? S_IROTH : 0)
+ | (octal_value & WOTH ? S_IWOTH : 0)
+ | (octal_value & XOTH ? S_IXOTH : 0)));
p = make_node_op_equals (mode);
if (p == NULL)
/* `affected_bits' modified by umask. */
mode_t affected_masked;
/* Operators to actually use umask on. */
- unsigned ops_to_mask = 0;
+ unsigned int ops_to_mask = 0;
- int who_specified_p;
+ bool who_specified_p;
- affected_bits = 0;
- ops_to_mask = 0;
/* Turn on all the bits in `affected_bits' for each group given. */
for (++mode_string;; ++mode_string)
switch (*mode_string)
/* If none specified, affect all bits, except perhaps those
set in the umask. */
if (affected_bits)
- who_specified_p = 1;
+ who_specified_p = true;
else
{
- who_specified_p = 0;
+ who_specified_p = false;
affected_bits = CHMOD_MODE_BITS;
ops_to_mask = masked_ops;
}
if (changes->value & S_IRWXU)
/* Copy `u' permissions onto `g' and `o'. */
- value |= ((value & S_IRUSR ? S_IRGRP | S_IROTH : 0)
- | (value & S_IWUSR ? S_IWGRP | S_IROTH : 0)
+ value |= ( (value & S_IRUSR ? S_IRGRP | S_IROTH : 0)
+ | (value & S_IWUSR ? S_IWGRP | S_IWOTH : 0)
| (value & S_IXUSR ? S_IXGRP | S_IXOTH : 0));
else if (changes->value & S_IRWXG)
/* Copy `g' permissions onto `u' and `o'. */
- value |= ((value & S_IRGRP ? S_IRUSR | S_IROTH : 0)
- | (value & S_IWGRP ? S_IWUSR | S_IROTH : 0)
+ value |= ( (value & S_IRGRP ? S_IRUSR | S_IROTH : 0)
+ | (value & S_IWGRP ? S_IWUSR | S_IWOTH : 0)
| (value & S_IXGRP ? S_IXUSR | S_IXOTH : 0));
else
/* Copy `o' permissions onto `u' and `g'. */
- value |= ((value & S_IROTH ? S_IRUSR | S_IRGRP : 0)
- | (value & S_IWOTH ? S_IWUSR | S_IRGRP : 0)
+ value |= ( (value & S_IROTH ? S_IRUSR | S_IRGRP : 0)
+ | (value & S_IWOTH ? S_IWUSR | S_IWGRP : 0)
| (value & S_IXOTH ? S_IXUSR | S_IXGRP : 0));
/* In order to change only `u', `g', or `o' permissions,
or some combination thereof, clear unselected bits.
- This can not be done in mode_compile because the value
+ This cannot be done in mode_compile because the value
to which the `changes->affected' mask is applied depends
on the old mode of each file. */
value &= changes->affected;