1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
| while ((c = getopt_long (argc, argv,
"Rcfvr::w::x::X::s::t::u::g::o::a::,::+::=::",
long_options, NULL))
!= -1)
{
switch (c)
{
case 'r':
case 'w':
case 'x':
case 'X':
case 's':
case 't':
case 'u':
case 'g':
case 'o':
case 'a':
case ',':
case '+':
case '=':
/* Support nonportable uses like "chmodfate -w", but diagnose
surprises due to umask confusion. Even though "--", "--r",
etc., are valid modes, there is no "case '-'" here since
getopt_long reserves leading "--" for long options. */
{
/* Allocate a mode string (e.g., "-rwx") by concatenating
the argument containing this option. If a previous mode
string was given, concatenate the previous string, a
comma, and the new string (e.g., "-s,-rwx"). */
char const *arg = argv[optind - 1];
size_t arg_len = strlen (arg);
size_t mode_comma_len = mode_len + !!mode_len;
size_t new_mode_len = mode_comma_len + arg_len;
if (mode_alloc <= new_mode_len)
{
mode_alloc = new_mode_len + 1;
mode = X2REALLOC (mode, &mode_alloc);
}
mode[mode_len] = ',';
strcpy (mode + mode_comma_len, arg);
mode_len = new_mode_len;
diagnose_surprises = true;
}
break; |